def get_host(): host = None (pin,pout) = popen2.popen2(get_cmd('uname')) nom = pin.readline() pin.close() pout.close() if nom == 'Linux\n': (pin,pout) = popen2.popen2(get_cmd('hostname')) nom = pin.readline() pin.close() pout.close() if nom[:5] == 'euler': host = "euler08" elif nom[-10:-1] == "clickroot": host = "chicken" elif len(nom) < 4: host = "chicken" else: host = "linux" elif nom == 'SunOS\n': host = "sun" else: sys.stderr.write("I don't know about this host-type: %s\n" % nom) assert 0 assert host return host
def main(file): s = song_rw.load_song(file) if s: abc2midi = preferences.get_external_prog_path('ABC2MIDI') if not abc2midi: print '\n' + _("abc2midi program not found."), _("Please, check your preferences file (") + preferences.preferences_file + ")" sys.exit(2) midiplayer = preferences.get_external_prog_path('MIDIPLAYER') if not midiplayer: print '\n' + _("MIDI player program not found."), _("Please, check your preferences file (") + preferences.preferences_file + ")" sys.exit(2) final_song = s.generate_song(preferences.get_prefered_instruments()) input = tempfile.mktemp('.abc') abc_file = open(input, 'w') output = os.path.abspath(os.path.dirname(file) + '/' + s.id + '.mid') for l in final_song: abc_file.write(l + "\n") abc_file.close() command = abc2midi + ' "' + input + '" -o "' + output + '"' print '\n' + _("Executing: ") + command print '\n' + _("MIDI file saved on ") + output popen2.popen2(command) command = midiplayer + ' "' + output + '"' print '\n' + _("Executing: ") + command os.system(command) else: print '\n' + _("There was some problem while loading the song file ") + os.path.normpath(file) + '\n' + _("Please, check that file.")
def spaceLeft (inputDir): """ spaceLeft: returns the number of free KB in inputDir """ # returns the number of free KB left in inputDir if not os.path.isdir (inputDir): sys.exit ("spaceLeft ERROR: $inputDir is not a directory\n ") if not os.access(inputDir, os.W_OK): # It's not much sense to check space without a write permission ... warning('you have no write permission in $inputDir') # important warning dfOutput = popen2.popen2("df --portability -k "+inputDir)[0].readlines()[1] if string.split(dfOutput)[0]=="AFS": # Use listquota to get space left in AFS volume: lqOutputSplit = \ string.split\ (popen2.popen2 ("fs listquota "+ inputDir)[0].readlines()[1]) if lqOutputSplit[1] == "no" and lqOutputSplit[2] == "limit": #There is no quota, so look at volume size lqOutputSplit = \ string.split\ (popen2.popen2 ("fs listquota "+ inputDir)[0].readlines()[1]) dfOutput = popen2.popen2("fs diskfree " + inputDir) available = float(lqOutputSplit[3]) else: available = float(lqOutputSplit[1]) - float(lqOutputSplit[2]) else: available = float(string.split(dfOutput)[3]) infoOut( "spaceLeft: "+str(available)+" KB free in directory "+inputDir) return available
def doPopupMessage(msg,alt=""): import popen2 if alt == "": out,junk = popen2.popen2(cocoadialog + ' ok-msgbox --no-cancel --float --text "'+msg+'"') else: out,junk = popen2.popen2(cocoadialog + ' ok-msgbox --no-cancel --float --text "'+msg+'" --informative-text "'+alt+'"') return out.readline()[:-1]
def send_jobs(datasets,my_mem,controller,queue): for data in datasets: if controller == "slurm": output, input = popen2('sbatch') else: output, input = popen2('qsub') job_name = "UGAP_%s" % data[0] walltime = "48:00:00" command = "python %s/ugap_single.py -n %s -f %s -v %s -e %s -k %s -t %s -r %s -p %s -x %s -z %s -b %s -o %s" % (data[9],data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9],data[10],data[11]) if controller == "slurm": memory = "mem=%s" % my_mem job_string = \ """#!/bin/sh #SBATCH -p %s #SBATCH -J %s #SBATCH -c %s #SBATCH --time %s #SBATCH --mem=%s %s""" % (queue, job_name, data[7], walltime, my_mem, command) input.write(job_string) input.close() print job_string print output.read() elif controller == "torque": memory = "mem=%s" % my_mem processors = "nodes=1:ppn=%s" % data[7] job_string = """#!/bin/bash #PBS -N %s #PBS -l walltime=%s #PBS -l %s #PBS -l mem=%s #PBS -j oe #PBS -m a #PBS -q %s cd $PBS_O_WORKDIR %s""" % (job_name, walltime, processors, my_mem, queue, command) input.write(job_string) input.close() print job_string print output.read() elif controller == "sge": memory = "mem_free=%s" % my_mem job_string = """ #!/bin/bash #$ -N %s #$ -P %s #$ -l %s #$ -cwd %s""" % (job_name,queue,memory,command) input.write(job_string) input.close() print job_string print output.read()
def __init__(self): Lister.__init__(self) # The command below must work on linux (UNIX), # other platfroms may need more tweaking. self._Uname = popen2.popen2("uname -a")[0].readlines() self._Hostname = popen2.popen2("hostname")[0].readlines() self._Nisdomainname = popen2.popen2("nisdomainname")[0].readlines() self._Dnsdomainname = popen2.popen2("dnsdomainname")[0].readlines() self._Bintype = ''
def export(evt): """ Export Database""" import popen2 from BarWriter import BARWRITER BARWRITER.write("Backup start...") popen2.popen2('../SQL/backup.sh') BARWRITER.write("Backup complete...")
def get_command_output(cmd): if os.name == "posix": dout, din = popen2.popen2('{ ' + cmd + '; } 2>&1') else: dout, din = popen2.popen2(cmd + ' 2>&1') res = dout.readlines() dout.close() din.close() return res
def onRunJava(self, e): if self.onCompileJava(-1): popen2.popen2(self.dir[0:2]) popen2.popen2("cd "+self.dir) cmdout, cmdin = popen2.popen2("java "+self.filename[:-5]) self.sendMessage('Log', 'File running from '+self.dir+'\\'+self.filename[:-5]+'.class') self.sendMessage('Output', cmdout.read().strip()) else: self.sendMessage('Log', 'Fail to run due to failture in compiling')
def test_foo(idx, DIR): case_idx = str(idx) if DIR == IN_DIR: sample = "tmp.trace.Sample-" + case_idx + ".xml" elif DIR == ONLINE_CHI_DIR: sample = case_idx + ".trace.xml" elif DIR == ONLINE_ENG_DIR: sample = case_idx + ".trace.xml" else: sys.exit(2) #O_SUFF = " " O_SUFF = " -o " out_tmp = OUT_DIR + "case" + case_idx + ".xml" print out_tmp std_out, std_in = popen2.popen2("python3 __init__.py -i" + DIR + sample + O_SUFF + out_tmp) ostr = std_out.read() tree_log = "@@@@@@@@@@@@@@@@@ EG TREE : \n" tree_log += ostr diff_files = GOLDEN_DIR + "case" + case_idx + ".xml" + " " + out_tmp is_differ = os.system("diff -q " + diff_files) err_log = "" if 0 != is_differ: #err_log = os.system("diff " + diff_files) #err_log = # pass # print ("aaaaaaaaaaaaaaaa") std_out, std_in = popen2.popen2("diff " + diff_files) #print ("std_out :: ", std_out) ostr = std_out.read() #print (ostr) err_log += "@@@@@@@@@@@@@@@@@@ DIFF :\n" err_log += ostr ##print ("std_in :: ", std_in.read()) #if is_differ != 0 #print is_differ result = diffRecorder(is_differ) #fp_o = open("out_new/out" + case_idx + ".xml", "w") msg = FILLER + "\tcase" + case_idx + "\t" + FILLER + "\n" msg += tree_log msg += FILLER1 + " end of EG Tree log " + "\n\n" if 0 != is_differ: msg += err_log msg += FILLER1 + " end of err_log " + "\n\n" msg += result msg += "\n" msg += FILLER2 + "\tend of case" + case_idx + "\t" + FILLER2 + "\n\n" fp_o.write(msg) fp_o.flush() #fp_o.close() print "\n" + msg + "\n"
def testOtherProcess(self, fpath, **kwargs): n = 10 for x in xrange(n): self.app.setThermo('build_pdf', x, 'Elaboro') time.sleep(1) fname = '%s.%s' % (fpath, str(time.time())) f = open(fname, 'w') f.write('ciao') f.close() self.app.setThermo('build_pdf', command='end') popen2('lpr %s' % fname)
def RunExpandMSU(self,filename): tmp_dir=self.GetFileTmpDir(filename) cmdline="expand -f:* %s %s" % (filename, tmp_dir) try: os.makedirs(tmp_dir) except: pass popen2.popen2(cmdline) self.TmpDirs.append(tmp_dir) return tmp_dir
def extract(self, fpatch=None): """ """ patchee = fpatch if fpatch else self._patchee if not patchee: raise Exception( 'Patch file missed?' ) # TODO handle msu/msp/msi if patchee[-4:] == '.exe': popen2.popen2( patchee + " /x:" + self._tmpdir + " /quiet" ) return True return False
def main(): stdout, stdin = popen2('df .') stdout.readline() #stip column headers data = [field for field in stdout.readline().split(' ') \ if field.endswith('%')] used = int(data[0][:-1]) if used > 70: alert.alert('Disk space used at '+str(used)+'%' , '') stdout, stdin = popen2("free -tm | awk '/Mem:/ {print $4}'") free = int(stdout.readline().rstrip()) if free < 45: alert.alert('Memory free at %s MB' % free, '')
def cgiFake(sroot, verbose, prog, args): """Run the local program prog as a CGI using the POST method.""" content = urllib.parse.urlencode(args) length = len(content) # setup CGI environment env = os.environ.copy() env['REQUEST_METHOD'] = "POST" env['NETSITE_ROOT'] = sroot env['CONTENT_LENGTH'] = str(length) progdir = os.path.dirname(prog) if HASPOPEN: pipe = Popen(prog, cwd=progdir, env=env, stdin=PIPE, stdout=PIPE, stderr=STDOUT) child_stdin = pipe.stdin child_stdout = pipe.stdout else: saveenv = os.environ os.environ = env child_stdout, child_stdin = popen2.popen2(prog) os.environ = saveenv child_stdin.write(content) child_stdin.close() for line in child_stdout: if verbose: sys.stdout.write(line) ary = line.split(":") if len(ary) > 1 and ary[0] == 'NMC_Status': exitCode = ary[1].strip() break child_stdout.close() if HASPOPEN: osCode = pipe.wait() print("%s returned NMC code %s and OS code %s" % (prog, exitCode, osCode)) return exitCode
def tsne(args): # Convert CSV to TSV for tSNE (child_stdout, child_stdin) = popen2.popen2("sed 1d %s | perl -ne 's/,/\t/g; print' | ./barnes-hut-sne/bhtsne.py" % args.infile) points = [] for l in child_stdout: points.append([float(i) for i in string.split(l)]) return points
def test_1_generate(self): cmd = 'python ../generateDS.py -f -o out2sup.py -s out2sub.py --super=out2sup -u gends_user_methods people.xsd' outfile, infile = popen2.popen2(cmd) result = outfile.read() outfile.close() infile.close() self.failUnless(len(result) == 0)
def connect(self, host="doesnt_matter", port=0): r, w = popen2(SENDMAIL, 1) self.file = FileDummy(r, w) self.sock = SocketDummy(self.file) (code, msg) = self.getreply() if self.debuglevel > 0 : print "connect:", msg return (code, msg)
def start(self,callback): # this is UDP send (the reader) logger.debug("open monitor: %s" % (self.scanner_path)) r, w = popen2.popen2(self.scanner_path) logger.debug("after opening monitor") ret = r.readline() logger.debug("written line is: %s" % (ret)) res = ret.rstrip('\n') # may need to change for windows self.btscan_pid = 999999 try: self.btscan_pid = int(res) except: logger.error("failed to launch btscan") self.stop() return logger.debug("scanner PID: %s" % (self.btscan_pid)) # something here to wait. # might even be able to put the consumer.. reader here. f = open(self.scanner_pipe, "r") line = "1" while ( line != "" and not self.stopme): line = f.readline() if(line != ""): # do stuff logger.debug("READ %s" % (line)) callback( {"raw": line } ) logger.debug("Ended reading from file") f.close() r.close() w.close()
def Demangle(self): """Evil command line lookup of method name from mangled variant""" (outt, inn) = popen2.popen2('c++filt \'%s\'' % self.MangledMethodName) self.MethodName = outt.read().strip() outt.close() inn.close() return self.MethodName
def isSaverEnabled(self, avatar): if not os.environ.has_key("XAUTHORITY"): os.environ["XAUTHORITY"] = os.environ["USER_XAUTHORITY"] remove_xauth = True else: remove_xauth = False # Run 'xset q' and determine the setting of the screen saver timeout. (child_stdout, child_stdin) = popen2.popen2([self.mCmd, "q"]) # Read the output from 'xset q'. This is not done using readlines() # because that could fail due to an interrupted system call. Instead, # we read lines one at a time and handle EINTR if an when it occurs. lines = [] done = False while not done: try: line = child_stdout.readline() if line == "": done = True else: lines.append(line) except IOError, ex: if ex.errno == errno.EINTR: continue else: raise
def _cpp_get_pipe(filename = None, cpp = None, options = None, include_dirs = None, defines = None): # Set defaults for optional parameters if cpp is None: cpp = 'cpp' if options is None: options = [] if include_dirs is None: include_dirs = [] if defines is None: defines = [] # Build the command line. cpp_command_line = ' '.join ([cpp] + options \ + ['-I%s' % (incdir) for incdir in include_dirs] + ['-D%s' % (define) for define in defines] ) # We accept an optional filename - it's good to have it because # cpp includes its output. if filename: cpp_command_line += ' %s' % (filename) # Run cpp. child_out, child_in = popen2.popen2(cpp_command_line) return child_out, child_in
def TM(x, ffrom, tto, TM, BINPATH=ANCILLARY_PATH): oristdout = sys.stdout fin, sys.stdout = popen2.popen2(BINPATH+"/TM") z = atmList(x[ffrom:tto].atms) crds = z.crds() # sys.stderr.write("TM: crds %s\n" % str(crds) ) print len(z) for i in crds: print i print TM[0] print TM[1] print TM[2] print TM[3] sys.stdout.close() sys.stdout = oristdout orirmsd = string.split(orirmsd[0])[2] rmsd = string.split(rmsd[0])[1] print "REMARK ",sys.argv[1]," (",len(x),")", sys.argv[2]," (",len(y),")" print "REMARK ",from1, to1, from2, to2,"match len :",len(xs) print "REMARK Initial RMSd : ",orirmsd print "REMARK Best fit RMSd : ",rmsd rs = [] for i in range(0,len(z)): lrs= fin.readline() # sys.stderr.write("%s" % lrs) rs.append(z.list[i][0:30]+lrs[:-1]+z.list[i][54:-1]) return rs
def __init__(self, user): global prompt prompt = login_prompt self.cout, self.cin = popen2.popen2('sqlplus') getprompt(self, 0, 15) prompt = passwd_prompt try: self.sql(user+'\n', 15) except: raise prompt = sql_prompt try: self.sql(sqloracfg.passwd[user]+'\n', 15) except: raise try: self.sql('set heading off;\n', 15) except: raise try: self.sql('set linesize 300;\n', 15) except: raise try: self.sql('set tab off;\n', 15) except: raise
def make_trustdb(trust): print "updating trustdb" cmd = "gpg --homedir %s --import-ownertrust" % homedir (stdout,stdin) = popen2.popen2(cmd) for id in trust.keys(): stdin.write("%s:%d:\n" % (id, trust[id])) stdin.close()
def GetShellScriptEnv( os_env, script ): os_environ = os.environ if (sys.platform == "win32"): shell = os_environ.get("COMSPEC", "cmd.exe") script = 'call ' + script else: shell = '/bin/sh' script = '. ' + script cmdout, cmdin = popen2.popen2( shell ) cmdin.write( script + "\n" ) cmdin.write( "set\n" ) cmdin.close() env = cmdout.readlines() cmdout.close() for arg in env: match = re.search(r'^\w+=', arg ) if match: index = arg.find('=') name = arg[:index] value = arg[index + 1:].rstrip('\n \t\r') current = os_environ.get( name ) if (current is None) or (value != current): os_env[ name ] = value
def get_array_status(array): "Determine and return status for the three disks in one array." # The mdadm -QD command will give us the details we need. try: outf, inf = popen2.popen2("mdadm -QD /dev/%s" % array) except OSError, e: err("%s: %s" % (e.filename, e.strerror))
def my_popen(cmd_l, stdout=None): class MockPopenResult(object): def wait(self): pass p = MockPopenResult() p.stdout, p.stdin = popen2(cmd_l) return p
def __getProcessLine(self, userName): platform = sys.platform.lower() # Set up the flags to pass to ps(1) so that we get the same formatting # of the output on all platforms. if platform.startswith('freebsd') or platform.startswith('darwin'): args = ['-wxu', '-U', userName] else: args = ['-fu', userName] (child_stdout, child_stdin) = popen2.popen2(["/bin/ps"] + args) # Read the output from 'ps ...'. This is not done using readlines() # because that could fail due to an interrupted system call. Instead, # we read lines one at a time and handle EINTR if an when it occurs. lines = maestro.util.readlinesRetryOnEINTR(child_stdout) child_stdout.close() child_stdin.close() process_line = None for l in lines: if self.cmd_re.search(l) is not None: process_line = l break return process_line
def bestFit(self, getFit = 0): oristdout = sys.stdout cmd = self.binPath+"/"+self.method+" " if getFit: cmd += "-bfxyz " fin, sys.stdout = popen2.popen2(cmd) # We send data to method print self.ncrd for i in self.qxyz: print i[0],i[1],i[2] for i in self.txyz: print i[0],i[1],i[2] sys.stdout.close() sys.stdout = oristdout # we get the results self.orirmsd = fin.readline(), self.bestrmsd = fin.readline(), self.M1 = fin.readline() self.M2 = fin.readline() self.M3 = fin.readline() self.M4 = fin.readline() self.ocrd = [] if getFit: for i in range(0,self.ncrd): self.ocrd.append(fin.readline()[:-1]) fin.close() # return the result return string.split(self.orirmsd[0])[1], string.split(self.bestrmsd[0])[1], self.M1, self.M2, self.M3, self.M4, self.ocrd
def getDefaultConcurrency(self): args = [ BHOSTS, ] args.extend(self.getOptionList()) stdout, stdin = popen2.popen2(args) stdin.close() aCpuNumber = 0 for i in stdout: aCpuNumber = aCpuNumber + 1 return aCpuNumber
def preammp_protein_textfile_maker(AMMP_path,protein_file): command ='pwd' fhin,fhout = popen2.popen2(command) for line in fhin: working_path = line atoms_path = AMMP_path + '/progs/preammp/' ############################# preammp_fhin = open('preammp_protein.txt','w') preammp_fhin.write(atoms_path + 'atoms.sp4\n') preammp_fhin.write(atoms_path + 'pdb\n') preammp_fhin.write(protein_file+'\n') preammp_fhin.write('preammpoutput_protein.ammp\n') preammp_fhin.close()
def preammp_ligand_textfile_maker(AMMP_path): command ='pwd' fhin,fhout = popen2.popen2(command) for line in fhin: working_path = line atoms_path = AMMP_path + '/progs/preammp/' ############################# preammp_fhin = open('preammp_ligand.txt','w') preammp_fhin.write(atoms_path + 'atoms.sp4\n') preammp_fhin.write(working_path) preammp_fhin.write('input_ligand.pdb\n') preammp_fhin.write('input_ligand.ammp\n') preammp_fhin.close()
def osNetworkMappingIsMapped(driveLetter='Z', mappedPath='D:\\'): mappedPath = os.path.normpath(mappedPath) (r, w) = popen2.popen2('net use') result = r.readlines() r.close() w.close() for eachLine in result: if str(driveLetter + ':') in eachLine and str(mappedPath) in eachLine: return True return False
def stemWord(str): if str in stemmed_words: return stemmed_words[str] fin, fout = popen2.popen2(stemmer + " -l ta") fout.write(str) fout.write("\n") fout.close() res = fin.readlines() fin.close() if not res: stemmed_words[str] = str return str stemmed_words[str] = res[0] return res[0]
def getpdisks(controller="0"): cmd = [ "omreport", "storage", "pdisk", "controller=" + controller, "-fmt", "xml" ] (omstdin, omstdout) = popen2.popen2(cmd) tree = ElementTree() root = tree.parse(omstdin) iter = root.getiterator() pdisks = [] for element in iter: if element.tag == "DCStorageObject": pdisks.append(pdisk(element)) return pdisks
def copy(self, clean, prefix, updatedb): """Copy all the pallets from the CD to Disk""" # Populate the info hash. This hash contains pallet # information about all the pallets present on disc. r, w = popen2.popen2('find %s -type f -name roll-\*.xml' % self.mountPoint) dict = {} for filename in r.readlines(): roll = stack.file.RollInfoFile(filename.strip()) dict[roll.getRollName()] = roll if len(dict) == 0: # If the roll_info hash is empty, that means there are # no Rocks recognizable rolls on the Disc. This mean # it may just be a normal OS CD like CentOS, RHEL, # Scientific Linux or Solaris. In any case it's a # foreign CD, and should be treated as such. # # Check the OS of the CD. This is pretty easily # discernable. A .treeinfo file in the root of the CD # implies an RHEL based disc, and a .cdtoc file in the # root of the CD implies a Solaris 10 disc. treeinfo = os.path.join(self.mountPoint, '.treeinfo') cdtoc = os.path.join(self.mountPoint, '.cdtoc') if os.path.exists(treeinfo): res = self.runImplementation('foreign_redhat', (clean, prefix, treeinfo)) if res and updatedb: self.insert(res[0], res[1], '', res[2], 'redhat') else: raise CommandError(self, 'unknown os on media') # # Keep going even if a foreign pallet. Safe to loop over an # empty list. # # For all pallets present, copy into the pallets directory. for key, info in dict.items(): self.runImplementation('native_%s' % info.getRollOS(), (clean, prefix, info)) if updatedb: self.insert(info.getRollName(), info.getRollVersion(), info.getRollRelease(), info.getRollArch(), info.getRollOS())
def main(code_path, jy_exe="jython", print_diff=True, print_fail=False, print_success=False, print_diff_lines=False): from pprint import pprint from popen2 import popen2 from StringIO import StringIO from difflib import Differ if os.path.isdir(code_path): pyfiles = globwalk.GlobDirectoryWalker(code_path, "*.py") else: pyfiles = [code_path] for pyfile in pyfiles: ast = parser().parse([pyfile]) lispified = lispify_ast(ast) sio = StringIO() pprint(lispified, stream=sio) fin, fout = popen2("python astlib2.py %s" % pyfile) sio.seek(0) jstr = sio.readlines() pstr = fin.readlines() differs = False diffstr = [] difflines = 0 diff = Differ() results = diff.compare(pstr, jstr) for d in results: diffstr.append(d) if d[0] in ['+', '-']: differs = True difflines += 1 if print_success and not differs: print "SUCCESS: %s" % pyfile if print_fail and differs: print "FAIL: %s" % pyfile if print_diff_lines: print "%s diff lines in %s" % (difflines, pyfile) if print_diff and differs: print "---------- ouput -------------" print "py: %s" % sio.getvalue() print "jy: %s" % "".join(jstr) print "---------- DIFF -------------" print "".join(diffstr)
def copy(self, clean, prefix, updatedb): """Copy all the pallets from the CD to Disk""" # Populate the info hash. This hash contains pallet # information about all the pallets present on disc. r, w = popen2.popen2('find %s -type f -name roll-\*.xml' % self.mountPoint) dict = {} for filename in r.readlines(): roll = stack.file.RollInfoFile(filename.strip()) dict[roll.getRollName()] = roll if len(dict) == 0: # If the roll_info hash is empty, that means there are # no stacki recognizable rolls on the Disc. This mean # it may just be a normal OS CD like CentOS, RHEL, # Ubuntu, or SuSE. In any case it's a # foreign CD, and should be treated as such. # self.loadImplementation() impl_found = False for i in self.impl_list: if hasattr(self.impl_list[i], 'check_impl'): if self.impl_list[i].check_impl(): impl_found = True res = self.runImplementation(i, (clean, prefix)) break if not impl_found: raise CommandError(self, 'unknown os on media') if res and updatedb: self.insert(res[0], res[1], res[2], res[3], res[4]) # # Keep going even if a foreign pallet. Safe to loop over an # empty list. # # For all pallets present, copy into the pallets directory. for key, info in dict.items(): self.runImplementation('native_%s' % info.getRollOS(), (clean, prefix, info)) if updatedb: self.insert(info.getRollName(), info.getRollVersion(), info.getRollRelease(), info.getRollArch(), info.getRollOS())
def run(p): k = 0 for sta in p['stalist']: for cha in p['chalist']: comandLine = 'python postprocessing/parse_results.py \ -d data/waveforms%s/fingerprints/\ -p candidate_pairs_%s_%s \ -i data/global_indices/%s_%s_idx_mapping.txt' k += 1 cmd = comandLine % (sta, sta, cha, sta, cha) print cmd if k != 10: continue print cmd #print comps, sta.station, date # Open a pipe to the qsub command. output, input = popen2('qsub') # Customize your options here job_name = sta + '.' + cha nnodes = 16 processors = "nodes=1:ppn=%s" % nnodes command = cmd #"002.CorrelBinsSingleRotation.py -p %s -d %s -s %s -c %s -t %s -v" %(path, date, target, comps, nthreads) node = 'beroza' print os.getcwd() job_string = """ #!/bin/bash\n\ #PBS -N %s\n\ #PBS -q %s\n\ #PBS -l %s\n\ #PBS -o out/%s.out\n\ #PBS -e out/%s.err\n\ cd $PBS_O_WORKDIR\n\ %s""" % (job_name, node, processors, job_name, job_name, command) # Send job_string to qsub input.write(job_string) input.close() # Print your job and the system response to the screen as it's submitted print job_string print output.read() time.sleep(1.0000) print os.getcwd() # os.system('echo "%s %s %s" >> o.txt'%(bin, target, k )) njob = int(commands.getoutput('qstat -u zspica | wc -l')) while njob >= 10: njob = int(commands.getoutput('qstat -u zspica | wc -l')) time.sleep(60)
def axeRot(self) : oristdout = sys.stdout cmd = ANCILLARY_PATH+"/"+method fin, sys.stdout = popen2.popen2(cmd) print self.at1.x, self.at1.y, self.at1.z print self.at2.x, self.at2.y, self.at2.z print self.angle sys.stdout.close() sys.stdout = oristdout self.M1 = fin.readline() self.M2 = fin.readline() self.M3 = fin.readline() self.M4 = fin.readline()
def IPtoASN(IPlist): ASNlist = {} for IP in IPlist: try: ASNOut, IPIN = popen2.popen2("whois -h whois.cymru.com -c " + IP) SeparateASN = (ASNOut.read()).split("\n") temp = SeparateASN[2].split('|') ASN = temp[0] Country = temp[2] if ASN not in ASNlist: ASNlist[ASN] = Country except: continue return ASNlist
def blur2d(a, w): x, y, c = shape(a) bin = "./blur2d" if os.stat(bin + ".c").st_mtime > os.stat(bin).st_mtime: os.system("make " + bin) g, f = popen2.popen2("%s %s %s %s" % (bin, x, y, c)) f.write(w[:, :, 0].astype('f').tostring()) f.write(a.astype('f').tostring()) tmp = fromstring(g.read(x * y * c * 4), "f") return reshape(tmp, shape(a))
def getpower(): cmd = ["omreport", "chassis", "pwrsupplies", "-fmt", "xml"] (omstdin, omstdout) = popen2.popen2(cmd) tree = ElementTree() root = tree.parse(omstdin) iter = root.getiterator() status = "" pwrsupplies = [] for element in iter: if element.tag == "Redundancy": status = element.get("status") redunstatus = element.findtext("RedunStatus") if element.tag == "PowerSupply": pwrsupplies.append(powersupply(element)) return [(status, redunstatus), pwrsupplies]
def submit_experiment(experiment): filename = experiment.foldername + "experiment_instance.bin" f = open(filename, 'w') dump(experiment, f) f.close() command = "OMP_NUM_THREADS=1 nice -n 10 python " + experiment.dispatcher_filename + " " + filename job_name = filename.split(os.sep)[-2].split(".")[0] walltime = "walltime=99:59:59" processors = "nodes=1:ppn=1" memory = "pmem=2gb" workdir = experiment.foldername output = experiment.foldername + ClusterTools.cluster_output_filename error = experiment.foldername + ClusterTools.cluster_error_filename job_string = """ #PBS -S /bin/bash #PBS -N %s #PBS -l %s #PBS -l %s #PBS -l %s #PBS -o %s #PBS -e %s cd %s %s""" % (job_name, walltime, processors, memory, output, error, workdir, command) # send job_string to qsub outpipe, inpipe = popen2('qsub') print job_string inpipe.write(job_string) inpipe.close() job_id = outpipe.read().strip() outpipe.close() print job_id try: qsub_filename = experiment.experiment_dir + ClusterTools.qsub_filename f = open(qsub_filename, 'a') f.write(job_id + "\n") f.close() except IOError: print "could not save job id to file", qsub_filename time.sleep(0.1)
def FindEntriesWithAgrep(search, fuzzy=0): search = NormalizedSearchString(search) (o,i) = popen2.popen2('agrep -' + str(fuzzy) + ' -e "' + search + '"') threading.Thread(target = WriteThread, args = (i, BibEntriesSearchString)).start() res = [] res = o.read() res = string.split(res, '\n') num = [] for a in res: try: b = string.replace(a[4:12], '#', '') n = int(b) num.append(n) except: pass return num
def machine_get_clipboard(): result = [] from popen2 import popen2 wish_path = os.environ['PYMOL_PATH']+"/ext/bin/wish8.0" # dubious... if not os.path.exists(wish_path): wish_path = "/usr/bin/wish" if os.path.exists(wish_path): pipe = popen2(wish_path) pipe[1].write("puts [ selection get ]\n") pipe[1].write("exit\n") pipe[1].close() while 1: l=pipe[0].readline() if not l: break result.append(l) return result
def set_face(w, f): w.set_data("face", f) if not sqmail.preferences.get_usexfaces(): return decoder = sqmail.preferences.get_xfacedecoder() pipefp = popen2.popen2(decoder) pipefp[1].write(f) pipefp[1].close() pixdata = sqmail.utils.load_xpm(pipefp[0]) if not pixdata: sqmail.gui.utils.errorbox( "I was unable to decode an X-Face string. See the error message on the console." ) return set_xpm(w, pixdata)
def __init__(self, command): try: infile, outfile = popen2.popen2(command) except: print "popen2 failed" sys.exit(1) self.infile = infile self.outfile = outfile # total number of gtpa-logfiles for i in range(1000): log_name = "gtpa%03i.log" % i if not os.path.exists(log_name): break self.log_fp = open(log_name, "w") self.log_fp.write(command+"\n") self.log_fp.flush()
def create_temporary_ca_path(anchor_list, folder): """ Create a CA path folder as defined in OpenSSL terminology, by storing all certificates in 'anchor_list' list in PEM format under provided 'folder' and then creating the associated links using the hash as usually done by c_rehash. Note that you can also include CRL in 'anchor_list'. In that case, they will also be stored under 'folder' and associated links will be created. In folder, the files are created with names of the form 0...ZZ.pem. If you provide an empty list, folder will be created if it does not already exist, but that's all. The number of certificates written to folder is returned on success, None on error. """ # We should probably avoid writing duplicate anchors and also # check if they are all certs. try: if not os.path.isdir(folder): os.makedirs(folder) except: return None l = len(anchor_list) if l == 0: return None fmtstr = "%%0%sd.pem" % math.ceil(math.log(l, 10)) i = 0 try: for a in anchor_list: fname = os.path.join(folder, fmtstr % i) f = open(fname, "w") s = a.output(fmt="PEM") f.write(s) f.close() i += 1 except: return None r, w = popen2.popen2("c_rehash %s" % folder) r.close() w.close() return l
def set_display(): disp = ":0" auth = "" proc = "-C X -C Xorg -C XFree86" ps = "/bin/ps " + proc + " --format args --no-headers" r, w = popen2.popen2(ps) arg = string.split(r.read()) for i in range(1, len(arg)): if arg[i][0] != '-' and i == 1: disp = arg[i] elif arg[i] == "-auth": auth = arg[i + 1] break os.environ['DISPLAY'] = disp os.environ['XAUTHORITY'] = auth
def __init__(self, data): if 'txt_from' in data: self.txt_from = data['txt_from'] cmd = "/home/manwe/projects/sr/web/1.sh" sin, sout = popen2(cmd) sout.write(self.txt_from.encode("utf-8")) sout.close() self.txt_to = "" for i in sin: self.txt_to += unicode(i, "utf-8") elif 'txt_to' in data: self.txt_to = data['txt_to'] else: self.txt_from = "" self.txt_to = ""
def preprocess_and_grab_data(self, filename_list): # Make a tiny C file containing all the filenames as included. cpp_file = ['#include "%s"' % (filename) for filename in filename_list] cpp_file = '\n'.join(cpp_file) + '\n' # Ensure that the specified cpp actually exists full_cpp_path = usr_bin_which(self.cpp) if full_cpp_path is None: raise CPPNotFoundError("C pre-processor '%s' not found" % self.cpp) cpp_command_line = ' '.join ([self.cpp] + self.cpp_options \ + ['-I%s' % (incdir) for incdir in self.include_dirs] + ['-D%s' % (define) for define in self.defines] ) debug_import ("***** cpp: %s" % (cpp_command_line)) child_out, child_in = popen2.popen2(cpp_command_line) child_in.write(cpp_file) child_in.close() return child_out.read()
def add_jira_status(commits): commit_lines = commits.split("\n") new_commits = [] for commit in commit_lines: if re.match(".*https://issues.apache.org/.*", commit): jira = re.findall("QPID-[0-9]*", commit)[0] jira_xml_url = "http://issues.apache.org/jira/si/jira.issueviews:issue-xml/%s/%s.xml" % ( jira, jira) (stdout, stdin) = popen2("wget -q -O - %s" % jira_xml_url) jira_dom = parse(stdout) status = jira_dom.getElementsByTagName("status")[0] new_commits.append("%s %s | " % (commit, status.lastChild.data)) else: new_commits.append(commit) return "\n".join(new_commits)
def get_pipe(self): self.get_files() # use an array for the command to avoid the shell and potential # security exposures cmd = ["diff"] \ + self.diffoptions \ + [self.tempfile1, self.tempfile2] # the windows implementation of popen2 requires a string if _sys.platform == "win32": cmd = _svncore.argv_to_command_string(cmd) # open the pipe, forget the end for writing to the child (we won't), # and then return the file object for reading from the child. fromchild, tochild = _popen2.popen2(cmd) tochild.close() return fromchild
def disassemble(filename): """From a filename, returns a list of all asm instructions.""" cmd = "i586-mingw32msvc-objdump -d %s " % filename o, i = popen2.popen2(cmd) def floupi(line): line1 = line.split('\t') if len(line1) > 2: line2 = line1[2] else: line2 = line1[0] line3 = line2.split(' ') if len(line3) > 1: inst = line3[0] else: inst = line3[0] return inst inst = [floupi(i) for i in o] return inst
def DomainToIP(domain): IPlist = [] domain = "".join(domain.split()) for dns in [" ", " 139.175.55.244", " 8.8.8.8"]: DataOut, DataIn = popen2.popen2("host -t A " + domain + dns) SeparateIP = DataOut.readlines() for i in range(len(SeparateIP) - 1): temp = SeparateIP[i].split() if len(temp) > 0: try: IP = temp[3] if IP not in "alias": if IP not in IPlist: IPlist.append(IP) except: continue return IPlist
def qsub_hmmsearch(xargs_input_file, num_nodes=1, num_threads=1, memmory_size='1GB', time_limit='170:00:00', working_dir='~', genome_dir='.', profile_dir='.'): # Open a pipe to the qsub command. qsub_out, qsub_in = popen2('sbatch') # Customize your options here job_string = """#!/bin/bash #SBATCH -p sched_mit_g4nier #greg's partition on the cluster #SBATCH -N {num_nodes} #number of nodes #SBATCH -c {num_threads} #number of cores #SBATCH --mem={memmory_size} #max amount of memory #SBATCH --time={time_limit} #wall time #SBATCH -J hmmsearch #job name #SBATCH --output=hmmsearch.out #output name #SBATCH --error=hmmsearch.err #error file name #SBATCH [email protected] #if you want emails upon start/finish module load engaging/hmmer/3.1b2 cd {working_dir} cat {input_file} | xargs -n 2 -P {simultaneous_processes} sh -c 'hmmsearch --acc --noali --cpu 1 -o $1_-_$2.hmm_out {profile_dir}/$1 {genome_dir}/$2' sh """.format(input_file=xargs_input_file, num_nodes=num_nodes, num_threads=num_threads, memmory_size=memmory_size, time_limit=time_limit, working_dir=working_dir, simultaneous_processes=num_threads * num_nodes, genome_dir=genome_dir, profile_dir=profile_dir) # Send job_string to qsub qsub_in.write(job_string) qsub_in.close() # Print your job and the system response to the screen as it's submitted return qsub_out.read()
def __PrivateFile(self, aLocalView): """ Return a list with all private and cheked out files in <aLocalView> view. """ myClearCaseCommand = 'cleartool lsprivate -tag ' + aLocalView myPrivateFileList = [] (mystdIn, myStdOut) = popen2.popen2(myClearCaseCommand) for myLine in mystdIn: myFilter = '[checkedout]' myLine = string.rstrip(string.lstrip(myLine)) if myLine[-len(myFilter):] == myFilter: myLine = string.rstrip(string.lstrip(myLine[:-len(myFilter)])) myPrivateFileList.append(myLine) return myPrivateFileList
def __init__(self, monitor_program_name, maxiters): import popen2 assert type(maxiters) == types.IntType assert maxiters >= 0 # TODO: when new monitor is everywhere, always pass the --maxiters flag if maxiters > 0: cmdline = '%s --maxiters=%d' % (monitor_program_name, maxiters) else: cmdline = monitor_program_name # end if if not print_only(): (self.monitor_out, self.monitor_in) = popen2.popen2(cmdline) else: (self.monitor_out, self.monitor_in) = (None, None) self.restartfns = {} # hash from host:port to restart cmd self.maxiters = maxiters self.originaldata = {} # original host/port self.restarts = {} # from (host, port) to # of restarts