How to use do_replace method in localstack

Best Python code snippet using localstack_python

tc_tracker.py

Source:tc_tracker.py Github

copy

Full Screen

...31expname_template = 'CTL1860_v201904_tigercpu_intelmpi_18_576PE'32ifile = os.path.join(os.path.dirname(os.path.abspath(__file__)),33 'script_templates', 34 f'{model_template}.{expname_template}.lmh_TCtrack_ts_4x_gav_ro110_1C_330k_yr.csh')35def do_replace(content, istr, ostr):36 '''replace istr with ostr in content'''37 print('[replacing]:', istr, '->', ostr)38 return content.replace(istr, ostr)39# target script path40obasename = os.path.basename(ifile)41# modify the script name accordingly42if model != model_template:43 obasename = obasename.replace(model_template, model)44if model in ('AM2.5C360',):45 obasename = obasename.replace('_1C_', '_') # use the default value of dt_crit_warm = 2.46elif model in ('HIRAM',):47 obasename = obasename.replace('_1C_', '_2p5C_') # dt_crit_warm = 2.5degC48elif model in ('AM4', 'AM4_urban'):49 obasename = obasename.replace('_ro110_', '_ro250_') # r_offset_warm = 250.50 obasename = obasename.replace('_1C_', '_p75C_') # dt_crit_warm = 0.75degC51 obasename = obasename.replace('_330k_', '_550k_') # r_crit_warm = 550.52else:53 pass54if expname:55 obasename = obasename.replace(expname_template, expname)56ofile = os.path.join(cwd, obasename)57if os.path.exists(ofile):58 print('[exists]:', obasename)59 sys.exit()60# tracker script61with open(ifile) as fi:62 icontent = fi.read()63 print('[ifile]:', ifile)64 with open(ofile, 'w') as fo:65 ocontent = icontent66 # modify the script content accordingly67 if model != model_template:68 istr, ostr = '= FLOR', f'= {model}'69 ocontent = do_replace(ocontent, istr, ostr)70 if model in ('FLOR',):71 istr, ostr = '${model}/', ''72 ocontent = do_replace(ocontent, istr, ostr) # FLOR outputs are directly under MODEL_OUT73 elif model in ('AM2.5C360',):74 istr, ostr = 'dt_crit_warm = 1.', 'dt_crit_warm = 2.! default is 2.'75 ocontent = do_replace(ocontent, istr, ostr)76 istr, ostr = '_1C_', '_'77 ocontent = do_replace(ocontent, istr, ostr)78 elif model in ('HIRAM',):79 istr, ostr = 'dt_crit_warm = 1.', 'dt_crit_warm = 2.5! default is 2.'80 ocontent = do_replace(ocontent, istr, ostr)81 istr, ostr = '_1C_', '_2p5C_'82 ocontent = do_replace(ocontent, istr, ostr)83 elif model in ('AM4', 'AM4_urban'):84 istr, ostr = 'r_offset_warm = 110.', 'r_offset_warm = 250.! default is 110.'85 ocontent = do_replace(ocontent, istr, ostr)86 istr, ostr = '_ro110_', '_ro250_'87 ocontent = do_replace(ocontent, istr, ostr)88 89 istr, ostr = 'dt_crit_warm = 1.', 'dt_crit_warm = 0.75! default is 2.'90 ocontent = do_replace(ocontent, istr, ostr)91 istr, ostr = '_1C_', '_p75C_'92 ocontent = do_replace(ocontent, istr, ostr)93 94 istr, ostr = 'r_crit_warm = 330.', 'r_crit_warm = 550.! default is 330.'95 ocontent = do_replace(ocontent, istr, ostr)96 istr, ostr = '_330k', '_550k'97 ocontent = do_replace(ocontent, istr, ostr)98 99 #sorter script100 #istr, ostr = 'python $rootTCanalysis/track_sorter_FLOR_fix99.py $outputname #WY', 'python $rootTCanalysis/track_sorter_AM4C96.py $outputname #WY/GV'101 istr, ostr = 'python $rootTCanalysis/track_sorter_FLOR_fix99.py $outputname #WY', 'python $rootTCanalysis/track_sorter_fix99_AM4C96.py $outputname #WY/GV/WY'102 ocontent = do_replace(ocontent, istr, ostr)103 if expname:104 istr, ostr = f'= {expname_template}', f'= {expname}'105 ocontent = do_replace(ocontent, istr, ostr)106 if ens:107 istr = '#set ensemble'108 ostr = '''#set ensemble109set en = $2110set eno = 100111@ enoo = $eno + $en112set en = `echo $enoo | cut -c2-3`'''113 ocontent = do_replace(ocontent, istr, ostr)114 istr, ostr = '${expname}/', '${expname}/en${en}/'115 ocontent = do_replace(ocontent, istr, ostr)116 fo.write(ocontent)117 print('[created]:', obasename)118# loop script119loop_basename = f'loop.{obasename}'.replace('.csh', '.sh')120loop_file = os.path.join(cwd, loop_basename)121t = datetime.datetime.now()122with open(loop_file, 'w') as fo:123 if ens:124 s = f'''#!/usr/bin/env bash125# Wenchang Yang (wenchang@princeton.edu)126# {t.year:04d}-{t.month:02d}-{t.day:02d}T{t.hour:02d}:{t.minute:02d}:{t.second:02d}@Princeton127set -ev128script=./{obasename}129for en in {{{en_start}..{en_end}}}; do...

