1 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
2 # Copyright (C) 2010 INRIA
4 import time, os, re, glob, sys
5 from pprint import PrettyPrinter
9 def init_options(options_arg):
13 # how could this accept a list again ?
15 now=time.strftime("%H:%M:%S", time.localtime())
16 print "*",now,'--',message
18 def pprint(message,spec,depth=2):
19 now=time.strftime("%H:%M:%S", time.localtime())
20 print ">",now,"--",message
21 PrettyPrinter(indent=8,depth=depth).pprint(spec)
25 def system(command,background=False,silent=False):
26 if getattr(options,'dry_run',None):
27 print 'dry_run:',command
31 if command.find(';')>=0: command = "(%s) 2> /dev/null" % command
32 else: command += " 2> /dev/null"
33 if background: command += " &"
38 now=time.strftime("%H:%M:%S", time.localtime())
39 # don't show in summary
42 return os.system("set -x; " + command)
44 ### WARNING : this ALWAYS does its job, even in dry_run mode
45 def output_of (command):
47 (code,string) = commands.getstatusoutput(command)
51 # convenience: translating shell-like pattern into regexp
52 def match (string, pattern):
53 # tmp - there's probably much simpler
54 # rewrite * into .*, ? into .
55 pattern=pattern.replace("*",".*")
56 pattern=pattern.replace("?",".")
57 return re.compile(pattern).match(string)
59 def locate_hooks_scripts (message,path,extensions):
60 print message,'searching',path,'for extensions',extensions
62 for ext in extensions:
63 # skip helper programs
64 scripts += glob.glob (path+'/[a-zA-Z]*.'+ext)
67 # quick & dirty - should probably use the parseroption object instead
68 # and move to TestMain as well
69 exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
70 def show_options (message,options):
71 now=time.strftime("%H:%M:%S", time.localtime())
72 print ">",now,"--",message
73 for k in dir(options):
74 if k.find("_")==0: continue
75 if k in exclude_options_keys: continue
76 print " ",k,":",getattr(options,k)