1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
9 from config import config
12 return re.sub("([\"\\\\$`])", r"\\\1", cmd)
14 def command(cmd, user = None, nostdin=""):
16 user = config.builder_user
18 nostdin = "exec < /dev/null; "
19 return "%s sudo chroot %s su - %s -c \"export LC_ALL=C; %s %s\"" \
20 % (config.sudo_chroot_wrapper, config.chroot, user, nostdin, quote(cmd))
23 return "%s sudo chroot %s /bin/sh -c \"export LC_ALL=C; exec < /dev/null; %s\"" \
24 % (config.sudo_chroot_wrapper, config.chroot, quote(cmd))
26 def popen(cmd, user = "builder", mode = "r"):
28 p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True)
31 p = subprocess.Popen(command(cmd, user), shell=True, stdin=subprocess.PIPE, close_fds=True)
35 def run(cmd, user = "builder", logfile = None, logstdout = None):
36 c = command(cmd, user, nostdin=True)
39 c = "%s 2>&1 | /usr/bin/tee -a %s" % (c, logfile)
41 c = "%s >> %s 2>&1" % (c, logfile)
52 def cp(file, outfile, user="builder", rm=False):
53 f_out = open(outfile, 'wb')
56 cmd += "; rm %s" % file
57 p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True)
59 shutil.copyfileobj(f_in, f_out)