Full Screen

Full Screen

GeneralAbility.py

Source:GeneralAbility.py Github

copy

Full Screen

...9 "modal_effects"]10preventAll = lambda self, amt, source, combat=False: 011def prevent_all_damage():12 msg = "~ - prevent all damage"13 return combine(do_replace(CreatureType, "assignDamage", preventAll, msg=msg),14 do_replace(Player, "assignDamage", preventAll, msg=msg),15 do_replace(PlaneswalkerType, "assignDamage", preventAll, msg=msg))16def prevent_all_combat_damage():17 def condition(self, amt, source, combat=False): return combat18 msg = "~ - prevent all combat damage"19 return combine(do_replace(CreatureType, "assignDamage", preventAll, msg=msg, condition=condition),20 do_replace(Player, "assignDamage", preventAll, msg=msg, condition=condition),21 do_replace(PlaneswalkerType, "assignDamage", preventAll, msg=msg, condition=condition))22def prevent_all_noncombat_damage():23 def condition(self, amt, source, combat=False): return not combat24 msg = "~ - prevent all noncombat damage"25 return combine(do_replace(CreatureType, "assignDamage", preventAll, msg=msg, condition=condition),26 do_replace(Player, "assignDamage", preventAll, msg=msg, condition=condition),27 do_replace(PlaneswalkerType, "assignDamage", preventAll, msg=msg, condition=condition))28def prevent_all_damage_by(dmgsource):29 def condition(self, amt, source, combat=False): return source == dmgsource30 msg = "~ - prevent all damage by %s"%dmgsource.name31 return combine(do_replace(CreatureType, "assignDamage", preventAll, msg=msg, condition=condition),32 do_replace(Player, "assignDamage", preventAll, msg=msg, condition=condition),33 do_replace(PlaneswalkerType, "assignDamage", preventAll, msg=msg, condition=condition))34def prevent_all_combat_damage_by(dmgsource):35 def condition(self, amt, source, combat=False): return source == dmgsource and combat36 msg = "~ - prevent all combat damage by %s"%dmgsource.name37 return combine(do_replace(CreatureType, "assignDamage", preventAll, msg=msg, condition=condition),38 do_replace(Player, "assignDamage", preventAll, msg=msg, condition=condition),39 do_replace(PlaneswalkerType, "assignDamage", preventAll, msg=msg, condition=condition))40def prevent_all_noncombat_damage_by(dmgsource):41 def condition(self, amt, source, combat=False): return source == dmgsource and not combat42 msg = "~ - prevent all noncombat damage by %s"%dmgsource.name43 return combine(do_replace(CreatureType, "assignDamage", preventAll, msg=msg, condition=condition),44 do_replace(Player, "assignDamage", preventAll, msg=msg, condition=condition),45 do_replace(PlaneswalkerType, "assignDamage", preventAll, msg=msg, condition=condition))46def modal_effects(*modes, **kw):47 choose = kw['choose']48 def make_modal(effects):49 def modal_effects(controller, source):50 selected = controller.make_selection([(mode.__doc__,mode) for mode in modes], choose, prompt='Select %d mode(s):'%choose)51 if choose > 1: chosen = tuple((mode(controller, source) for mode in selected))52 else: chosen = (selected(controller, source), )53 # get the costs54 # We need to have a "payment = yield NoCost" in the mode to pass55 # back the cost in case the mode needs to reference is (see Profane Command)56 empty_costs = tuple((mode.next() for mode in chosen))57 payment = yield effects(controller, source).next()58 # get the targets - demultiplex them59 targets, unflatten = flatten(mode.send(payment) for mode in chosen)...

