2 import time, os, re, glob, sys
3 from pprint import PrettyPrinter
7 def init_options(options_arg):
11 # how could this accept a list again ?
13 now=time.strftime("%H:%M:%S", time.localtime())
14 print "*",now,'--',message
16 def pprint(message,spec,depth=2):
17 now=time.strftime("%H:%M:%S", time.localtime())
18 print ">",now,"--",message
19 PrettyPrinter(indent=8,depth=depth).pprint(spec)
23 def system(command,background=False):
24 if background: command += " &"
26 print 'dry_run:',command
29 now=time.strftime("%H:%M:%S", time.localtime())
30 # don't show in summary
33 return os.system("set -x; " + command)
35 ### WARNING : this ALWAYS does its job, even in dry_run mode
36 def output_of (command):
39 # print 'dry_run',command
40 # return (0,'[[dry-run - fake output]]')
42 (code,string) = commands.getstatusoutput(command)
47 # convenience: translating shell-like pattern into regexp
48 def match (string, pattern):
49 # tmp - there's probably much simpler
50 # rewrite * into .*, ? into .
51 pattern=pattern.replace("*",".*")
52 pattern=pattern.replace("?",".")
53 return re.compile(pattern).match(string)
55 def locate_hooks_scripts (message,path,extensions):
56 print message,'searching',path,'for extensions',extensions
58 for ext in extensions:
59 # skip helper programs
60 scripts += glob.glob (path+'/[a-zA-Z]*.'+ext)
63 # quick & dirty - should probably use the parseroption object instead
64 # and move to TestMain as well
65 exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
66 def show_options (message,options):
67 now=time.strftime("%H:%M:%S", time.localtime())
68 print ">",now,"--",message
69 for k in dir(options):
70 if k.find("_")==0: continue
71 if k in exclude_options_keys: continue
72 print " ",k,":",getattr(options,k)