def submit_jobs(): for run_number, exponent in enumerate(exponents1): runname = 'rsigma_{}'.format(exponent) run.run( run_name=runname, parameters={ 'rho_ion_si': 1e26, 'plasma_length_si': 100, 'acceleration_gradient_gev_per_m': 0, 'unperturbed_plasma_density_si': 1e26, 'particles_target': 1000, 'cross_section_radius_si': 10. ** exponent, 'minimum_steps_per_betatron_period': 10 ** 4, 'output_phase_space': True }, hoffman2=False, compute_processes=7 ) for run_number, exponent in enumerate(exponents2): runname = 'steps_{}'.format(exponent) run.run( run_name=runname, parameters={ 'rho_ion_si': 1e26, 'plasma_length_si': 100, 'acceleration_gradient_gev_per_m': 0, 'unperturbed_plasma_density_si': 1e26, 'particles_target': 1000, 'cross_section_radius_si': 10. ** -8, 'minimum_steps_per_betatron_period': 10 ** exponent, 'output_phase_space': True }, hoffman2=False, compute_processes=7 )
def vary_hyperparameters(config, hyperparams, device, epochs, replications, seed, num_data_workers): """ Run a config with all combinations of hyperparameters specified. The script takes the same parameters as run.py and an additional list of hyperparameters to vary over. It will span a grid of these hyperparameters and execute run.py with a modified config dict for each combination of hyperparameter values on the grid. :param config: path to config JSON file :param hyperparams: list of hyperparams as string ('hparam.in.dot.notation=['list','of','values']') :param device: device to train on :param epochs: number of epochs to train :param replications: number of replications for each run :param seed: random seed passed to run.py :param num_data_workers: number of data loading processes """ config = utils.read_config(config) # Parse list of hyperparameters from CLI grid_axis = {} for param in hyperparams: param, values = param.split('=') values = eval(values) grid_axis[param] = values # Create hparam grid hyperparams = sklearn.model_selection.ParameterGrid(grid_axis) # Execute run.py for each modified config for params in hyperparams: config = modify_config(config, params) run(config, device, epochs, replications, seed, num_data_workers)
def run(self): """Run the Playbook App. Returns: int: The App exit code """ # first-party from run import run # pylint: disable=no-name-in-module # backup sys.argv sys_argv_orig = sys.argv # clear sys.argv sys.argv = sys.argv[:1] # run the app exit_code = 0 try: # provide callback to to run.py method on Trigger Service Apps run(set_app=self._app_callback) # pylint: disable=unexpected-keyword-arg except SystemExit as e: exit_code = e.code # restore sys.argv sys.argv = sys_argv_orig self.log.data('run', 'Exit Code', exit_code) return exit_code
def compile_javascript(self, fullpath): js_jar = os.path.join(self.template_dir, 'js.jar') # poor man's os.path.relpath (we don't have python 2.6 in windows) resource_relative_path = fullpath[len(self.project_dir) + 1:].replace( "\\", "/") # chop off '.js' js_class_name = resource_relative_path[:-3] escape_chars = ['\\', '/', ' ', '.'] for escape_char in escape_chars: js_class_name = js_class_name.replace(escape_char, '_') # TODO: add closure compiling too? jsc_args = [ self.java, '-classpath', js_jar, 'org.mozilla.javascript.tools.jsc.Main', '-main-method-class', 'org.appcelerator.titanium.TiScriptRunner', '-package', self.appid + '.js', '-encoding', 'utf8', '-o', js_class_name, '-d', self.classes_dir, fullpath ] print "[INFO] Compiling javascript: %s" % resource_relative_path sys.stdout.flush() run.run(jsc_args)
def test_heavy_hitters_window(): heavy_hitters_object = HeavyHitters(width=1000, depth=5) x = Stream('input') ## y = Stream('output') window_size = 4 y = heavy_hitters_window(x, window_size, heavy_hitters_object) #heavy_hitters_window(x, y, window_size, heavy_hitters_object) x.extend([ 'a', 'a', 'a', 'b', # next window 'a', 'b', 'c', 'a', # next window 'b', 'c', 'b', 'b' ]) run() #Stream.scheduler.step() print(recent_values(y))
def make_run_compile(executableName, executableInputList, resultFolderName, resultFileName, CBuildFolder, operandSampleFileName, bench_suit_name, process_id, settings_obj, input_list): if (bench_suit_name == "my_micro_benchmark"): #validating the number of inputs #validating the existance of the dir, and making it other wise if not os.path.isdir(resultFolderName): print "the folderName provided does not correspond to any existing folder. I will be making it" os.system("mkdir " + resultFolderName); if not os.path.isfile(operandSampleFileName): print "the operandSampleFileName:" + operandSampleFileName + " does not exist" exit() currentDir = os.getcwd() #getting the current directory #CBuildFolder = "./../../Debug" os.chdir(CBuildFolder) #chaning the directory make.make() if (settings_obj.runMode == "parallel"): run.run(executableName, resultFolderName, resultFileName, settings_obj.operatorSampleFileName+str(process_id)+ ".txt", operandSampleFileName) else: run.run(executableName, resultFolderName, resultFileName, settings_obj.operatorSampleFileName+"0.txt", operandSampleFileName) os.chdir(currentDir) #chaning the directory elif (bench_suit_name == "sd-vbs"): currentDir = os.getcwd() #getting the current directory os.chdir(CBuildFolder) #chaning the directory os.system("pwd"); #os.system("gdb --args ./sift ~/behzad_local/sd-vbs/benchmarks/sift/data/sim"); if (settings_obj.runMode == "parallel"): os.system("gmake c-run-compile " + "exe_annex="+str(process_id) + " first_input="+input_list[0] + " second_input="+input_list[1]) else: os.system("gmake c-run-compile " + "exe_annex="+str(0) + " first_input="+input_list[0] + " second_input="+input_list[1]) os.chdir(currentDir) #chaning the directory
def test_chain(): command = run("ps aux", "wc -l", "wc -c") assert command.status == 0 assert len(run("ps aux", "wc -l", "wc -c").chain) == 3 assert [0, 0, 0] == [e.status for e in run("ps aux", "wc -l", "wc -c").chain] assert [1, 0] == [e.status for e in run("ps aux fail", "wc -l").chain]
def create_avd(self,avd_id,avd_skin): name = "titanium_%s_%s" % (avd_id,avd_skin) home_dir = os.path.join(os.path.expanduser('~'), '.titanium') if not os.path.exists(home_dir): os.makedirs(home_dir) sdcard = os.path.abspath(os.path.join(home_dir,'android.sdcard')) if not os.path.exists(sdcard): mksdcard = os.path.join(self.sdk,'tools','mksdcard') if platform.system() == "Windows": mksdcard += ".exe" print "[INFO] Created shared 10M SD card for use in Android emulator(s)" run.run([mksdcard, '10M', sdcard]) avd_path = os.path.expanduser("~/.android/avd") my_avd = os.path.join(avd_path,"%s.avd" % name) if not os.path.exists(my_avd): print "[INFO] creating new AVD %s %s" % (avd_id,avd_skin) inputgen = os.path.join(template_dir,'input.py') pipe([sys.executable, inputgen], [self.android, '--verbose', 'create', 'avd', '--name', name, '--target', avd_id, '-s', avd_skin, '--force', '--sdcard', sdcard]) inifile = os.path.join(my_avd,'config.ini') inifilec = open(inifile,'r').read() inifiledata = open(inifile,'w') inifiledata.write(inifilec) inifiledata.write("hw.camera=yes\n") inifiledata.close() return name
def onBtRunClicked(self): srcFile = str(self.leSrcFile.text()) if not os.path.isfile(srcFile): msg = self.tr("Source File '%s' does not exist"%srcFile) QMessageBox.warning(None, self.tr("File Error!"), msg) return trkFile = str(self.leTrkFile.text()) if not os.path.isfile(trkFile): msg = self.tr("Track File '%s' does not exist"%trkFile) QMessageBox.warning(None, self.tr("File Error!"), msg) return ptkFile = str(self.lePtkFile.text()) if not os.path.isfile(ptkFile): msg = self.tr("Particle File '%s' does not exist"%ptkFile) QMessageBox.warning(None, self.tr("File Error!"), msg) return ptkWeight = str(self.lePtkWeight.text()) if len(ptkWeight)==0: msg = self.tr("Particle weight is not set") return ptkWeight = float(ptkWeight) gridRslt = str(self.leGridRslt.text()) if len(gridRslt)==0: msg = self.tr("Grid resolution is not set") return gridRslt = float(gridRslt) run(srcFile, trkFile, ptkFile, ptkWeight, gridRslt)
def test_chain(): command = run('ps aux', 'wc -l', 'wc -c') assert command.status == 0 assert len(run('ps aux', 'wc -l', 'wc -c').chain) == 3 assert [0, 0, 0] == [e.status for e in run('ps aux', 'wc -l', 'wc -c').chain] assert [1, 0] == [e.status for e in run('ps aux fail', 'wc -l').chain]
def run_test_code(self, source_path: str, expect_fail: bool): args = Args() self.init_args(args) args.source_path = source_path args.expect_fail = expect_fail io = TestIo() run(args, io)
def test_stdin(): command = run( "ls -la", """python -c 'from run import run; print(run("wc -l", stdin=run.stdin).stdout)'""" ) command.stdout.strip("\n") == run('ls -la', 'wc -l')
def main(): # offline data_collection, files_dict = init_data_collection('source') # online run(data_collection, files_dict, K)
def main(): # preparser, we need the transform arguments from this file before we know what to print in cli # options package_parser = argparse.ArgumentParser(description='EcoSML Python CLI', add_help=False) package_parser.add_argument('package', nargs='?', help='Path to PLSR package to use') package_parser.add_argument('--transform', '-t', action='store', help='Custom transform input spectra', required=False) package_args, unknown = package_parser.parse_known_args() # if a package was given, read in the EcoSML file config = None if package_args.package is not None: if not path.isabs(package_args.package): package_args.package = path.normpath(path.join(getcwd(), package_args.package)) config = get_config(package_args.package) # Generate custom cli and actually fire off a 'for real' argparser args = get_custom_args(config, package_args.transform) # normalize some more paths if not path.isabs(args.spectra): args.spectra = path.normpath(path.join(getcwd(), args.spectra)) if not path.isfile(args.spectra): print 'Input spectra file does not exist: %s' % args.spectra exit(1) if not path.isabs(args.output): args.output = path.normpath(path.join(getcwd(), args.output)) if not path.exists(args.output): print 'Output directory does not exist: %s' % args.output exit(1) # run the desired transforms transform.run(config, args) # run main module run.run(config, args)
def test(): x = Stream('x') y = Stream('y') subtract_mean(x, y, window_size=10, step_size=10) x.extend(list(range(100))) run() print(recent_values(y))
def test_nginx(self): test_id = '00000000-0000-0000-0000-000000000001' soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM) # TODO nginx does not listen to IPv6 run.run(True, cmd=('/usr/sbin/nginx', '-g', 'daemon off;'), image='nginx', uuid=test_id) sleep(1) result = soc.connect_ex(('localhost', 80)) # clean up soc.close() run.terminate(test_id) os.remove(os.path.join("container", test_id + '.img')) config.delete_record(test_id) # check result self.assertEqual( result, 0, msg="Could not connect to localhost:80, return code is {0}".format( result)) print("Nginx is running normally")
def test_subtract_mean(): x = StreamArray('x', dtype=float) y = StreamArray('x', dtype=float) subtract_mean(x, window_size=2, step_size=1, y=y) x.extend(np.arange(5, dtype=float)) run() print(recent_values(y))
def predict(opts=None): if opts is None: sys.argv.extend(["evaluation.predict=true"]) else: opts.extend(["evaluation.predict=true"]) run(predict=True)
def test_subtract_mean_block(): x = StreamArray('x') y = StreamArray('y') subtract_mean_block(x, y, window_size=4, step_size=4, block_size=4) x.extend(np.arange(20, dtype=float)) run() print(recent_values(y))
def test(): from stream import Stream, StreamArray def copy(list_of_in_lists, state): return ([in_list.list[in_list.start:in_list.stop] for in_list in list_of_in_lists], state, [in_list.stop for in_list in list_of_in_lists]) input_stream_0 = Stream('input_stream_0', num_in_memory=32) input_stream_1 = Stream('input_stream_1', num_in_memory=32 ) output_stream_0 = Stream('output_stream_0', num_in_memory=32) output_stream_1 = Stream('output_stream_1', num_in_memory=32) A = Agent(in_streams=[input_stream_0, input_stream_1 ], out_streams=[output_stream_0, output_stream_1], transition=copy, name='A') input_stream_0.extend(list(range(10))) run() assert(output_stream_0.stop == 10) assert(output_stream_1.stop == 0) assert(output_stream_0.recent[:10] == list(range(10))) assert(input_stream_0.start == {A:10}) assert(input_stream_1.start == {A:0}) input_stream_1.extend(list(range(10, 25, 1))) run() assert(output_stream_0.stop == 10) assert(output_stream_1.stop == 15) assert(output_stream_0.recent[:10] == list(range(10))) assert(output_stream_1.recent[:15] == list(range(10, 25, 1))) assert(input_stream_0.start == {A:10}) assert(input_stream_1.start == {A:15})
def test_test(mocker): def side_effect_test(args): modify_args(args) args.mode = 'test' main(args) mock = mocker.patch('main.main', side_effect=side_effect_test) run()
def loop_over_log_dirs(): rld1 = os.path.join(BASE_DIR, 'gauge_logs_eager', '2020_07') rld2 = os.path.join(BASE_DIR, 'gauge_logs_eager', '2020_06') ld1 = [ os.path.join(rld1, i) for i in os.listdir(rld1) if os.path.isdir(os.path.join(rld1, i)) ] ld2 = [ os.path.join(rld2, i) for i in os.listdir(rld2) if os.path.isdir(os.path.join(rld2, i)) ] log_dirs = ld1 + ld2 for log_dir in log_dirs: args = AttrDict({ 'hmc': False, 'run_steps': 2000, 'overwrite': True, 'log_dir': log_dir, }) try: run(args, log_dir, random_start=True) except: pass
def compile_javascript(self, fullpath): js_jar = os.path.join(self.template_dir, "js.jar") # poor man's os.path.relpath (we don't have python 2.6 in windows) resource_relative_path = fullpath[len(self.project_dir) + 1 :].replace("\\", "/") # chop off '.js' js_class_name = resource_relative_path[:-3] escape_chars = ["\\", "/", " ", "."] for escape_char in escape_chars: js_class_name = js_class_name.replace(escape_char, "_") # TODO: add closure compiling too? jsc_args = [ self.java, "-classpath", js_jar, "org.mozilla.javascript.tools.jsc.Main", "-main-method-class", "org.appcelerator.titanium.TiScriptRunner", "-nosource", "-package", self.appid + ".js", "-encoding", "utf8", "-o", js_class_name, "-d", self.classes_dir, fullpath, ] print "[INFO] Compiling javascript: %s" % resource_relative_path sys.stdout.flush() run.run(jsc_args)
def run(self): """Run the Playbook App. Returns: int: The App exit code """ from run import run # pylint: disable=no-name-in-module # backup sys.argv sys_argv_orig = sys.argv # clear sys.argv sys.argv = sys.argv[:1] # run the app exit_code = 0 try: run(set_app=self._app_callback) except SystemExit as e: exit_code = e.code # restore sys.argv sys.argv = sys_argv_orig self.log.data('run', 'Exit Code', exit_code) return exit_code
def make_run(executableName, executableInputList, resultFolderName, resultFileName, CBuildFolder, operandSampleFileName, bench_suit_name, process_id, settings_obj, input_list): if (bench_suit_name == "my_micro_benchmark"): #validating the number of inputs #validating the existance of the dir, and making it other wise currentDir = os.getcwd() #getting the current directory #CBuildFolder = "./../../Debug" os.chdir(CBuildFolder) #chaning the directory if (settings_obj.runMode == "parallel"): run.run(executableName, resultFolderName, resultFileName, settings_obj.operatorSampleFileName+str(process_id)+ ".txt", operandSampleFileName) else: run.run(executableName, resultFolderName, resultFileName, settings_obj.operatorSampleFileName+"0.txt", operandSampleFileName) os.chdir(currentDir) #chaning the directory elif (bench_suit_name == "sd-vbs"): currentDir = os.getcwd() #getting the current directory os.chdir(CBuildFolder) #chaning the directory os.system("pwd"); #os.system("gdb --args ./sift ~/behzad_local/sd-vbs/benchmarks/sift/data/sim"); if (settings_obj.runMode == "parallel"): os.system("gmake c-run " + "exe_annex="+str(process_id) + " first_input="+input_list[0] + " second_input="+input_list[1]) else: os.system("gmake c-run " + "exe_annex="+str(0) + " first_input="+input_list[0] + " second_input="+input_list[1]) os.chdir(currentDir) #chaning the directory # os.chdir(resultFolderName) #chaning the directory # resultFileP = open(resultFileName, "a") # resultFileP.close(); # os.chdir(currentDir)
def onBtRunClicked(self): srcFile = str(self.leSrcFile.text()) if not os.path.isfile(srcFile): msg = self.tr("Source File '%s' does not exist" % srcFile) QMessageBox.warning(None, self.tr("File Error!"), msg) return trkFile = str(self.leTrkFile.text()) if not os.path.isfile(trkFile): msg = self.tr("Track File '%s' does not exist" % trkFile) QMessageBox.warning(None, self.tr("File Error!"), msg) return ptkFile = str(self.lePtkFile.text()) if not os.path.isfile(ptkFile): msg = self.tr("Particle File '%s' does not exist" % ptkFile) QMessageBox.warning(None, self.tr("File Error!"), msg) return ptkWeight = str(self.lePtkWeight.text()) if len(ptkWeight) == 0: msg = self.tr("Particle weight is not set") return ptkWeight = float(ptkWeight) gridRslt = str(self.leGridRslt.text()) if len(gridRslt) == 0: msg = self.tr("Grid resolution is not set") return gridRslt = float(gridRslt) run(srcFile, trkFile, ptkFile, ptkWeight, gridRslt)
def validate_bin(self): try: run.run(self.bin_file) except: print(f"============> failure on {self.bin_file}") return False return True
def my_main(_run, _config, _log): # Setting the random seed throughout the modules config = config_copy(_config) np.random.seed(config["seed"]) th.manual_seed(config["seed"]) config['env_args']['seed'] = config["seed"] # run the framework run(_run, config, _log)
def my_main(_run, _config, _log, env_args): # Setting the random seed throughout the modules np.random.seed(_config["seed"]) th.manual_seed(_config["seed"]) env_args['seed'] = _config["seed"] # run the framework run(_run, _config, _log)
def test(pattern, accept, reject): re = make_re(pattern) for i in accept: if not run(re, i): print "Error: '%s' rejected '%s'" % (pattern, i) for i in reject: if run(re, i): print "Error: '%s' accepted '%s'" % (pattern, i)
def test_r_add(): x = Stream() y = Stream() z = 5 r_add(x, y, z) x.extend(list(range(3))) run() assert recent_values(y) == [5, 6, 7]
def put_data_in_stream(stream): num_steps=5 step_size=4 for i in range(num_steps): data = list(range(i*step_size, (i+1)*step_size)) stream.extend(data) run() return
def check_java(): try: if platform.system() == "Windows": run.run(['cmd.exe','/C','javac','-version']) else: run.run(['javac','-version']) except: print "Missing Java SDK. Please make sure Java SDK is on your PATH" sys.exit(1)
def test_map_window_with_state(): x = Stream() y = Stream() @map_w def f(window, state): return sum(window)+state, state+1 f(x, y, window_size=2, step_size=2, state=0) x.extend(list(range(10))) run() assert recent_values(y) == [1, 6, 11, 16, 21]
def test_map_window_list_1(): x = Stream() y = Stream() @map_wl def f(window): return [2*v for v in window] f(x, y, window_size=2, step_size=2) x.extend(list(range(10))) run() assert recent_values(y) == list(range(0, 20, 2))
def test_map_with_keyword_arg(): x = Stream() y = Stream() @map_e def f(v, k): return v+ k f(x, y, k=10) x.extend(list(range(5))) run() assert recent_values(y) == [10, 11, 12, 13, 14]
def test_sink_1(): x = Stream() y = Stream() @sink_w def f(v, out_stream): out_stream.append(sum(v)+10) f(x, window_size=2, step_size=1, out_stream=y) x.extend(list(range(5))) run()
def test_sink_2(): x = Stream() y = Stream() @sink_e def f(v, out_stream): out_stream.append(v+100) f(x, out_stream=y) x.extend(list(range(5))) run()
def compile_translations (): for f_name in glob.glob('po/*.po'): lang = f_name.replace ("po/", "").replace (".po", "") lang = lang.replace ("\\", "/") build_path = "build/locale/" + lang + "/LC_MESSAGES/" target = build_path + "birdfont.mo" run ("mkdir -p " + build_path); f_name = f_name.replace ("\\", "/") run ("msgfmt --output=%s %s" % (target, f_name));
def sel_file(self): sels = self.ui_filelist.getcurselection() if len(sels) == 0: self.file = "" else: self.file = sels[0] self.update_path() runfile = "%s/%s/seq/%s/%s/%s" % (path.ROOT, self.project, self.shot, self.task, self.file) run.run(runfile)
def delete_pattern(directory, pattern): """ Finds and deletes all files matching `pattern` Be careful with this, for obvious reasons. """ run('cd {0} && find . -name "{1}" -print -delete'.format( directory, pattern ))
def compile_into_bytecode(self,paths): jar_path = os.path.join(self.template_dir,"js.jar") for package in paths: args = [self.java,"-cp",jar_path,"org.mozilla.javascript.tools.jsc.Main","-opt","9","-nosource","-package",package,"-d",self.classes_dir] count = 0 for path in paths[package]: # skip any JS found inside HTML <script> if path in self.html_scripts: continue args.append(path) count+=1 self.compiled_files.append(path) if count > 0: run.run(args)
def init(names, products, matrix): if isinstance(names, int): names = m.mockData(names, products) else: '''expected data: list of customers, list of products, list customer arrays containing product purchases in same order as product list.''' buildHistory(names, products, matrix); c.matrixBuilder() recommend = run.run(names) while recommend == 'again': recommend = run.run(names) return recommend
def publish(files, app, version, s3_bucket): v = make_semantic_version(version) # assert version does not exist and is newer old = _list_versions(s3_bucket, app) last = old[-1] if old else None assert v > last for f in files: run("aws s3 cp %(f)s s3://%(s3_bucket)s/%(app)s/%(version)s/" % locals())
def format_src_code(): ''' Format source files using astyle. Exclude the install directory as it is generated. If the install directory is absent (e.g. after running clean) then it will raise an exception. So just try again without excluding install directory. ''' ftypes = "'*.cc' '*.h' '*.tcc' '*.java'" fcmd = "astyle --quiet --recursive --suffix=none" try: run("%s --exclude='install' %s" % (fcmd, ftypes)) except: run("%s %s" % (fcmd, ftypes))
def assemble(): """Creates a build/$version directory with the artifacts to bake into the docker image""" v = get_version(env) prof = cfg.profile(env) files = env.PROJECT_FILES build = cfg.build_dir(v) run("mkdir -p %s" % build) for f in files: expanded_path = f % env recurse = "-r " if path.isdir(expanded_path) else " " run("cp %s%s %s" % (recurse, expanded_path, build))
def base(): global dist, angl global mean_distance, fwd_dist, back_dist rospy.init_node('follower', anonymous=True) pub = rospy.Publisher('cmd_vel', Twist) r=rospy.Rate(10) while not rospy.is_shutdown(): twist = Twist() ch = getch() if ch == '\x03': # stop twist = Twist() pub.publish(twist) break elif ch == 'f': # wall follow rospy.Subscriber("scan", LaserScan, follow.scan_recived) twist = follow.follow(fwd_dist,back_dist) elif ch == 'r': # run away rospy.Subscriber("scan", LaserScan, run.scan_recived) twist = run.run(dist,angl) pub.publish(twist)
def main(): cfg = util.readConfig(util.gcfg( )) cseed = 0 if cfg[MAIN][SEED] == '': cseed = util.seed( ) else: cseed = float(cfg[MAIN][SEED]) random.seed(cseed) util.loadCSV(cfg[AGENT][CSV_FILE]) lg = log( cfg, cseed, util.gcfg( ) ) util.renderHead( cfg ) best = None for i in range( 0, int(cfg[MAIN][RUNS]) ): lg.sep( i ) nbest = run(cfg, i, lg) #Determine if our new potential best is better, # this just uses the average of the two fitness values versus the bad opponents if best == None or nbest.fit > best.fit: if best != None: best.delete( ) best = nbest lg.best(best) lg.absBestFinish(cfg, best) lg.wrapUp(best) print("\n")
def get_sdks(): found = [] ipad = False output = run.run(["xcodebuild","-showsdks"],True,False) #print output if output: for line in output.split("\n"): if line[0:1] == '\t': line = line.strip() i = line.find('-sdk') if i < 0: continue type = line[0:i] cmd = line[i+5:] if cmd.find("iphoneos")==0: ver = cmd[8:] elif cmd.find("iphonesimulator")==0: ver = cmd[15:] else: continue major = int(ver[0]) if major>=3 and ver!='3.0': if not (ver in found): found.append(ver) # ipad is anything 3.2+ if major>3 or ver.startswith('3.2'): ipad=True return (sorted(found,version_sort),ipad)
def compile(include_dir,sdk_version,arch,src_file,obj_file): platform = get_platform(arch) out = run.run([ "/Developer/Platforms/iPhone%s.platform/Developer/usr/bin/gcc-4.2" % platform, "-x", "objective-c", "-arch", arch, "-fmessage-length=0", "-pipe", "-std=c99", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wreturn-type", "-Wunused-variable", "-isysroot", "/Developer/Platforms/iPhone%s.platform/Developer/SDKs/iPhone%s%s.sdk" % (platform,platform,sdk_version), "-gdwarf-2", "-mthumb", "-miphoneos-version-min=%s" % sdk_version, "-I", os.path.dirname(src_file), "-I", include_dir, "-F%s" % os.path.dirname(obj_file), "-c", src_file, "-o", obj_file ]) print out
def test_popen_4(): command = Popen(["cat", "/dev/urandom"]) command = Popen(["tr", "-dc", '"[:alpha:]"'], stdin=command.stdout) command = Popen(["head", "-c", "10"], stdin=command.stdout) assert len(command.communicate()[0]) == len(run("cat /dev/urandom", 'tr -dc "[:alpha:]"', "head -c 10").stdout)
def get_avds(sdk): avds = [] name = None theid = None android = os.path.join(sdk,'tools','android') if platform.system() == "Windows": android += ".bat" for line in run.run([android,'list','target'],debug=False).split("\n"): line = line.strip() if line.find("id: ")!=-1: theid = line[4:] theid = theid[0:theid.find('or ')-1] if line.find("Name:")!=-1: name = line[6:] elif line.find("Based on ")!=-1: version = line[9:] version = version[0:version.find('(')-1] name = "%s %s" % (name,version) elif line.find("Skins: ")!=-1: skins = line[7:].replace(' (default)','').strip().split(", ") avds.append({'name':name,'id':theid,'skins':skins}) return avds
def execute(self, line, cell='', local_ns={}): # save globals and locals so they can be referenced in bind vars user_ns = self.shell.user_ns user_ns.update(local_ns) uid = int(os.environ.get('DROPBOX_UID')) sql = cell if not sql: sql = line try: database, rewritten_sql = self.rewriter.rewrite(sql, uid, user_ns) except RewriterError as ex: return RawMagicError(str(ex)) engine = create_engine("postgresql://%s:%s@%s/%s" % (database['user'], database['password'], database['host'], database['database'])) with closing(engine.connect()) as conn: try: result = run(conn, rewritten_sql, self, user_ns) return result except (ProgrammingError, OperationalError) as e: # Sqlite apparently return all errors as OperationalError :/ if self.short_errors: print(e) else: raise
def cleanup_app_logfiles(): print "[DEBUG] finding old log files" sys.stdout.flush() # on OSX Snow Leopard, we can use spotlight for faster searching of log files results = run.run(['mdfind', '-onlyin', os.path.expanduser('~/Library/Application Support/iPhone Simulator/%s'%iphone_version), '-name', '%s.log'%log_id],True) if results == None: # probably not Snow Leopard def find_all_log_files(folder, fname): results = [] for root, dirs, files in os.walk(os.path.expanduser(folder)): for file in files: if fname==file: fullpath = os.path.join(root, file) results.append(fullpath) return results for f in find_all_log_files("~/Library/Application Support/iPhone Simulator/%s"%iphone_version,'%s.log' % log_id): print "[DEBUG] removing old log file: %s" % f sys.stdout.flush() os.remove(f) else: for i in results.splitlines(False): print "[DEBUG] removing old log file: %s" % i os.remove(i)
def get_avds(sdk): avds = [] name = None theid = None skins = None abis = None for line in run.run([sdk.get_android(),'list','target'],debug=False).split("\n"): line = line.strip() if line.find("id: ")!=-1: theid = line[4:] theid = theid[0:theid.find('or ')-1] if line.find("Name:")!=-1: name = line[6:] elif line.find("Based on ")!=-1: version = line[9:] version = version[0:version.find('(')-1] name = "%s %s" % (name,version) elif line.find("Skins: ")!=-1: skins = line[7:].replace(' (default)','').strip().split(", ") elif line.find("ABIs : ") != -1: abis = line[7:].strip().split(", ") avds.append({'name':name,'id':theid,'skins':skins,'abis':abis}) return avds
def graphDataDiff(request): logger=getLogger() g=Graph.objects.all() for tmp in g: tmp.status="info" tmp.save() print tmp.status cur_runids=getCurRunids() if not cur_runids : result_id=1 else: result_id=int(cur_runids[0]['result_id'])+1 #未来需要大数处理 runIds=request.GET.get('runJobIds') idArr=runIds.split(",") for i in idArr: g=Graph.objects.get(g_id=int(i)) ret=run(result_id,i,g.run_url) if(ret==0): g.status="success" logger.debug(str(i)+' success') else: g.status="error" logger.error(str(i)+' error') g.save() gr=GraphResult(result_id=result_id,g_id=g,status=g.status) gr.save() print g.g_id,g.status redict={"status":"done"} return JsonResponse(redict)
def compile_javascript(self, fullpath): js_jar = os.path.join(self.template_dir, 'js.jar') # poor man's os.path.relpath (we don't have python 2.6 in windows) resource_relative_path = fullpath[len(self.project_dir)+1:].replace("\\", "/") # chop off '.js' js_class_name = resource_relative_path[:-3] escape_chars = ['\\', '/', ' ', '.','-'] for escape_char in escape_chars: js_class_name = js_class_name.replace(escape_char, '_') if self.use_bytecode: jsc_args = [self.java, '-classpath', js_jar, 'org.mozilla.javascript.tools.jsc.Main', '-main-method-class', 'org.appcelerator.titanium.TiScriptRunner', '-nosource', '-package', self.appid + '.js', '-encoding', 'utf8', '-o', js_class_name, '-d', self.classes_dir, fullpath] else: jsc_args = [self.java, '-jar', os.path.join(self.template_dir, 'lib/closure-compiler.jar'), '--js', fullpath, '--js_output_file', fullpath + '-compiled', '--jscomp_off=internetExplorerChecks'] print "[INFO] Compiling javascript: %s" % resource_relative_path sys.stdout.flush() so, se = run.run(jsc_args, ignore_error=True, return_error=True) if not se is None and len(se): sys.stderr.write("[ERROR] %s\n" % se) sys.stderr.flush() sys.exit(1) os.unlink(fullpath) os.rename(fullpath+'-compiled',fullpath)
def create_sys(lammps_command, system_info): """ Uses LAMMPS to generate a System based on the supplied system_info. Arguments: lammps_command -- the lammps command/executable to use. system_info -- LAMMPS input script command lines associated with creating a new system. system_info can be generated using atomman.lammps.sys_gen. """ newline = '\n' script = newline.join([system_info, '', 'mass * 1', 'pair_style none', 'atom_modify sort 0 0.0', '', 'dump dumpit all custom 100000 temp.dump id type x y z', 'dump_modify dumpit format "%i %i %.13e %.13e %.13e"', 'run 0']) f = open('create_sys.in', 'w') f.write(script) f.close() output = run(lammps_command, 'create_sys.in') system = atom_dump.load('temp.dump') os.remove('create_sys.in') os.remove('log.lammps') os.remove('temp.dump') os.remove('temp.dump.json') return system
def link(sdk_version,arch,obj_files,out_file): f,path = tempfile.mkstemp('LinkFileList') os.close(f) f = open(path,"w") try: for name in obj_files: f.write("%s\n" % name) f.close() out = run.run([ "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool", "-static", "-arch_only", arch, "-syslibroot", "/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS%s.sdk" % sdk_version, "-L%s" % os.path.dirname(out_file), "-filelist", path, "-o", out_file ]) print out finally: os.remove(path)
def compile_js_files(): print "[DEBUG] packaging javascript" template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename)) titanium_prep = os.path.abspath(os.path.join(template_dir,'titanium_prep')) cmdargs = [titanium_prep, self.appid, self.assets_dir] cmdargs.extend(js_files) so = run.run(cmdargs) impf.write(so)