def ParseCommandLine(self): """ Get the options from the command line and check for errors. @return tuple with parsed options and unparsed args """ # Define and get command line options. # version = '$Revision: 1.33 $' version = version.replace('$Revision: ', '') ver = version.replace(' $', '') us = '%prog --bbv_file FILE --data_dir DIR FILE --simpoint_file FILE [options]' desc = 'Runs Simpoint and then generates the region CSV file. ' \ 'Input to Simpoint can be just an BBV file or a combination of BBV/LDV files. \n\n' \ 'Required options: --bbv_file, --data_dir, --simpoint_file' util.CheckNonPrintChar(sys.argv) parser = optparse.OptionParser( usage=us, version=ver, description=desc, formatter=cmd_options.BlankLinesIndentedHelpFormatter()) cmd_options.debug(parser) cmd_options.global_file(parser) cmd_options.list(parser, '') cmd_options.bbv_file(parser, '') cmd_options.data_dir(parser) cmd_options.simpoint_file(parser) cmd_options.ldv(parser, '') cmd_options.combine(parser, '') cmd_options.cutoff(parser, '') cmd_options.focus_thread(parser, '') cmd_options.maxk(parser, '') cmd_options.num_cores(parser, '') cmd_options.simpoint_options(parser, '') (options, args) = parser.parse_args() # Added method cbsp() to 'options' to check if running CBSP. # util.AddMethodcbsp(options) # Must have option '--ldv', even if using option '--combine', in order to # process BBV/LDV both. Let user know if '--combine' used w/o '--ldv'. # if not options.ldv and options.combine != -1.0: msg.PrintMsgPlus('WARNING: Option \'--combine\' detected without \'--ldv\'. Only using BBV for ' \ 'Simpoint. \n Must explicitly specify \'--ldv\' in order to use both BBV/LDV.\n') if options.ldv: msg.PrintMsgPlus( 'Using both BBV/LDV files when running Simpoint\n') # If option combine is not set, then set it to the default value. # Check to make sure combine an acceptable value. # util.SetCombineDefault(options) util.CheckCombine(options) # Read in an optional configuration files and set global variables. # config_obj = config.ConfigClass() config_obj.GetCfgGlobals(options, False) # Don't need to require 4 variables # Error check input to make sure all required options are on the command line. # if options.bbv_file == '': msg.PrintAndExit( 'Basic block vector file must be defined with option: --bbv_file FILE' ) if options.data_dir == '': msg.PrintAndExit( 'Simpoint data directory must be defined with option: --data_dir DIR' ) if options.simpoint_file == '': msg.PrintAndExit( 'Simpoint output must be defined with option: --simpoint_file FILE' ) # The data_dir should exist and contain the BBV file. # if not os.path.isdir(options.data_dir): msg.PrintAndExit('Data directory does not exist: ' + options.data_dir) if not os.path.isfile(os.path.join(options.data_dir, options.bbv_file)): msg.PrintAndExit('Basic block vector file does not exist: ' + options.bbv_file) # Do some 'special' things on native Windows. # util.WindowsNativeCheck(options) return (options, args)
def GetOptions(): """ Get users command line options/args and check to make sure they are correct. @return List of options and 3 file pointers for bbv, simpoint and weights files """ version = '$Revision: 1.1 $'; version = version.replace('$Revision: ', '') ver = version.replace(' $', '') us = '%prog [options] action file_name [file_name]' desc = 'Implements several different actions to process FV (Frequency Vector) files. ' \ 'An action must be defined in order for the script to run. '\ 'All actions require at least one file name be given using an option. '\ ' '\ '--------------------------------------------'\ ' '\ 'There are two types of frequency vector files: '\ ' '\ 'BBV = Basic Block Vector, '\ 'LDV = LRU stack Distance Vector' parser = optparse.OptionParser(usage=us, version=ver, description=desc) cmd_options.focus_thread(parser, '') # Options which define the actions the script to execute # action_group = cmd_options.ActionGroup(parser) cmd_options.combine(parser, action_group) cmd_options.csv_region(parser, action_group) cmd_options.project_bbv(parser, action_group) cmd_options.weight_ldv(parser, action_group) parser.add_option_group(action_group ) # Options which list the files the script can process # # import pdb; pdb.set_trace() file_group = cmd_options.FileGroup(parser) cmd_options.bbv_file(parser, file_group) cmd_options.ldv_file(parser, file_group) cmd_options.normal_bbv(parser, file_group) cmd_options.normal_ldv(parser, file_group) cmd_options.region_file(parser, file_group) # cmd_options.vector_file(parser, file_group) cmd_options.weight_file(parser, file_group) parser.add_option_group(file_group) # Parse command line options and get any arguments. # (options, args) = parser.parse_args() matrix = ReadVectorFile(args[0]) PrintVectorFile(matrix) sys.exit(0) def TrueXor(*args): """Return xor of some booleans.""" return sum(args) == 1 # Must have one, and only one, action on command line. # # import pdb; pdb.set_trace() if not TrueXor(options.csv_region, options.project_bbv, options.weight_ldv, \ options.combine != None): msg.PrintAndExit('Must give one, and only one, action for script to execute.\n' 'Use -h to get help.') # Check to see if options required for the various actions are given. # file_error = lambda file, action: msg.PrintAndExit("Must use option '" + file + \ "' to define the file to use with '" + action + "'. \nUse -h for help.") # import pdb; pdb.set_trace() fp_bbv = fp_ldv = fp_simp = fp_weight = None if options.combine: # First check to make sure the scaling factor is a valid FP number between 0.0 and 1.0 # if not util.IsFloat(options.combine): msg.PrintAndExit('Illegal value for scaling factor: ' + str(options.combine) + \ '\nScaling factor must be a float between 0.0 and 1.0.') else: value = float(options.combine) if value < 0.0 or value > 1.0: msg.PrintAndExit('Scaling factor given (%f) must be between 0.0 and 1.0' % value) options.combine = value # Then check to make sure required files are given. # if not options.normal_bbv: file_error('--normal_bbv', '--combine') if not options.normal_ldv: file_error('--normal_ldv', '--combine') fp_bbv = OpenNormalFVFile(options.normal_bbv, 'projected, normalized BBV file: ') fp_ldv = OpenNormalFVFile(options.normal_ldv, 'projected, normalized BBV file: ') if options.csv_region: if not options.bbv_file: file_error('--bbv_file', '--csv_region') if not options.region_file: file_error('--region_file', '--csv_region') if not options.weight_file: file_error('--weight_file', '--csv_region') fp_bbv = OpenFVFile(options.bbv_file, 'Basic Block Vector (bbv) file: ') fp_simp = OpenSimpointFile(options.region_file, 'simpoints file: ') fp_weight = OpenWeightsFile(options.weight_file, 'weights file: ') if options.project_bbv: if not options.bbv_file: file_error('--bbv_file', '--project_bbv') fp_bbv = OpenFVFile(options.bbv_file, 'Basic Block Vector (bbv) file: ') if options.weight_ldv: if not options.ldv_file: file_error('--ldv_file', '--weight_ldv') fp_ldv = util.OpenCompressFile(options.ldv_file) return (options, fp_bbv, fp_ldv, fp_simp, fp_weight)
def GetOptions(): """ Get users command line options/args and check to make sure they are correct. @return List of options and 3 file pointers for bbv, simpoint and weights files """ version = '$Revision: 1.30 $' version = version.replace(' ', '') ver = version.replace(' $', '') us = '%prog [options] action file_name [file_name]' desc = 'Implements several actions used to process FV (Frequency Vector) files. ' \ 'One action, and only one, must be defined in order for the script to run. '\ 'All actions require at least one file name be given using an option. \n\n'\ '' \ 'There are two types of frequency vector files: '\ ' '\ 'BBV = Basic Block Vector, '\ ' '\ 'LDV = LRU stack Distance Vector' def combine(parser, group): """ IMPORTANT NOTE: This is a local definition for the option which has more help information than the default defined in cmd_options.py. This info is specific to this script and is not applicable to the other locations where the option is used. Default value for combine to 'none' instead of setting it to a value (as it is in cmd_options.py). This allows the option to be used to determine what to do. @return No return value """ method = cmd_options.GetMethod(parser, group) method( "--combine", dest="combine", default=None, help= "Combine the vectors for BBV and LDV files into a single FV file, use scaling " "factor COMBINE (0.0 >= COMBINE <= 1.0). The BB vectors " "are scaled by COMBINE, while the LD vectors are scaled by 1-COMBINE. Default: 0.5 " "Assumes both files have already been transformed by the appropriate process " "(project/normal for BBV, weight/normal for LDV). " "Must use --normal_bbv and --normal_ldv to define files to process." ) util.CheckNonPrintChar(sys.argv) parser = optparse.OptionParser( usage=us, version=ver, description=desc, formatter=cmd_options.BlankLinesIndentedHelpFormatter()) cmd_options.dimensions(parser, '') cmd_options.focus_thread(parser, '') # Options which define the actions the script to execute # action_group = cmd_options.ActionGroup(parser) combine(parser, action_group) cmd_options.csv_region(parser, action_group) cmd_options.project_bbv(parser, action_group) cmd_options.weight_ldv(parser, action_group) parser.add_option_group(action_group) # Options which list the files the script can process # # import pdb; pdb.set_trace() file_group = cmd_options.FileGroup(parser) cmd_options.bbv_file(parser, file_group) cmd_options.ldv_file(parser, file_group) cmd_options.normal_bbv(parser, file_group) cmd_options.normal_ldv(parser, file_group) cmd_options.region_file(parser, file_group) cmd_options.vector_file(parser, file_group) cmd_options.weight_file(parser, file_group) parser.add_option_group(file_group) # Parse command line options and get any arguments. # (options, args) = parser.parse_args() # Added method cbsp() to 'options' to check if running CBSP. # util.AddMethodcbsp(options) def TrueXor(*args): """Return xor of some booleans.""" return sum(args) == 1 # Must have one, and only one, action on command line. # # import pdb; pdb.set_trace() if not TrueXor(options.csv_region, options.project_bbv, options.weight_ldv, \ options.combine != None, options.vector_file != None): msg.PrintAndExit( 'Must give one, and only one, action for script to execute.\n' 'Use -h to get help.') # Check to see if options required for the various actions are given. # file_error = lambda file, action: msg.PrintAndExit("Must use option '" + file + \ "' to define the file to use with '" + action + "'. \nUse -h for help.") # import pdb; pdb.set_trace() fp_bbv = fp_ldv = fp_simp = fp_weight = None if options.combine: # Check to make sure the option 'combine' is an acceptable value. If so, then turn it into a float. # util.CheckCombine(options) options.combine = float(options.combine) # Then check to make sure required files are given. # if not options.normal_bbv: file_error('--normal_bbv', '--combine') if not options.normal_ldv: file_error('--normal_ldv', '--combine') fp_bbv = OpenNormalFVFile(options.normal_bbv, 'projected, normalized BBV file: ') fp_ldv = OpenNormalFVFile(options.normal_ldv, 'projected, normalized BBV file: ') if options.csv_region: if not options.bbv_file: file_error('--bbv_file', '--csv_region') if not options.region_file: file_error('--region_file', '--csv_region') if not options.weight_file: file_error('--weight_file', '--csv_region') fp_bbv = OpenFVFile(options.bbv_file, 'Basic Block Vector (bbv) file: ') fp_simp = OpenSimpointFile(options.region_file, 'simpoints file: ') fp_weight = OpenWeightsFile(options.weight_file, 'weights file: ') if options.project_bbv: if not options.bbv_file: file_error('--bbv_file', '--project_bbv') fp_bbv = OpenFVFile(options.bbv_file, 'Basic Block Vector (bbv) file: ') if options.weight_ldv: if not options.ldv_file: file_error('--ldv_file', '--weight_ldv') fp_ldv = util.OpenCompressFile(options.ldv_file) return (options, fp_bbv, fp_ldv, fp_simp, fp_weight)