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)
30 # set a default timeout to 15 minutes - this should be plenty even for installations
31 # call with timeout=None if the intention really is to wait until full completion
32 def system(command, background=False, silent=False, dry_run=None, timeout=15*60):
33 dry_run = dry_run if dry_run is not None else getattr(options, 'dry_run', False)
35 print('dry_run:', command)
39 if command.find(';') >= 0:
40 command = "({}) 2> /dev/null".format(command)
41 else: command += " 2> /dev/null"
48 now = time.strftime("%H:%M:%S", time.localtime())
49 # don't show in summary
50 print("->", now, '--', end=' ')
53 command = "set -x; " + command
55 return subprocess.call(command, shell=True, timeout=timeout)
56 except subprocess.TimeoutExpired as e:
57 header("TIMEOUT when running command {}- {}".format(command, e))
60 ### WARNING : this ALWAYS does its job, even in dry_run mode
61 def output_of (command):
63 (code, string) = subprocess.getstatusoutput(command)
67 # convenience: translating shell-like pattern into regexp
68 def match (string, pattern):
69 # tmp - there's probably much simpler
70 # rewrite * into .*, ? into .
71 pattern = pattern.replace("*",".*")
72 pattern = pattern.replace("?",".")
73 return re.compile(pattern).match(string)
75 def locate_hooks_scripts (message, path, extensions):
76 print(message, 'searching', path, 'for extensions', extensions)
78 for ext in extensions:
79 # skip helper programs
80 scripts += glob.glob (path+'/[a-zA-Z]*.' + ext)
83 # quick & dirty - should probably use the parseroption object instead
84 # and move to TestMain as well
85 exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
86 def show_options (message, options):
87 now = time.strftime("%H:%M:%S", time.localtime())
88 print(">", now, "--", message)
89 for k in dir(options):
92 if k in exclude_options_keys:
94 print(" ", k, ":", getattr(options, k))