import util
import subprocess
-try:
- from hashlib import md5 as md5
-except ImportError:
- from md5 import md5
-
from config import config
def quote(cmd):
return r
def cp(file, outfile, user="builder", rm=False):
- m = md5()
- m.update(util.to_bytes(str(random.sample(range(100000), 500))))
- digest = m.hexdigest()
-
- marker_start = "--- FILE BEGIN DIGEST %s ---" % digest
- marker_end = "--- FILE END DIGEST %s ---" % digest
-
- f = open(outfile, 'wb')
- cmd = "echo \"%s\"; cat %s; echo \"%s\"" % (marker_start, file, marker_end)
+ f_out = open(outfile, 'wb')
+ cmd = "cat %s" % file
if rm:
cmd += "; rm %s" % file
- c = command(cmd, user)
- p = os.popen(c)
- # get file contents
- marker = False
- for l in p:
- if not marker and l.strip() == marker_start:
- marker = True
- continue
- me = l.find(marker_end)
- if me != -1:
- l = l[:me]
- f.write(util.to_bytes(l))
- marker = False
- break
- if marker:
- f.write(util.to_bytes(l))
- rp = p.close()
- rf = f.close()
- if rp == None:
+ p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True)
+ f_in = p.stdout
+ shutil.copyfileobj(f_in, f_out)
+ f_out.close()
+ r = f_in.close()
+ if r == None:
return 0
else:
- return rp
+ return r