]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/chroot.py
- ups. One dot instead of two. Thx wrobell
[projects/pld-builder.new.git] / PLD_Builder / chroot.py
1 import os
2 import re
3 from config import config
4
5 def quote(cmd):
6   return re.sub("([\"\\\\$`])", r"\\\1", cmd)
7   
8 def command(cmd, user = None):
9   if user == None:
10     user = config.builder_user
11   return "%s sudo chroot %s su - %s -c \"export LC_ALL=C; %s\"" \
12                 % (config.sudo_chroot_wrapper, config.chroot, user, quote(cmd))
13   
14 def command_sh(cmd):
15   return "%s sudo chroot %s /bin/sh -c \"export LC_ALL=C; %s\"" \
16         % (config.sudo_chroot_wrapper, config.chroot, quote(cmd))
17
18 def popen(cmd, user = "builder", mode = "r"):
19   f = os.popen(command(cmd, user), mode)
20   return f
21   
22 def run(cmd, user = "builder", logfile = None):
23   c = command(cmd, user)
24   if logfile != None:
25     try:
26       c = "%s >> %s 2>&1" % (c, logfile)
27     except UnicodeDecodeError:
28       c.decode('iso-8859-2')
29       c = "%s >> %s 2>&1" % (c, logfile)
30   f = os.popen(c)
31   for l in f.xreadlines():
32     pass
33   r = f.close()
34   if r == None:
35     return 0
36   else:
37     return r
This page took 0.032246 seconds and 4 git commands to generate.