def main(argv=sys.argv): unix_success = 0 unix_error = 1 ################ get user parameters if len(argv) < 2 : # print selfdoc and exit if no parameters rsfprog.selfdoc() return unix_error par = rsf.Par(argv) # get parameters levels = par.int('levels',3) # directory search depth list = par.string('list') # how much to list [all,filter,none], default = all timer = par.string('timer') # output execution time [log,file,none], default = none rsfproj = par.string('rsfproj') # rsfproj filter [yes,no,both], default = yes size = par.int('size',1024**2) # max data size filter (MB) size = size*1024**2 uses = par.string('uses') # uses filter, default = any fetch_none = par.bool('nofetch',True) # fetch-no-data filter fetch_public = par.bool('public',False) # fetch-public-data filter fetch_private = par.bool('private',False) # fetch-private-data filter fetch_local = par.bool('local',False) # fetch-local-data filter command = par.string('command') # command to execute in each directory, default = none skipfile = par.string('skipfile') # file with list of directories to skip if list is None: list='all' if list not in ['all','filter','none']: sys.stderr.write('Unknown list option: %s\n' % list) return unix_error if timer is None: timer='none' if timer not in ['log','file','none']: sys.stderr.write('Unknown timer option: %s\n' % timer) return unix_error if rsfproj is None: rsfproj='yes' if rsfproj not in ['yes','no','both']: sys.stderr.write('Unknown rsfproj option: %s\n' % rsfproj) return unix_error if uses is None: uses='any' if fetch_none is None: fetch_none = True if fetch_public is None: fetch_public = False if fetch_private is None: fetch_private = False if fetch_local is None: fetch_local = False ################ build list of search directories books = [] for item in argv[1:]: if '=' in item: continue # skip parameter items if not os.path.exists(item): # does item exist? sys.stderr.write("Directory '%s' does not exist.\n" % item) continue if not os.path.isdir(item): # is item a directory? sys.stderr.write("File '%s' is not a directory.\n" % item) continue books.append(os.path.normpath(item)) if len(books) == 0: # nothing to search sys.stderr.write("No directories to search.\n") return unix_error sys.stdout.write("Searching in: %s\n\n" % books) sys.stdout.flush() ################ read skipfile g = {} l = {} if skipfile is not None: execfile(skipfile,g,l) if 'skiplist' in l: skiplist = l['skiplist'] else: skiplist = [] ################ get list of tools installed in $RSFROOT tool_list = os.listdir(os.path.join(RSFROOT,"bin")) ################ search directory tree if (list == 'all') or (list == 'filter'): sys.stdout.write('command rsfproj data size directory\n') sys.stdout.flush() total_list = 0 total_size = 0 pass_list = 0 pass_size = 0 rsfproj_yes = 0 rsfproj_no = 0 rsfproj_error = 0 command_error = 0 data_unknown = 0 data_none = 0 data_public = 0 data_private = 0 data_local = 0 for bookdir in books: for root,dirs,files in os.walk(bookdir): if '.svn' in dirs: dirs.remove('.svn') # don't visit .svn dirs reldir = root.replace(bookdir,"dummy",1) # get relative dir name level = len(reldir.split(os.sep))-1 # get dir level if level < levels: continue # scan to depth 'levels' ... if level == levels: del dirs[:] # ... but not beyond 'levels' # skip dirs without SConstruct if 'SConstruct' not in files: continue # read rsfproj file tuple = read_rsfproj(root,files) (error,rsfproj_exist,uses_list,data_type,data_size) = tuple if error==1: rsfproj_error = rsfproj_error+1 string = " ********* .rsfproj error ********* %s\n" sys.stdout.write(string % root) sys.stdout.flush() tools = 'yes' for item in uses_list: if (item not in tool_list): tools = 'no ' # calculate directory filter options = (skiplist,rsfproj,uses,size,fetch_none,fetch_public,fetch_private,fetch_local) props = (root,rsfproj_exist,uses_list,data_type,data_size) filter = calc_filter(options,props) if filter==True: pass_list = pass_list+1 pass_size = pass_size+data_size # print data for each directory if (list == 'all') or ((list == 'filter') and (filter == True)): total_list = total_list+1 total_size = total_size+data_size if filter: filter_command = 'yes' else: filter_command = 'no ' if rsfproj_exist == 'yes' : rsfproj_yes = rsfproj_yes+1 if rsfproj_exist == 'no' : rsfproj_no = rsfproj_no+1 if data_type == 'unknown' : data_unknown = data_unknown+1 if data_type == 'none' : data_none = data_none+1 if data_type == 'public' : data_public = data_public+1 if data_type == 'private' : data_private = data_private+1 if data_type == 'local' : data_local = data_local+1 tuple = (filter_command,rsfproj_exist, data_type,size_string(data_size),root) sys.stdout.write('%s %-3s %10s %-7s %s\n' % tuple) sys.stdout.flush() # execute command in directory if (filter is True) and (command is not None): string = " +++++++++ running command +++++++++ %s\n" sys.stdout.write(string % root) sys.stdout.flush() tuple = command_wait(' '.join(['cd',root,';',command])) (exit,dt_user,dt_sys,dt_real) = tuple if (timer == 'log'): string = " user %6.2f sys %6.2f real %6.2f %s\n" sys.stdout.write(string % (dt_user,dt_sys,dt_real,root)) if (timer == 'file'): rsftimer_write(root,exit,dt_user,dt_sys,dt_real) if (exit==0): string = " --------- command success --------- %s\n" else: string = " ********* command error ********* %s\n" command_error = command_error+1 sys.stdout.write(string % root) sys.stdout.write("\n") sys.stdout.flush() sys.stdout.write("\n") sys.stdout.write("Directories listed : %3d\n" % total_list) sys.stdout.write("Total data size : %s\n" % size_string(total_size)) sys.stdout.write("\n") sys.stdout.write("Directories with .rsfproj : %3d\n" % rsfproj_yes) sys.stdout.write("Directories without .rsfproj : %3d\n" % rsfproj_no) sys.stdout.write(".rsfproj errors : %3d\n" % rsfproj_error) sys.stdout.write("\n") sys.stdout.write("Directories for command : %3d\n" % pass_list) sys.stdout.write("Total data size for command : %s\n" % size_string(pass_size)) sys.stdout.write("Command errors : %3d\n" % command_error) sys.stdout.write("\n") sys.stdout.write("Directories using unknown external data : %3d\n" % data_unknown) sys.stdout.write("Directories using no external data : %3d\n" % data_none) sys.stdout.write("Directories using public external data : %3d\n" % data_public) sys.stdout.write("Directories using private external data : %3d\n" % data_private) sys.stdout.write("Directories using local data : %3d\n" % data_local) sys.stdout.write("\n") return unix_success
def show_man_and_out(condition): 'Display self-doc (man page) and exit' if condition: rsfprog.selfdoc() # show the man page sys.exit(unix_error)
def main(argv=sys.argv): unix_success = 0 unix_error = 1 ################ get user parameters if len(argv) < 2: # print selfdoc and exit if no parameters rsfprog.selfdoc() return unix_error par = rsf.Par(argv) # get parameters levels = par.int('levels', 3) # directory search depth outfile_name = par.string('outfile') # file name for detailed inventory table, default none untested = par.bool('untested', False) # list untested examples? ################ build list of search directories books = [] for item in argv[1:]: if '=' in item: continue # skip parameter items if not os.path.exists(item): # does item exist? sys.stderr.write("Directory '%s' does not exist.\n" % item) continue if not os.path.isdir(item): # is item a directory? sys.stderr.write("File '%s' is not a directory.\n" % item) continue books.append(os.path.normpath(item)) if len(books) == 0: # nothing to search sys.stderr.write("No directories to search.\n") return unix_error sys.stdout.write("Searching in: %s\n\n" % books) ################ open outut file if outfile_name == None: outfile = None else: outfile = open(outfile_name, 'w') outfile.write('proj error ') outfile.write('test error time ') outfile.write('size type fig lock miss ext diff same dir\n') ################ search directory tree sbool = {True: 'yes', False: 'no ', None: '- '} serror = {0: 'ok ', 1: 'error'} rsftest_errors = 0 rsftest_no = 0 figdir_no = 0 lockdir_no = 0 figs_missing = 0 figs_extra = 0 figs_diff = 0 rsftest_error_list = [] rsftest_no_list = [] figdir_no_list = [] lockdir_no_list = [] figs_missing_list = [] figs_extra_list = [] figs_diff_list = [] for bookdir in books: for root, dirs, files in os.walk(bookdir): if '.svn' in dirs: dirs.remove('.svn') # don't visit .svn dirs reldir = root.replace(bookdir, "dummy", 1) # get relative dir name level = len(reldir.split(os.sep)) - 1 # get dir level if level < levels: continue # scan to depth 'levels' ... if level == levels: del dirs[:] # ... but not beyond 'levels' # skip dirs without SConstruct if 'SConstruct' not in files: continue rsfproj_vals = read_rsfproj(root, files) # read rsfproj file rsftest_vals = read_rsftest(root, files) # read rsftest file # count errors if rsftest_vals['error'] == 1: rsftest_errors = rsftest_errors + 1 rsftest_error_list.append(root) if not rsftest_vals['exist']: rsftest_no = rsftest_no + 1 rsftest_no_list.append(root) if rsftest_vals['exist_fig'] == False: figdir_no = figdir_no + 1 figdir_no_list.append(root) if rsftest_vals['exist_lock'] == False: lockdir_no = lockdir_no + 1 lockdir_no_list.append(root) if rsftest_vals['miss'] > 0: figs_missing = figs_missing + 1 figs_missing_list.append(root) if rsftest_vals['extra'] > 0: figs_extra = figs_extra + 1 figs_extra_list.append(root) if rsftest_vals['diff'] > 0: figs_diff = figs_diff + 1 figs_diff_list.append(root) # write summary table if outfile != None: outfile.write('%s ' % sbool[rsfproj_vals['exist']]) outfile.write('%s ' % serror[rsfproj_vals['error']]) outfile.write('%s ' % sbool[rsftest_vals['exist']]) outfile.write('%s ' % serror[rsftest_vals['error']]) outfile.write('"%-24s" ' % rsftest_vals['time']) outfile.write('%12s ' % int_string(rsfproj_vals['size'])) outfile.write('%s ' % rsfproj_vals['data']) outfile.write('%s ' % sbool[rsftest_vals['exist_fig']]) outfile.write('%s ' % sbool[rsftest_vals['exist_lock']]) outfile.write('%3s ' % int_string(rsftest_vals['miss'])) outfile.write('%3s ' % int_string(rsftest_vals['extra'])) outfile.write('%3s ' % int_string(rsftest_vals['diff'])) outfile.write('%3s ' % int_string(rsftest_vals['same'])) outfile.write('%s\n' % root) ################ write summary sys.stdout.write("Examples without an .rsftest file (%d):\n" % rsftest_no) if untested: rsftest_no_list.sort() for item in rsftest_no_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Examples with .rsftest file errors (%d):\n" % rsftest_errors) rsftest_error_list.sort() for item in rsftest_error_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples without a fig directory (%d):\n" % figdir_no) figdir_no_list.sort() for item in figdir_no_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples without a lock directory (%d):\n" % lockdir_no) lockdir_no_list.sort() for item in lockdir_no_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples with missing figs (%d):\n" % figs_missing) figs_missing_list.sort() for item in figs_missing_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples with extra figs (%d):\n" % figs_extra) figs_extra_list.sort() for item in figs_extra_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples with non-matching figs (%d):\n" % figs_diff) figs_diff_list.sort() for item in figs_diff_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") return unix_success
def main(argv=sys.argv): unix_success = 0 unix_error = 1 ################ get user parameters if len(argv) < 2: # print selfdoc and exit if no parameters rsfprog.selfdoc() return unix_error par = rsf.Par(argv) # get parameters figdir = par.string('figdir') # fig directory, default = ./Fig lockdir = par.string( 'lockdir') # lock directory, default = lock counterpart of figdir list = par.string( 'list') # how much to list [none,diff,miss,all], default = all show = par.string( 'show') # how much to show [none,diff,miss,all], default = none rsftest = par.bool('rsftest', False) # write .rsftest file? copy = par.bool('copy', False) # copy different figs from figdir to lockdir? # check list and show parameters options = ['none', 'diff', 'miss', 'all'] if list is None: list = 'all' if options.count(list) == 0: print "Unknown list option: %s" % list return unix_error if show is None: show = 'none' if options.count(show) == 0: print "Unknown show option: %s" % show return unix_error ################ get environment variables # get $RSFFIGS variable rsffigs = os.environ.get('RSFFIGS') # use $RSFROOT/figs if $RSFFIGS not defined if rsffigs == None: rsffigs = os.path.join(RSFROOT, 'share', 'madagascar', 'figs') # get $RSFALTFIGS variable rsfaltfigs = os.environ.get('RSFALTFIGS') # use rsffigs if $RSFALTFIGS not defined if rsfaltfigs == None: rsfaltfigs = rsffigs ################ get directory paths # get fig directory path if figdir is None: figpath = os.path.abspath(os.path.join('.', 'Fig')) else: figpath = os.path.abspath(figdir) # get lock directory path if lockdir is None: # default to $RSFFIGS/book_tree book_paths = book_path_split(figpath) lockpath = os.path.expandvars(os.path.join(rsffigs, book_paths[1])) # if $RSFSRC is defined and we are not in # $RSFSRC/book/book_tree then # default to $RSFALTFIGS/book_tree if os.environ.get('RSFSRC') != None: if book_paths[0] != os.path.expandvars( os.path.join('$RSFSRC', 'book')): lockpath = os.path.expandvars( os.path.join(rsfaltfigs, book_paths[1])) # use user-supplied lockdir else: lockpath = os.path.abspath(lockdir) # check if fig & lock directories exist exist_fig = os.path.exists(figpath) exist_lock = os.path.exists(lockpath) # print fig directory path print "" if exist_fig: print "Fig directory:" print figpath else: print "Fig directory does not exist:" print figpath # print lock directory path print "" if exist_lock: print "Lock directory:" print lockpath else: print "Lock directory does not exist:" print lockpath if (not exist_fig) or (not exist_lock): if rsftest: rsftest_write(exist_fig, exist_lock, None, None, None, None, None) return unix_error ################ initialize variables miss = 0 extra = 0 diff = 0 same = 0 files = {} ################ get file lists # get lists of vpl files figlist = vpl_list(os.listdir(figpath)) locklist = vpl_list(os.listdir(lockpath)) figlist.sort() locklist.sort() # merge vpl lists for item in figlist: files[item] = ' ' for item in locklist: files[item] = ' ' filelist = files.keys() filelist.sort() ################ find missing and different files # find missing files for item in filelist: if figlist.count(item) == 0: files[item] = ' -' miss = miss + 1 for item in filelist: if locklist.count(item) == 0: files[item] = ' +' extra = extra + 1 # find different files print "" binpath = os.path.join(RSFROOT, 'bin') command = os.path.join(binpath, sfprefix + 'vplotdiff') for item in filelist: if files[item] == ' ': figfile = os.path.join(figpath, item) lockfile = os.path.join(lockpath, item) check = os.system(' '.join( [command, figfile, lockfile, '2>/dev/null'])) if check != 0: if copy: print "Copying %s from fig directory to lock directory." % item shutil.copy(figfile, lockfile) else: files[item] = '%2d' % (check // 256) diff = diff + 1 ################ print file list and show selected figs command = os.path.join(binpath, 'sfpen') for item in filelist: miss_check = (files[item] != ' ') diff_check = ((files[item] != ' ') and (files[item] != ' -') and (files[item] != ' +')) list_check = (((list == 'all')) or ((list == 'miss') and miss_check) or ((list == 'diff') and diff_check)) show_check = (((show == 'all')) or ((show == 'miss') and miss_check) or ((show == 'diff') and diff_check)) if files[item] == ' -': figfile = '' else: figfile = os.path.join(figpath, item) if files[item] == ' +': lockfile = '' else: lockfile = os.path.join(lockpath, item) if list_check: print " %s %s" % (files[item], item) if show_check: syswait(' '.join([command, figfile, lockfile])) if files[item] == ' ': same = same + 1 print "" print "Identical files: %3d" % same print "Different files: %3d" % diff print "Files missing from Fig: %3d" % miss print "Extra files in Fig: %3d" % extra print "Total vplot files: %3d" % len(filelist) print "" # write .rsftest file if rsftest: rsftest_write(exist_fig, exist_lock, miss, extra, diff, same, files) return unix_success
def main(argv=sys.argv): unix_success = 0 unix_error = 1 ################ get user parameters if len(argv) < 2: # print selfdoc and exit if no parameters rsfprog.selfdoc() return unix_error par = rsf.Par(argv) # get parameters levels = par.int('levels', 3) # directory search depth list = par.string('list') # how much to list [all,filter,none], default = all timer = par.string('timer') # output execution time [log,file,none], default = none rsfproj = par.string('rsfproj') # rsfproj filter [yes,no,both], default = yes size = par.int('size', 1024**2) # max data size filter (MB) size = size * 1024**2 uses = par.string('uses') # uses filter, default = any fetch_none = par.bool('nofetch', True) # fetch-no-data filter fetch_public = par.bool('public', False) # fetch-public-data filter fetch_private = par.bool('private', False) # fetch-private-data filter fetch_local = par.bool('local', False) # fetch-local-data filter command = par.string('command') # command to execute in each directory, default = none skipfile = par.string('skipfile') # file with list of directories to skip if list is None: list = 'all' if list not in ['all', 'filter', 'none']: sys.stderr.write('Unknown list option: %s\n' % list) return unix_error if timer is None: timer = 'none' if timer not in ['log', 'file', 'none']: sys.stderr.write('Unknown timer option: %s\n' % timer) return unix_error if rsfproj is None: rsfproj = 'yes' if rsfproj not in ['yes', 'no', 'both']: sys.stderr.write('Unknown rsfproj option: %s\n' % rsfproj) return unix_error if uses is None: uses = 'any' if fetch_none is None: fetch_none = True if fetch_public is None: fetch_public = False if fetch_private is None: fetch_private = False if fetch_local is None: fetch_local = False ################ build list of search directories books = [] for item in argv[1:]: if '=' in item: continue # skip parameter items if not os.path.exists(item): # does item exist? sys.stderr.write("Directory '%s' does not exist.\n" % item) continue if not os.path.isdir(item): # is item a directory? sys.stderr.write("File '%s' is not a directory.\n" % item) continue books.append(os.path.normpath(item)) if len(books) == 0: # nothing to search sys.stderr.write("No directories to search.\n") return unix_error sys.stdout.write("Searching in: %s\n\n" % books) sys.stdout.flush() ################ read skipfile g = {} l = {} if skipfile is not None: execfile(skipfile, g, l) if 'skiplist' in l: skiplist = l['skiplist'] else: skiplist = [] ################ get list of tools installed in $RSFROOT tool_list = os.listdir(os.path.join(RSFROOT, "bin")) ################ search directory tree if (list == 'all') or (list == 'filter'): sys.stdout.write( 'command rsfproj data size directory\n') sys.stdout.flush() total_list = 0 total_size = 0 pass_list = 0 pass_size = 0 rsfproj_yes = 0 rsfproj_no = 0 rsfproj_error = 0 command_error = 0 data_unknown = 0 data_none = 0 data_public = 0 data_private = 0 data_local = 0 for bookdir in books: for root, dirs, files in os.walk(bookdir): if '.svn' in dirs: dirs.remove('.svn') # don't visit .svn dirs reldir = root.replace(bookdir, "dummy", 1) # get relative dir name level = len(reldir.split(os.sep)) - 1 # get dir level if level < levels: continue # scan to depth 'levels' ... if level == levels: del dirs[:] # ... but not beyond 'levels' # skip dirs without SConstruct if 'SConstruct' not in files: continue # read rsfproj file tuple = read_rsfproj(root, files) (error, rsfproj_exist, uses_list, data_type, data_size) = tuple if error == 1: rsfproj_error = rsfproj_error + 1 string = " ********* .rsfproj error ********* %s\n" sys.stdout.write(string % root) sys.stdout.flush() tools = 'yes' for item in uses_list: if (item not in tool_list): tools = 'no ' # calculate directory filter options = (skiplist, rsfproj, uses, size, fetch_none, fetch_public, fetch_private, fetch_local) props = (root, rsfproj_exist, uses_list, data_type, data_size) filter = calc_filter(options, props) if filter == True: pass_list = pass_list + 1 pass_size = pass_size + data_size # print data for each directory if (list == 'all') or ((list == 'filter') and (filter == True)): total_list = total_list + 1 total_size = total_size + data_size if filter: filter_command = 'yes' else: filter_command = 'no ' if rsfproj_exist == 'yes': rsfproj_yes = rsfproj_yes + 1 if rsfproj_exist == 'no': rsfproj_no = rsfproj_no + 1 if data_type == 'unknown': data_unknown = data_unknown + 1 if data_type == 'none': data_none = data_none + 1 if data_type == 'public': data_public = data_public + 1 if data_type == 'private': data_private = data_private + 1 if data_type == 'local': data_local = data_local + 1 tuple = (filter_command, rsfproj_exist, data_type, size_string(data_size), root) sys.stdout.write('%s %-3s %10s %-7s %s\n' % tuple) sys.stdout.flush() # execute command in directory if (filter is True) and (command is not None): string = " +++++++++ running command +++++++++ %s\n" sys.stdout.write(string % root) sys.stdout.flush() tuple = command_wait(' '.join(['cd', root, ';', command])) (exit, dt_user, dt_sys, dt_real) = tuple if (timer == 'log'): string = " user %6.2f sys %6.2f real %6.2f %s\n" sys.stdout.write(string % (dt_user, dt_sys, dt_real, root)) if (timer == 'file'): rsftimer_write(root, exit, dt_user, dt_sys, dt_real) if (exit == 0): string = " --------- command success --------- %s\n" else: string = " ********* command error ********* %s\n" command_error = command_error + 1 sys.stdout.write(string % root) sys.stdout.write("\n") sys.stdout.flush() sys.stdout.write("\n") sys.stdout.write("Directories listed : %3d\n" % total_list) sys.stdout.write("Total data size : %s\n" % size_string(total_size)) sys.stdout.write("\n") sys.stdout.write("Directories with .rsfproj : %3d\n" % rsfproj_yes) sys.stdout.write("Directories without .rsfproj : %3d\n" % rsfproj_no) sys.stdout.write(".rsfproj errors : %3d\n" % rsfproj_error) sys.stdout.write("\n") sys.stdout.write("Directories for command : %3d\n" % pass_list) sys.stdout.write("Total data size for command : %s\n" % size_string(pass_size)) sys.stdout.write("Command errors : %3d\n" % command_error) sys.stdout.write("\n") sys.stdout.write("Directories using unknown external data : %3d\n" % data_unknown) sys.stdout.write("Directories using no external data : %3d\n" % data_none) sys.stdout.write("Directories using public external data : %3d\n" % data_public) sys.stdout.write("Directories using private external data : %3d\n" % data_private) sys.stdout.write("Directories using local data : %3d\n" % data_local) sys.stdout.write("\n") return unix_success
def main(argv=sys.argv): unix_success = 0 unix_error = 1 ################ get user parameters if len(argv) < 2 : # print selfdoc and exit if no parameters rsfprog.selfdoc() return unix_error par = rsf.Par(argv) # get parameters figdir = par.string('figdir') # fig directory, default = ./Fig lockdir = par.string('lockdir') # lock directory, default = lock counterpart of figdir list = par.string('list') # how much to list [none,diff,miss,all], default = all show = par.string('show') # how much to show [none,diff,miss,all], default = none rsftest = par.bool('rsftest',False) # write .rsftest file? copy = par.bool('copy',False) # copy different figs from figdir to lockdir? # check list and show parameters options = ['none','diff','miss','all'] if list is None: list='all' if options.count(list) == 0: print "Unknown list option: %s" % list return unix_error if show is None: show='none' if options.count(show) == 0: print "Unknown show option: %s" % show return unix_error ################ get environment variables # get $RSFFIGS variable rsffigs = os.environ.get('RSFFIGS') # use $RSFROOT/figs if $RSFFIGS not defined if rsffigs == None: rsffigs = os.path.join(RSFROOT,'share','madagascar','figs') # get $RSFALTFIGS variable rsfaltfigs = os.environ.get('RSFALTFIGS') # use rsffigs if $RSFALTFIGS not defined if rsfaltfigs == None: rsfaltfigs = rsffigs ################ get directory paths # get fig directory path if figdir is None: figpath = os.path.abspath(os.path.join('.','Fig')) else: figpath = os.path.abspath(figdir) # get lock directory path if lockdir is None: # default to $RSFFIGS/book_tree book_paths = book_path_split(figpath) lockpath = os.path.expandvars(os.path.join(rsffigs,book_paths[1])) # if $RSFSRC is defined and we are not in # $RSFSRC/book/book_tree then # default to $RSFALTFIGS/book_tree if os.environ.get('RSFSRC') != None: if book_paths[0] != os.path.expandvars(os.path.join('$RSFSRC','book')): lockpath = os.path.expandvars(os.path.join(rsfaltfigs,book_paths[1])) # use user-supplied lockdir else: lockpath = os.path.abspath(lockdir) # check if fig & lock directories exist exist_fig = os.path.exists(figpath) exist_lock = os.path.exists(lockpath) # print fig directory path print "" if exist_fig: print "Fig directory:" print figpath else: print "Fig directory does not exist:" print figpath # print lock directory path print "" if exist_lock: print "Lock directory:" print lockpath else: print "Lock directory does not exist:" print lockpath if (not exist_fig) or (not exist_lock): if rsftest: rsftest_write(exist_fig,exist_lock,None,None,None,None,None) return unix_error ################ initialize variables miss = 0 extra = 0 diff = 0 same = 0 files = {} ################ get file lists # get lists of vpl files figlist = vpl_list(os.listdir(figpath)) locklist = vpl_list(os.listdir(lockpath)) figlist.sort() locklist.sort() # merge vpl lists for item in figlist: files[item] = ' ' for item in locklist: files[item] = ' ' filelist = files.keys() filelist.sort() ################ find missing and different files # find missing files for item in filelist: if figlist.count(item) == 0: files[item] = ' -' miss = miss+1 for item in filelist: if locklist.count(item) == 0: files[item] = ' +' extra = extra+1 # find different files print "" binpath = os.path.join(RSFROOT,'bin') command = os.path.join(binpath,sfprefix+'vplotdiff') for item in filelist: if files[item] == ' ': figfile = os.path.join(figpath,item) lockfile = os.path.join(lockpath,item) check = os.system(' '.join([command,figfile,lockfile, '2>/dev/null'])) if check != 0: if copy: print "Copying %s from fig directory to lock directory." % item shutil.copy(figfile,lockfile) else: files[item] = '%2d' % (check//256) diff = diff+1 ################ print file list and show selected figs command = os.path.join(binpath,'sfpen') for item in filelist: miss_check = (files[item] != ' ') diff_check = ( (files[item] != ' ') and (files[item] != ' -') and (files[item] != ' +')) list_check = ( ((list == 'all')) or ((list == 'miss') and miss_check) or ((list == 'diff') and diff_check)) show_check = ( ((show == 'all')) or ((show == 'miss') and miss_check) or ((show == 'diff') and diff_check)) if files[item] == ' -': figfile = '' else: figfile = os.path.join(figpath,item) if files[item] == ' +': lockfile = '' else: lockfile = os.path.join(lockpath,item) if list_check: print " %s %s" % (files[item],item) if show_check: syswait(' '.join([command,figfile,lockfile])) if files[item] == ' ': same = same+1 print "" print "Identical files: %3d" % same print "Different files: %3d" % diff print "Files missing from Fig: %3d" % miss print "Extra files in Fig: %3d" % extra print "Total vplot files: %3d" % len(filelist) print "" # write .rsftest file if rsftest: rsftest_write(exist_fig,exist_lock,miss,extra,diff,same,files) return unix_success
def main(argv=sys.argv): unix_success = 0 unix_error = 1 ################ get user parameters if len(argv) < 2 : # print selfdoc and exit if no parameters rsfprog.selfdoc() return unix_error par = rsf.Par(argv) # get parameters levels = par.int('levels',3) # directory search depth outfile_name = par.string('outfile') # file name for detailed inventory table, default none untested = par.bool('untested',False) # list untested examples? ################ build list of search directories books = [] for item in argv[1:]: if '=' in item: continue # skip parameter items if not os.path.exists(item): # does item exist? sys.stderr.write("Directory '%s' does not exist.\n" % item) continue if not os.path.isdir(item): # is item a directory? sys.stderr.write("File '%s' is not a directory.\n" % item) continue books.append(os.path.normpath(item)) if len(books) == 0: # nothing to search sys.stderr.write("No directories to search.\n") return unix_error sys.stdout.write("Searching in: %s\n\n" % books) ################ open outut file if outfile_name == None: outfile = None else: outfile = open(outfile_name,'w') outfile.write('proj error ') outfile.write('test error time ') outfile.write('size type fig lock miss ext diff same dir\n') ################ search directory tree sbool = {True:'yes', False:'no ', None:'- '} serror = {0:'ok ', 1:'error'} rsftest_errors = 0 rsftest_no = 0 figdir_no = 0 lockdir_no = 0 figs_missing = 0 figs_extra = 0 figs_diff = 0 rsftest_error_list = [] rsftest_no_list = [] figdir_no_list = [] lockdir_no_list = [] figs_missing_list = [] figs_extra_list = [] figs_diff_list = [] for bookdir in books: for root,dirs,files in os.walk(bookdir): if '.svn' in dirs: dirs.remove('.svn') # don't visit .svn dirs reldir = root.replace(bookdir,"dummy",1) # get relative dir name level = len(reldir.split(os.sep))-1 # get dir level if level < levels: continue # scan to depth 'levels' ... if level == levels: del dirs[:] # ... but not beyond 'levels' # skip dirs without SConstruct if 'SConstruct' not in files: continue rsfproj_vals = read_rsfproj(root,files) # read rsfproj file rsftest_vals = read_rsftest(root,files) # read rsftest file # count errors if rsftest_vals['error'] == 1: rsftest_errors = rsftest_errors+1 rsftest_error_list.append(root) if not rsftest_vals['exist']: rsftest_no = rsftest_no+1 rsftest_no_list.append(root) if rsftest_vals['exist_fig'] == False: figdir_no = figdir_no+1 figdir_no_list.append(root) if rsftest_vals['exist_lock'] == False: lockdir_no = lockdir_no+1 lockdir_no_list.append(root) if rsftest_vals['miss'] > 0: figs_missing = figs_missing+1 figs_missing_list.append(root) if rsftest_vals['extra'] > 0: figs_extra = figs_extra+1 figs_extra_list.append(root) if rsftest_vals['diff'] > 0: figs_diff = figs_diff+1 figs_diff_list.append(root) # write summary table if outfile != None: outfile.write('%s ' % sbool[rsfproj_vals['exist']]) outfile.write('%s ' % serror[rsfproj_vals['error']]) outfile.write('%s ' % sbool[rsftest_vals['exist']]) outfile.write('%s ' % serror[rsftest_vals['error']]) outfile.write('"%-24s" ' % rsftest_vals['time']) outfile.write('%12s ' % int_string(rsfproj_vals['size'])) outfile.write('%s ' % rsfproj_vals['data']) outfile.write('%s ' % sbool[rsftest_vals['exist_fig']]) outfile.write('%s ' % sbool[rsftest_vals['exist_lock']]) outfile.write('%3s ' % int_string(rsftest_vals['miss'])) outfile.write('%3s ' % int_string(rsftest_vals['extra'])) outfile.write('%3s ' % int_string(rsftest_vals['diff'])) outfile.write('%3s ' % int_string(rsftest_vals['same'])) outfile.write('%s\n' % root) ################ write summary sys.stdout.write("Examples without an .rsftest file (%d):\n" % rsftest_no) if untested: rsftest_no_list.sort() for item in rsftest_no_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Examples with .rsftest file errors (%d):\n" % rsftest_errors) rsftest_error_list.sort() for item in rsftest_error_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples without a fig directory (%d):\n" % figdir_no) figdir_no_list.sort() for item in figdir_no_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples without a lock directory (%d):\n" % lockdir_no) lockdir_no_list.sort() for item in lockdir_no_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples with missing figs (%d):\n" % figs_missing) figs_missing_list.sort() for item in figs_missing_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples with extra figs (%d):\n" % figs_extra) figs_extra_list.sort() for item in figs_extra_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") sys.stdout.write("Tested examples with non-matching figs (%d):\n" % figs_diff) figs_diff_list.sort() for item in figs_diff_list: sys.stdout.write("%s\n" % item) sys.stdout.write("\n") return unix_success