Best Python code snippet using mailosaur-python_python
limits.py
Source:limits.py
...12def check_if_expired():13 """check if account is expired. If expired, do not allow login"""14 if not has_expired():15 return16 limits = get_limits()17 expiry = limits.get("expiry")18 if not expiry:19 return20 expires_on = formatdate(limits.get("expiry"))21 support_email = limits.get("support_email")22 if limits.upgrade_url:23 message = _("""Your subscription expired on {0}. To renew, {1}.""").format(expires_on, get_upgrade_link(limits.upgrade_url))24 elif support_email:25 message = _("""Your subscription expired on {0}. To renew, please send an email to {1}.""").format(expires_on, support_email)26 else:27 # no recourse just quit28 return29 frappe.throw(message, SiteExpiredError)30def has_expired():31 if frappe.session.user=="Administrator":32 return False33 expires_on = get_limits().expiry34 if not expires_on:35 return False36 if now_datetime().date() <= getdate(expires_on):37 return False38 return True39def get_expiry_message():40 if "System Manager" not in frappe.get_roles():41 return ""42 limits = get_limits()43 if not limits.expiry:44 return ""45 expires_on = getdate(get_limits().get("expiry"))46 today = now_datetime().date()47 message = ""48 if today > expires_on:49 message = _("Your subscription has expired.")50 else:51 days_to_expiry = (expires_on - today).days52 if days_to_expiry == 0:53 message = _("Your subscription will expire today.")54 elif days_to_expiry == 1:55 message = _("Your subscription will expire tomorrow.")56 elif days_to_expiry <= EXPIRY_WARNING_DAYS:57 message = _("Your subscription will expire on {0}.").format(formatdate(expires_on))58 if message and limits.upgrade_url:59 upgrade_link = get_upgrade_link(limits.upgrade_url)60 message += ' ' + _('To renew, {0}.').format(upgrade_link)61 return message62@frappe.whitelist()63def get_usage_info():64 '''Get data to show for Usage Info'''65 # imported here to prevent circular import66 from frappe.email.queue import get_emails_sent_this_month67 limits = get_limits()68 if not (limits and any([limits.users, limits.space, limits.emails, limits.expiry])):69 # no limits!70 return71 limits.space = (limits.space or 0) * 1024.0 # to MB72 if not limits.space_usage:73 # hack! to show some progress74 limits.space_usage = {75 'database_size': 26,76 'files_size': 1,77 'backup_size': 1,78 'total': 2879 }80 usage_info = frappe._dict({81 'limits': limits,82 'enabled_users': len(get_enabled_system_users()),83 'emails_sent': get_emails_sent_this_month(),84 'space_usage': limits.space_usage['total'],85 })86 if limits.expiry:87 usage_info['expires_on'] = formatdate(limits.expiry)88 usage_info['days_to_expiry'] = (getdate(limits.expiry) - getdate()).days89 if limits.upgrade_url:90 usage_info['upgrade_url'] = get_upgrade_url(limits.upgrade_url)91 return usage_info92def get_upgrade_url(upgrade_url):93 parts = urlparse.urlsplit(upgrade_url)94 params = dict(urlparse.parse_qsl(parts.query))95 params.update({96 'site': frappe.local.site,97 'email': frappe.session.user,98 'full_name': get_fullname(),99 'country': frappe.db.get_value("System Settings", "System Settings", 'country')100 })101 query = urllib.urlencode(params, doseq=True)102 url = urlparse.urlunsplit((parts.scheme, parts.netloc, parts.path, query, parts.fragment))103 return url104def get_upgrade_link(upgrade_url, label=None):105 upgrade_url = get_upgrade_url(upgrade_url)106 upgrade_link = '<a href="{upgrade_url}" target="_blank">{click_here}</a>'.format(upgrade_url=upgrade_url, click_here=label or _('click here'))107 return upgrade_link108def get_limits():109 '''110 "limits": {111 "users": 1,112 "space": 0.5, # in GB113 "emails": 1000 # per month114 "expiry": "2099-12-31"115 }116 '''117 return frappe._dict(frappe.local.conf.limits or {})118def update_limits(limits_dict):119 '''Add/Update limit in site_config'''120 limits = get_limits()121 limits.update(limits_dict)122 update_site_config("limits", limits, validate=False)123 disable_users(limits)124 frappe.local.conf.limits = limits125def clear_limit(key):126 '''Remove a limit option from site_config'''127 limits = get_limits()128 to_clear = [key] if isinstance(key, basestring) else key129 for key in to_clear:130 if key in limits:131 del limits[key]132 update_site_config("limits", limits, validate=False)133 frappe.conf.limits = limits134def validate_space_limit(file_size):135 """Stop from writing file if max space limit is reached"""136 from frappe.utils.file_manager import MaxFileSizeReachedError137 limits = get_limits()138 if not limits.space:139 return140 # to MB141 space_limit = flt(limits.space * 1024.0, 2)142 # in MB143 usage = frappe._dict(limits.space_usage or {})144 if not usage:145 # first time146 usage = frappe._dict(update_space_usage())147 file_size = file_size / (1024.0 ** 2)148 if flt(flt(usage.total) + file_size, 2) > space_limit:149 # Stop from attaching file150 frappe.throw(_("You have exceeded the max space of {0} for your plan. {1}.").format(151 "<b>{0}MB</b>".format(cint(space_limit)) if (space_limit < 1024) else "<b>{0}GB</b>".format(limits.space),152 '<a href="#usage-info">{0}</a>'.format(_("Click here to check your usage or upgrade to a higher plan"))),153 MaxFileSizeReachedError)154 # update files size in frappe subscription155 usage.files_size = flt(usage.files_size) + file_size156 update_limits({ 'space_usage': usage })157def update_space_usage():158 # public and private files159 files_size = get_folder_size(frappe.get_site_path("public", "files"))160 files_size += get_folder_size(frappe.get_site_path("private", "files"))161 backup_size = get_folder_size(frappe.get_site_path("private", "backups"))162 database_size = get_database_size()163 usage = {164 'files_size': flt(files_size, 2),165 'backup_size': flt(backup_size, 2),166 'database_size': flt(database_size, 2),167 'total': flt(flt(files_size) + flt(backup_size) + flt(database_size), 2)168 }169 update_limits({ 'space_usage': usage })170 return usage171def get_folder_size(path):172 '''Returns folder size in MB if it exists'''173 if os.path.exists(path):174 return flt(subprocess.check_output(['du', '-ms', path]).split()[0], 2)175def get_database_size():176 '''Returns approximate database size in MB'''177 db_name = frappe.conf.db_name178 # This query will get the database size in MB179 db_size = frappe.db.sql('''180 SELECT table_schema "database_name", sum( data_length + index_length ) / 1024 / 1024 "database_size"181 FROM information_schema.TABLES WHERE table_schema = %s GROUP BY table_schema''', db_name, as_dict=True)...
ff.py
Source:ff.py
...70 if 'forces' not in self.results:71 forces = np.zeros(3 * len(atoms))72 for morse in self.morses:73 i, j, g = ff.get_morse_potential_gradient(atoms, morse)74 limits = get_limits([i, j])75 for gb, ge, lb, le in limits:76 forces[gb:ge] -= g[lb:le]77 for bond in self.bonds:78 i, j, g = ff.get_bond_potential_gradient(atoms, bond)79 limits = get_limits([i, j])80 for gb, ge, lb, le in limits:81 forces[gb:ge] -= g[lb:le]82 for angle in self.angles:83 i, j, k, g = ff.get_angle_potential_gradient(atoms, angle)84 limits = get_limits([i, j, k])85 for gb, ge, lb, le in limits:86 forces[gb:ge] -= g[lb:le]87 for dihedral in self.dihedrals:88 i, j, k, l, g = ff.get_dihedral_potential_gradient(89 atoms, dihedral)90 limits = get_limits([i, j, k, l])91 for gb, ge, lb, le in limits:92 forces[gb:ge] -= g[lb:le]93 for vdw in self.vdws:94 i, j, g = ff.get_vdw_potential_gradient(atoms, vdw)95 limits = get_limits([i, j])96 for gb, ge, lb, le in limits:97 forces[gb:ge] -= g[lb:le]98 for coulomb in self.coulombs:99 i, j, g = ff.get_coulomb_potential_gradient(atoms, coulomb)100 limits = get_limits([i, j])101 for gb, ge, lb, le in limits:102 forces[gb:ge] -= g[lb:le]103 self.results['forces'] = np.reshape(forces, (len(atoms), 3))104 if 'hessian' not in self.results:105 hessian = np.zeros((3 * len(atoms), 3 * len(atoms)))106 for morse in self.morses:107 i, j, h = ff.get_morse_potential_hessian(atoms, morse)108 limits = get_limits([i, j])109 for gb1, ge1, lb1, le1 in limits:110 for gb2, ge2, lb2, le2 in limits:111 hessian[gb1:ge1, gb2:ge2] += h[lb1:le1, lb2:le2]112 for bond in self.bonds:113 i, j, h = ff.get_bond_potential_hessian(atoms, bond)114 limits = get_limits([i, j])115 for gb1, ge1, lb1, le1 in limits:116 for gb2, ge2, lb2, le2 in limits:117 hessian[gb1:ge1, gb2:ge2] += h[lb1:le1, lb2:le2]118 for angle in self.angles:119 i, j, k, h = ff.get_angle_potential_hessian(atoms, angle)120 limits = get_limits([i, j, k])121 for gb1, ge1, lb1, le1 in limits:122 for gb2, ge2, lb2, le2 in limits:123 hessian[gb1:ge1, gb2:ge2] += h[lb1:le1, lb2:le2]124 for dihedral in self.dihedrals:125 i, j, k, l, h = ff.get_dihedral_potential_hessian(126 atoms, dihedral)127 limits = get_limits([i, j, k, l])128 for gb1, ge1, lb1, le1 in limits:129 for gb2, ge2, lb2, le2 in limits:130 hessian[gb1:ge1, gb2:ge2] += h[lb1:le1, lb2:le2]131 for vdw in self.vdws:132 i, j, h = ff.get_vdw_potential_hessian(atoms, vdw)133 limits = get_limits([i, j])134 for gb1, ge1, lb1, le1 in limits:135 for gb2, ge2, lb2, le2 in limits:136 hessian[gb1:ge1, gb2:ge2] += h[lb1:le1, lb2:le2]137 for coulomb in self.coulombs:138 i, j, h = ff.get_coulomb_potential_hessian(atoms, coulomb)139 limits = get_limits([i, j])140 for gb1, ge1, lb1, le1 in limits:141 for gb2, ge2, lb2, le2 in limits:142 hessian[gb1:ge1, gb2:ge2] += h[lb1:le1, lb2:le2]143 self.results['hessian'] = hessian144 def get_hessian(self, atoms=None):145 return self.get_property('hessian', atoms)146def get_limits(indices):147 gstarts = []148 gstops = []149 lstarts = []150 lstops = []151 for l, g in enumerate(indices):152 g3, l3 = 3 * g, 3 * l153 gstarts.append(g3)154 gstops.append(g3 + 3)155 lstarts.append(l3)156 lstops.append(l3 + 3)...
main.py
Source:main.py
1import copy2import services3import pathlib4path = "png"5# PYTHON 3.6ì´ì íì, dict ì ë ¬ ê´ë ¨.6# property를 pathí´ë ë´ë¶ì í´ëë¤ì ì´ì©í´ ì¸í
í¨.7print("## properties init ##")8properties_list = list(pathlib.Path(path).glob("[!.]*"))9properties_list.sort()10print(properties_list)11# final_property = str(properties_list[len(properties_list) - 1])[len(path) + 1:]12# print("final_property")13# print(final_property)14properties = {}15for p in properties_list:16 properties[str(p)[len(path) + 1:]] = 017# property_counts ì¸í
18property_counts = copy.deepcopy(properties)19for p in property_counts:20 property_path = path + '/' + p21 file_list = len(list(pathlib.Path(property_path).glob("*.png")))22 property_counts[p] = file_list23print("## property_counts ##")24print(property_counts)25limits = copy.deepcopy(properties)26limits_count = copy.deepcopy(properties)27result_properties = copy.deepcopy(properties)28final_properties = copy.deepcopy(properties)29for li in limits:30 limits[li] = {}31 limits_count[li] = {}32 result_properties[li] = []33for p in property_counts:34 for c in range(0, property_counts[p]):35 limits_count[p][c] = 036 limits[p][c] = 999937# ----- CUSTOM ----------------------------------38limits["0_background"][5] = 46539limits["2_clothes"][0] = 15040limits["2_clothes"][5] = 25441limits["2_clothes"][9] = 25442limits["2_clothes"][11] = 20143limits["2_clothes"][13] = 23144limits["2_clothes"][14] = 18845limits["2_clothes"][16] = 24846limits["3_item1"][1] = 13447limits["3_item1"][2] = 12748limits["3_item1"][19] = 6549limits["3_item1"][20] = 3450limits["4_head"][11] = 20051limits["4_head"][16] = 20452limits["4_head"][19] = 17853limits["4_head"][20] = 18954limits["4_head"][21] = 20755limits["6_hand"][6] = 1556limits["6_hand"][12] = 9257limits["7_item2"][1] = 20058limits["7_item2"][2] = 21159limits["7_item2"][3] = 19560# ----- CUSTOM ----------------------------------61print("## limits ##")62print(limits)63def roop_result(c):64 for p in result_properties:65 services.randomSelect(c, property_counts, limits_count, limits, p, result_properties)66 str_at = ""67 for p in result_properties:68 str_at += str(result_properties[p][c]) + "_"69 if str_at not in onlyOne:70 onlyOne[str_at] = True71 else:72 for p in result_properties:73 limits_count[p][result_properties[p][-1]] -= 174 result_properties[p].pop()75 roop_result(c)76# make!77create_count = 178onlyOne = {};79for c in range(0, create_count):80 roop_result(c)81print("## OnlyOne")82print(onlyOne)83# ê°¯ì ê²ì¦84print("## final properties count is : ##")85print(limits_count)86for li in limits_count:87 count = 088 for c in limits_count[li]:89 count = count + limits_count[li][c]90 final_properties[li] = count91print(final_properties)92print("##################################")93# í
ì¤í¸ì©94result_properties = {"0_background": [0], "1_body": [0], "2_clothes": [1], "3_item1": [0], "4_head": [3],95 "5_mustache": [2], "6_hand": [4], "7_item2": [0]}96print("## result_properties ##")97print(result_properties)98# makeImages...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!