workdir: create tmpfiles in the correct directory
[yap.git] / yap / util.py
blob74c7248b1213ae9055608f93fd8b224c87f29eec
1 import yap
2 import os
4 def get_output(cmd, strip=True):
5 fd = os.popen(cmd)
6 output = fd.readlines()
7 rc = fd.close()
8 if strip:
9 output = [x.strip() for x in output]
10 return output
12 def yield_output(cmd):
13 fd = os.popen(cmd)
14 for l in fd.xreadlines():
15 yield l.strip()
16 return
18 def run_command(cmd):
19 rc = os.system("%s > /dev/null 2>&1" % cmd)
20 rc >>= 8
21 return rc
23 def run_safely(cmd):
24 rc = run_command(cmd)
25 if rc:
26 raise yap.ShellError(cmd, rc)
28 def takes_options(options):
29 def decorator(func):
30 func.options = options
31 return func
32 return decorator
34 def short_help(help_msg):
35 def decorator(func):
36 func.short_help = help_msg
37 return func
38 return decorator
40 def long_help(help_msg):
41 def decorator(func):
42 func.long_help = help_msg
43 return func
44 return decorator