import os, sys, subprocess, time password = 'mypw'
h = '-h localhost' pw = '-p ' + password s = '/usr/bin/cal' # parse the dicts from submit, attributes def parse(s,n=1): L = s.strip().split('\n')[n:-n] D = dict() for line in L: k,v = line.strip().split(' = ') D[k] = v.split(';')[0] return D
def launch(cmd): p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) r,e = p.communicate() return r,e
# build the command we'll use def build(kind,arg=None): rL = ['xgrid',h,pw,'-job',kind] if kind in ['run','submit']: bin = arg if bin: rL.append(bin) if kind in ['results','attributes']: jid = arg if jid: rL.append('-id ' + jid) return ' '.join(rL)
def run(bin): cmd = build('run',bin) r,e = launch(cmd) print r.strip() + '\n'
run(s) |