X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=TLD_Builder%2Fchroot.py;h=7485e7213add7996c1d4c08f84e7ce0f216d9356;hb=bc5e1af0e1a33e54f39a5a93c8aa7aae4ef74cd8;hp=f099d018ebe5dff07ab8834f55b2d9b5e8a40e02;hpb=b999f53d4bf5d44586ecf028876e8bc20b5fd2ce;p=tld-builder.git diff --git a/TLD_Builder/chroot.py b/TLD_Builder/chroot.py index f099d01..7485e72 100644 --- a/TLD_Builder/chroot.py +++ b/TLD_Builder/chroot.py @@ -3,11 +3,9 @@ import os import re import random - -try: - from hashlib import md5 as md5 -except ImportError: - from md5 import md5 +import util +import shutil +import subprocess from config import config @@ -27,7 +25,12 @@ def command_sh(cmd): % (config.sudo_chroot_wrapper, config.chroot, quote(cmd)) def popen(cmd, user = "builder", mode = "r"): - f = os.popen(command(cmd, user), mode) + if mode == "r": + p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True) + f = p.stdout + else: + p = subprocess.Popen(command(cmd, user), shell=True, stdin=subprocess.PIPE, close_fds=True) + f = p.stdin return f def run(cmd, user = "builder", logfile = None, logstdout = None): @@ -48,36 +51,16 @@ def run(cmd, user = "builder", logfile = None, logstdout = None): return r def cp(file, outfile, user="builder", rm=False): - m = md5() - m.update(str(random.sample(xrange(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(l) - marker = False - break - if marker: - f.write(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