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
14 def popen(command, fatal=True):
15 (stdin, stdout, stderr) = os.popen3(command)
16 output = stdout.readlines()
17 print >> logfile, "+ "+command
18 print >> logfile, "".join(output).strip()
19 # filter output generated by set x
20 remove_set_x = lambda line: not line.startswith("+")
21 errors = filter(remove_set_x, stderr.readlines())
24 raise Exception, "".join(errors)
25 return (output, errors)
28 (stdin, stdout, stderr) = os.popen3(command)
29 print >> logfile, "+ "+command
30 return (stdin, stdout, stderr)
32 def commands(command, fatal = True):
33 (status, output) = getstatusoutput(command)
34 print >> logfile, "+ "+command
35 print >> logfile, output.strip()
36 if fatal and not status == 0:
37 raise Exception, "%(command)s Failed:\n%(output)s" % locals()
38 return (status, output)