2 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
3 # Copyright (C) 2015 INRIA
11 from pprint import PrettyPrinter
15 def init_options(options_arg):
19 # how could this accept a list again ?
21 now = time.strftime("%H:%M:%S", time.localtime())
22 print("*", now, '--', message)
24 def pprint(message, spec, depth=2):
25 now = time.strftime("%H:%M:%S", time.localtime())
26 print(">", now, "--", message)
27 PrettyPrinter(indent=8, depth=depth).pprint(spec)
31 def system(command, background=False, silent=False, dry_run=None):
32 dry_run = dry_run if dry_run is not None else getattr(options, 'dry_run', False)
34 print('dry_run:', command)
38 if command.find(';') >= 0:
39 command = "({}) 2> /dev/null".format(command)
40 else: command += " 2> /dev/null"
47 now = time.strftime("%H:%M:%S", time.localtime())
48 # don't show in summary
49 print("->", now, '--', end=' ')
52 command = "set -x; " + command
53 return os.system(command)
55 ### WARNING : this ALWAYS does its job, even in dry_run mode
56 def output_of (command):
58 (code, string) = subprocess.getstatusoutput(command)
62 # convenience: translating shell-like pattern into regexp
63 def match (string, pattern):
64 # tmp - there's probably much simpler
65 # rewrite * into .*, ? into .
66 pattern = pattern.replace("*",".*")
67 pattern = pattern.replace("?",".")
68 return re.compile(pattern).match(string)
70 def locate_hooks_scripts (message, path, extensions):
71 print(message, 'searching', path, 'for extensions', extensions)
73 for ext in extensions:
74 # skip helper programs
75 scripts += glob.glob (path+'/[a-zA-Z]*.' + ext)
78 # quick & dirty - should probably use the parseroption object instead
79 # and move to TestMain as well
80 exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
81 def show_options (message, options):
82 now = time.strftime("%H:%M:%S", time.localtime())
83 print(">", now, "--", message)
84 for k in dir(options):
87 if k in exclude_options_keys:
89 print(" ", k, ":", getattr(options, k))