raise Quit(0, '')
def execute_raw(what, instr, *popenargs, **popenargsk):
+ debug(" ++ %s" % string.join(popenargs[0]))
sp = subprocess.Popen(*popenargs, **popenargsk)
if instr is None: popenargsk['stdin'] = devnull_read
(out, err) = sp.communicate(instr)
else: stdout = None
cmd = perhaps_down + cmdl + cmd_list
- debug(" + %s" % string.join(cmd))
(status, out) = execute_raw(cmdl[0], None, cmd, stdout=stdout)
if status: bomb("%s%s failed (exit status %d)" %
- ((downp and "(down) " or ""), what, status))
+ ((downp and "(down) " or ""), cmdl[0], status))
if outp and out and out[-1]=='\n': out = out[:-1]
return out
script += ( gobody +
"go()\n" )
+ debug("+P ...\n"+script)
+
scripte = urllib.quote(script)
cmdl = down + ['python','-c',
"'import urllib; s = urllib.unquote(%s); exec s'" %
def copyupdown(c, ce, up_p):
cmdnumargs(c, ce, 2)
+ wh = ce[0]
sd = c[1:]
sde = ce[1:]
if not sd[0] or not sd[1]:
- bomb("%s paths must be nonempty" % ce[0])
+ bomb("%s paths must be nonempty" % wh)
dirsp = sd[0][-1]=='/'
functions = "import errno\n"
if dirsp != (sd[1][-1]=='/'):
bomb("% paths must agree about directoryness"
- " (presence or absence of trailing /)" % ce[0])
+ " (presence or absence of trailing /)" % wh)
localfd = None
deststdout = devnull_read
srcstdin = devnull_read
preexecfns = [None, None]
if not dirsp:
- gobody = " setfd(%s,'%s',%s)\n" % (up_p, sde[0], not up_p)
+ gobody = " setfd(%s,'%s',%s)\n" % (
+ 1-up_p, sde[0], not up_p)
gobody += " os.execvp('cat', ['cat'])\n"
- if up_p: deststdout = os.open(ce[1], os.WRONLY|os.CREAT, 0666)
- else: srcstdin = os.open(ce[0], os.RDONLY)
+ if up_p: deststdout = file(sd[1], 'w')
+ else: srcstdin = file(sd[0], 'r')
localcmdl = ['cat']
else:
paxbase = 'pax -p p -x cpio'
- gobody = " dir = urllib.unquote('%s'))\n" % ce[0]
+ gobody = " dir = urllib.unquote('%s'))\n" % sde[0]
if up_p:
- try: os.mkdir(ce[1])
+ try: os.mkdir(sd[1])
except OSError, oe:
if oe.errno != errno.EEXIST: raise
else:
gobody += (" try: os.mkdir(dir)\n"
" except OSError, oe:\n"
" if oe.errno != errno.EEXIST: raise\n")
- preexecfns[not up_p] = lambda *any: os.chdir(ce[not up_p])
+ preexecfns[not up_p] = lambda *any: os.chdir(sd[not up_p])
gobody += " os.chdir(dir)\n"
gobody += " paxcmd = '%s'.split()\n" % paxbase
localcmdl = ['sh','-ec',
downcmdl = down_python_script(gobody, functions)
- if up_p: cmdls = (downcmdl, localcmdll)
- else: cmdls = (localcmdll, downcmdl)
+ if up_p: cmdls = (downcmdl, localcmdl)
+ else: cmdls = (localcmdl, downcmdl)
+
+ debug(`["cmdls", `cmdls`]`)
+ debug(`["srcstdin", `srcstdin`, "deststdout", `deststdout`, "devnull_read", devnull_read]`)
subprocs = [None,None]
+ debug(" +< %s" % string.join(cmdls[0]))
subprocs[0] = subprocess.Popen(cmdls[0], stdin=srcstdin,
stdout=subprocess.PIPE, preexec_fn=preexecfns[0])
+ debug(" +> %s" % string.join(cmdls[1]))
subprocs[1] = subprocess.Popen(cmdls[1], stdin=subprocs[0].stdout,
stdout=deststdout, preexec_fn=preexecfns[1])
- for sd in [1,0]:
- status = subprocs[sd].wait
+ for sdn in [1,0]:
+ status = subprocs[sdn].wait()
if status: bomb("%s %s failed, status %d" %
- (ce[0], ['source','destination'][sd], status))
+ (wh, ['source','destination'][sdn], status))
def cmd_copydown(c, ce): copyupdown(c, ce, False)
def cmd_copyup(c, ce): copyupdown(c, ce, True)
ce = ce.rstrip().split()
c = map(urllib.unquote, ce)
if not c: bomb('empty commands are not permitted')
+ debug('executing '+string.join(ce))
try: f = globals()['cmd_'+c[0]]
- except KeyError: bomb("unknown command `%s'" % cu[0])
- ce = map(urllib.quote, c) # sanitise the quoted args
+ except KeyError: bomb("unknown command `%s'" % ce[0])
r = f(c, ce)
if not r: r = []
r.insert(0, 'ok')