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)
23 # quick & dirty - should probably use the parseroption object instead
24 # and move to TestMain as well
25 exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
26 def show_options (message,options):
27 now=time.strftime("%H:%M:%S", time.localtime())
28 print ">",now,"--",message
29 for k in dir(options):
30 if k.find("_")==0: continue
31 if k in exclude_options_keys: continue
32 print " ",k,":",getattr(options,k)
34 def show_site_spec (site):
35 print '======== site',site['site_fields']['name']
36 for (k,v) in site.iteritems():
39 print '\t\t','nodes : ',
41 print node['node_fields']['hostname'],'',
47 print user['name'],'',
49 elif k == 'site_fields':
50 print '\t\tlogin_base',':',v['login_base']
51 elif k == 'address_fields':
55 PrettyPrinter(indent=8,depth=2).pprint(v)
57 def show_initscript_spec (initscript):
58 print '======== initscript',initscript['initscript_fields']['name']
60 def show_key_spec (key):
61 print '======== key',key['name']
63 def show_slice_spec (slice):
64 print '======== slice',slice['slice_fields']['name']
65 for (k,v) in slice.iteritems():
78 elif k=='slice_fields':
79 print '\t\tfields',':',
80 print 'max_nodes=',v['max_nodes'],
85 def show_test_spec (message,all_plc_specs):
86 now=time.strftime("%H:%M:%S", time.localtime())
87 print ">",now,"--",message
88 for plc_spec in all_plc_specs:
89 show_test_spec_pass (plc_spec,1)
90 show_test_spec_pass (plc_spec,2)
92 def show_test_spec_pass (plc_spec,passno):
93 for (key,val) in plc_spec.iteritems():
98 elif key=='initscripts':
99 for initscript in val:
100 show_initscript_spec (initscript)
103 show_slice_spec (slice)
108 if key not in ['sites','initscripts','slices','keys']:
109 print '\t',key,':',val
111 def system(command,background=False):
112 now=time.strftime("%H:%M:%S", time.localtime())
113 if background: command += " &"
115 print 'dry_run:',command
118 return os.system("set -x; " + command)
120 def match (string, pattern):
121 # tmp - there's probably much simpler
122 # rewrite * into .*, ? into .
123 pattern=pattern.replace("*",".*")
124 pattern=pattern.replace("?",".")
125 return re.compile(pattern).match(string)