本文整理汇总了Python中subprocess.Popen.split方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.split方法的具体用法?Python Popen.split怎么用?Python Popen.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.split方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ignoring
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def test_ignoring(self):
"""
Tests for ignoring invalid files.
"""
result = Popen(['do_cleanup', '1_data/1'], stdout=PIPE, cwd=test_folder).communicate()[0]
self.assertTrue(result.split('\n')[0].startswith('Ignoring file '), 'First file should be ignored')
self.assertEquals(len(result.split('\n')), 11, 'Invalid message printed')
示例2: find_limit
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def find_limit(value,clevel):
alpha = 1-clevel
if value not in val_cache:
combine_args = ['combine',
'Example_AQGC2_workspace.root',
'-M','HybridNew',
'--freq',
'--testStat','PL',
'--rule','CLsplusb',
'--toysH','500',
'--clsAcc','0.002',
'--singlePoint','a0W=0,aCW=%e'%value]
result = Popen(combine_args,stdout=PIPE,stderr=PIPE).communicate()[0]
result = result.split('\n')[-3]
result = result.split('=')[-1]
result = result.split('+/-')
central_val = float(result[0])
error = float(result[1])
val_cache[value] = [central_val,error]
print 'limit at %e: %f +/- %e'%(value,
val_cache[value][0],
val_cache[value][1])
return val_cache[value][0] >= alpha, val_cache[value]
示例3: test_noargs
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def test_noargs(self):
"""
Tests for printing usage msg if no args are given
"""
result = Popen(['do_cleanup'], stdout=PIPE).communicate()[0]
self.assertEquals(result.split('\n')[0], 'Usage:', 'No help printed')
self.assertEquals(len(result.split('\n')), 10)
示例4: find_cal
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def find_cal(obs_id):
obs_id = obs_id.split('\n')[0]
obs_id = obs_id.strip()
cal_pref = 'HydA'
do_cal_pref = False
if do_cal_pref:
cal_output = Popen(["python", "/short/ek6/MWA_Code/MWA_extras/find_calibrator.py", "-v","--matchproject","--source="+cal_pref, str(obs_id)], stdout=PIPE).communicate()[0]
else:
cal_output = Popen(["python", "/short/ek6/MWA_Code/MWA_extras/find_calibrator.py", "-v","--matchproject", str(obs_id)], stdout=PIPE).communicate()[0]
try:
cal_id = cal_output.split()[7]
cal_name = cal_output.split()[10]
print str(obs_id)+": recommended cal is "+str(cal_id)+' = '+str(cal_name)
except:
print str(obs_id)+": cannot find suitable cal "
cal_id=None
pass;
os.chdir('/short/ek6/CALS/')
cal_num = None
return_cal = None
for cal in glob.glob('*.cal'):
cal_num = cal[0:10]
if cal_id == cal_num:
print "Found calibration file "+cal
return_cal = '/short/ek6/CALS/'+cal
if return_cal == None:
print "No calibrator file found, please generate it"
return return_cal
示例5: system_info
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def system_info():
deps = []
pdfimages = Popen(['pdfimages', '-v'], stderr=PIPE).communicate()[1]
deps.append(('pdfimages', pdfimages.split('\n')[0]))
tesseract = Popen(['tesseract', '-v'], stderr=PIPE).communicate()[1]
deps.append(('tesseract', tesseract.split('\n')[0]))
# hocr2pdf doesn't support a --version flag but prints the version to
# stderr if called without arguments
hocr2pdf = Popen(['hocr2pdf', '--help'], stdout=PIPE, stderr=PIPE)
hocr2pdf = hocr2pdf.communicate()[1]
hocr2pdf = [line for line in hocr2pdf if 'version' in line]
if hocr2pdf:
deps.append(('hocr2pdf', hocr2pdf))
gs = check_output(['gs', '--version']).split('\n')[0]
deps.append(('gs', gs))
identify = check_output(['identify', '--version']).split('\n')[0]
deps.append(('identify', identify))
convert = check_output(['convert', '--version']).split('\n')[0]
deps.append(('convert', convert))
return deps
示例6: _get_bat_status_win
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def _get_bat_status_win():
# First, lets (quickly) try to even see if this system _has_ a battery
line = Popen('wmic path win32_battery get batterystatus',
shell=True, stdout=PIPE, stderr=PIPE).stderr.readline().decode('utf8')
if "No Instance" in line:
# Nope, no battery. Bail out now.
raise BatteryException("No battery in system")
# We're pretty sure we have a battery, so get its status
try:
out = Popen('wmic path win32_battery get batterystatus',
shell=True, stdout=PIPE).stdout.read().decode('utf8').strip()
state = int(out.split('\n')[-1])
out = Popen('wmic path win32_battery get estimatedchargeremaining',
shell=True, stdout=PIPE).stdout.read().decode('utf8').strip()
charge = int(out.split('\n')[-1])
except ValueError:
# This fails if one of these two commands doesn't parse correctly into
# an int, which probably means that there is no battery to get the status
# of, so we are pobably on a desktop. Just abort.
raise BatteryException("Couldn't parse charge state")
status = powerline.discharge if state == 1 else powerline.charge
return(status, charge)
示例7: get_binetflowinfos
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def get_binetflowinfos(self):
""" Get info about binetflow files"""
if self.binetflowinfo == False and self.get_type() == 'binetflow':
# Get the time in the first line, ignoring the header
binetflow_first_flow = Popen('head -n 2 '+self.get_name()+'|tail -n 1', shell=True, stdin=PIPE, stdout=PIPE).communicate()[0]
first_flow_date = parser.parse(binetflow_first_flow.split(',')[0])
# Get the time in the last line
binetflow_last_flow = Popen('tail -n 1 '+self.get_name(), shell=True, stdin=PIPE, stdout=PIPE).communicate()[0]
last_flow_date = parser.parse(binetflow_last_flow.split(',')[0])
# Compute the difference
time_diff = last_flow_date - first_flow_date
self.set_duration(time_diff)
# Now fill the data for binetflows
self.binetflowinfo = {}
# Duration
self.binetflowinfo['Duration'] = self.get_duration()
# Amount of flows
amount_of_flows = Popen('wc -l '+self.get_name(), shell=True, stdin=PIPE, stdout=PIPE).communicate()[0].split()[0]
self.binetflowinfo['Amount of flows'] = amount_of_flows
# Always return true
return True
示例8: main
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def main(output_loc, parameters):
moneyFmt = ticker.FuncFormatter(price)
data_parameters = ['-F', '%(amount)\n', '-E', '--budget', '-p', 'this year', '-d', 'd < [this month]', '-M', 'reg'] + parameters
parameters += ['-F', '%(account)\n', '-p', 'this month', '--flat', '--no-total', '--budget', '-M', 'bal', '^exp']
output = Popen(["ledger"] + parameters, stdout=PIPE).communicate()[0]
accounts = [acct for acct in output.split('\n') if acct != ""]
data = []
labels = []
for acct in accounts:
output = Popen(["ledger"] + data_parameters + ["^" + acct], stdout=PIPE).communicate()[0]
values = []
for value in output.split('\n'):
if value == "":
continue
value = value.replace('$', '')
value = float(value.strip())
values.append(value)
data.append(values)
labels.append(acct.split(':')[-1])
fig = plt.figure()
ax = fig.add_subplot(111)
boxplot(data)
title('Boxplot of expenses by month this year')
ax.yaxis.set_major_formatter(moneyFmt)
ax.format_ydata = price
fig.autofmt_xdate()
ax.set_xticklabels(labels)
savefig(output_loc+"budgetboxplot.pdf")
示例9: system_driver
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def system_driver(self,sysname):
sysopt = self.sys_opts[sysname]
rmsd = 0.0
# This line actually runs TINKER
xyzfnm = sysname+".xyz"
if 'optimize' in sysopt and sysopt['optimize'] == True:
if self.FF.rigid_water:
#os.system("cp rigid.key %s" % os.path.splitext(xyzfnm)[0] + ".key")
o, e = Popen(["./%s" % self.optprog,xyzfnm,"1e-4"],stdout=PIPE,stderr=PIPE).communicate()
else:
o, e = Popen(["./%s" % self.optprog,xyzfnm,"1e-4"],stdout=PIPE,stderr=PIPE).communicate()
cnvgd = 0
for line in o.split('\n'):
if "Normal Termination" in line:
cnvgd = 1
if not cnvgd:
print o
print "The system %s did not converge in the geometry optimization - printout is above." % sysname
#warn_press_key("The system %s did not converge in the geometry optimization" % sysname)
o, e = Popen(["./analyze",xyzfnm+'_2',"E"],stdout=PIPE,stderr=PIPE).communicate()
if self.FF.rigid_water:
oo, ee = Popen(['./superpose', xyzfnm, xyzfnm+'_2', '1', 'y', 'u', 'n', '0'], stdout=PIPE, stderr=PIPE).communicate()
else:
oo, ee = Popen(['./superpose', xyzfnm, xyzfnm+'_2', '1', 'y', 'u', 'n', '0'], stdout=PIPE, stderr=PIPE).communicate()
for line in oo.split('\n'):
if "Root Mean Square Distance" in line:
rmsd = float(line.split()[-1])
os.system("rm %s" % xyzfnm+'_2')
else:
o, e = Popen(["./analyze",xyzfnm,"E"],stdout=PIPE,stderr=PIPE).communicate()
# Read the TINKER output.
for line in o.split('\n'):
if "Total Potential Energy" in line:
return float(line.split()[-2].replace('D','e')) * kilocalories_per_mole, rmsd * angstrom
warn_press_key("Total potential energy wasn't encountered for system %s!" % sysname)
示例10: test_rec
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def test_rec(self):
"""
Tests for recursive option handling.
"""
result = Popen(['do_cleanup', '-r', '1_data'], stdout=PIPE, cwd=test_folder).communicate()[0]
self.assertEquals(result.split('\n')[0], 'Directory 1_data contains no repozos files')
self.assertEquals(len(result.split('\n')), 12, 'Invalid message printed')
示例11: test_clean
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def test_clean(self):
"""
Tests for clean directory.
"""
result = Popen(['do_cleanup', '2_data/2'], stdout=PIPE, cwd=test_folder).communicate()[0]
self.assertEquals(result.split('\n')[0], 'Directory 2_data/2 clean', 'Clean directory reported as dirty')
self.assertEquals(len(result.split('\n')), 2, 'Invalid message printed')
示例12: test_nofiles
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def test_nofiles(self):
"""
Tests for directories with no repozos files
"""
result = Popen(['do_cleanup', '1_data'], stdout=PIPE, cwd=test_folder).communicate()[0]
self.assertEquals(result.split('\n')[0], 'Directory 1_data contains no repozos files')
self.assertEquals(len(result.split('\n')), 2, 'Invalid message printed')
示例13: test_help
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def test_help(self):
"""
Tests for printing usage msg if -h is given
"""
result = Popen(['do_cleanup', '-rh'], stdout=PIPE).communicate()[0]
self.assertEquals(result.split('\n')[0], 'Usage:', 'No help printed')
self.assertEquals(len(result.split('\n')), 10, 'Invalid message printed')
示例14: genPackageDict
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def genPackageDict(self):
self.packageDict = {}
self.totalSize = 0;
for package in self.packageList:
if package:
info = Popen(['pacman','-Si',package.split()[0]],stdout = PIPE)
sizes = Popen(['grep','Size'],stdin=info.stdout,stdout=PIPE).communicate()[0]
self.packageDict[package] = [sizes.split()[3],sizes.split()[8]]
示例15: execute_files
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import split [as 别名]
def execute_files(cl_argument=""):
from subprocess import Popen, PIPE
# 5. call python version
print "running python version: "
python_result = Popen("python tempB.py "+cl_argument, shell=True, stdout=PIPE).stdout.read()
print "running c version: "
c_result = Popen("./"+c_file+" "+cl_argument, shell=True, stdout=PIPE).stdout.read()
return python_result.split('\n'), c_result.split('\n')