another round of rework
[tests.git] / system / utils.py
index 85ad7ab..7aa670f 100644 (file)
@@ -4,6 +4,12 @@ import os
 import re
 from pprint import PrettyPrinter
 
+options={}
+
+def init_options(options_arg):
+    global options
+    options=options_arg
+
 # how could this accept a list again ?
 def header(message):
     now=time.strftime("%H:%M:%S", time.localtime())
@@ -14,6 +20,17 @@ def pprint(message,spec,depth=2):
     print ">",now,"--",message
     PrettyPrinter(indent=8,depth=depth).pprint(spec)
 
+# quick & dirty - should probably use the parseroption object instead
+# and move to TestMain as well
+exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
+def show_options (message,options):
+    now=time.strftime("%H:%M:%S", time.localtime())
+    print ">",now,"--",message
+    for k in dir(options):
+        if k.find("_")==0: continue
+        if k in exclude_options_keys: continue
+        print "    ",k,":",getattr(options,k)
+
 def show_site_spec (site):
     print '======== site',site['site_fields']['name']
     for (k,v) in site.iteritems():
@@ -94,8 +111,11 @@ def show_test_spec_pass (plc_spec,passno):
 def system(command,background=False):
     now=time.strftime("%H:%M:%S", time.localtime())
     if background: command += " &"
-    print "+",now,':',command
-    return os.system("set -x; " + command)
+    if options.dry_run:
+        print 'dry_run:',command
+        return 0
+    else:
+        return os.system("set -x; " + command)
 
 def match (string, pattern):
     # tmp - there's probably much simpler