Parent: [11cfbe] (diff)

Child: [2d97b9] (diff)

Download this file

command.py    46 lines (37 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import shutil
import logging
import subprocess
from pylons import c
log = logging.getLogger(__name__)
class Command(object):
base=None
def __init__(self, *args):
if isinstance(self.base, basestring):
base = self.base.split()
else:
base = self.base
self.args = tuple(base) + args
def run(self, output_consumer=None):
self.sp = subprocess.Popen(
self.args, executable=self.args[0],
stdin=None, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=self.cwd())
if output_consumer is None:
self.output = self.sp.stdout.read()
else:
output_consumer(self.sp.stdout)
self.sp.wait()
def cwd(self):
try:
result = c.app.repo_dir
except:
result = os.getcwd()
log.exception("Can't set cwd to app dir, defaulting to %s",
result)
return result
def clean_dir(self):
path = self.cwd()
if os.path.exists(path):
shutil.rmtree(path)
os.makedirs(path)