4 from commands import getstatusoutput
5 from logger import logfile
8 now=time.strftime("%H:%M:%S", time.localtime())
9 output = "*"+now+'--'+message
11 print >> logfile, output
13 def popen(command, fatal=True, verbose = False):
16 (stdin, stdout, stderr) = os.popen3(command)
17 output = stdout.readlines()
18 print >> logfile, "+ "+command
19 print >> logfile, "".join(output).strip()
20 # filter output generated by set x
21 remove_set_x = lambda line: not line.startswith("+")
22 errors = filter(remove_set_x, stderr.readlines())
25 raise Exception, "".join(errors)
26 return (output, errors)
28 def popen3(command, verbose = False):
31 (stdin, stdout, stderr) = os.popen3(command)
32 print >> logfile, "+ "+command
33 return (stdin, stdout, stderr)
35 def commands(command, fatal = True, verbose = False):
38 (status, output) = getstatusoutput(command)
39 print >> logfile, "+ "+command
40 print >> logfile, output.strip()
41 if fatal and not status == 0:
42 raise Exception, "%(command)s Failed:\n%(output)s" % locals()
43 return (status, output)