Full Screen

Full Screen

convert.py

Source:convert.py Github

copy

Full Screen

...26def check_duplicate(new):27 for m in conversions:28 if m[1] == new:29 return True30def do_replace(eVal):31 if eVal in opendj_attributes:32 return eVal33 for m in mapping['mappings']:34 if m in eVal:35 eVal = eVal.replace(m, mapping['mappings'][m])36 if eVal in mapping['postconversions']:37 eVal = mapping['postconversions'][eVal]38 return eVal39new_attributeTypes = []40for attribute in schema['attributeTypes']:41 skip = False42 for name in attribute['names']:43 if name in mapping['exclude']['attributeType']:44 skip = True45 if skip:46 continue47 for e in ('desc', 'equality', 'oid', 'x_origin'):48 if e in attribute:49 attribute[e] = do_replace(attribute[e])50 new_name_list = []51 for name in (attribute['names']):52 new = do_replace(name)53 54 if not new in new_name_list and not check_duplicate(new): 55 new_name_list.append(new)56 conversions.append((name, new))57 if new_name_list:58 attribute['names'] = new_name_list59 new_attributeTypes.append(attribute)60schema['attributeTypes'] = new_attributeTypes61new_objectClasses = []62def check_objduplicate(new, lt):63 for obc in new_objectClasses:64 if new in obc[lt]:65 return True66def get_obj_by_name(name):67 for obj in new_objectClasses:68 if name in obj['names']:69 return obj70for obj in schema['objectClasses']:71 skip = False72 for name in obj['names']:73 if name in mapping['exclude']['objectClass']:74 skip = True75 if skip:76 continue77 for e in ('oid', 'x_origin'):78 if e in obj:79 obj[e] = do_replace(obj[e])80 for lt in ('may', 'names'):81 new_list = []82 for name in obj[lt]:83 if name in mapping['exclude']['attributeType']:84 continue85 new = do_replace(name)86 obj_conversions.append((name, new))87 if lt == 'names' and check_objduplicate(new, lt):88 continue89 if not new in new_list:90 new_list.append(new)91 obj[lt] = new_list92 if obj['names'] and obj['may']:93 new_objectClasses.append(obj)94 elif not obj['names'] and obj['may']:95 prev_obj = get_obj_by_name(new)96 if prev_obj:97 prev_obj['may'] += obj['may']98schema['objectClasses'] = new_objectClasses99macrkeys = list(schema['oidMacros'].keys())100for macr in macrkeys:101 newname = do_replace(macr)102 schema['oidMacros'][newname] = schema['oidMacros'].pop(macr)103 schema['oidMacros'][newname] = do_replace(schema['oidMacros'][newname])104if argsp.outfile:105 with open(argsp.outfile, 'w') as w:106 json.dump(schema, w, indent=2)107if argsp.dump:108 conversions.sort()109 obj_conversions.sort()110 attr_dict = OrderedDict(conversions)111 obj_dict = OrderedDict(obj_conversions)112 ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful