def process_options(self): # process any optlist_ options self.valid_opts.check_special_opts(sys.argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, apply -help if len(sys.argv) <= 1 or '-help' in sys.argv: print g_help_string return 0 if '-hist' in sys.argv: print g_history return 0 if '-show_valid_opts' in sys.argv: self.valid_opts.show('', 1) return 0 if '-ver' in sys.argv: print g_version return 0 # ============================================================ # read options specified by the user self.user_opts = OL.read_options(sys.argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return 1 # error condition # ------------------------------------------------------------ # process non-chronological options, verb comes first val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val # ------------------------------------------------------------ # process options sequentially, to make them like a script for opt in uopts.olist: # main options if opt.name == '-infile': if self.a1d != None: print '** only 1 -infile option allowed' return 1 val, err = uopts.get_string_opt('', opt=opt) if val != None and err: return 1 if self.init_from_file(val): return 1 # general options elif opt.name == '-verb': val, err = uopts.get_type_opt(int, '', opt=opt) if val != None and err: return 1 else: self.verb = val continue return 0
def read_opts(self): """check for terminal arguments, then read the user options""" # ------------------------------------------------------------ # process any optlist_ options self.valid_opts.check_special_opts(sys.argv) # ------------------------------------------------------------ # check for terminal args in argv (to ignore required args) # if argv has only the program name, or user requests help, show it if len(sys.argv) <= 1 or '-help' in sys.argv: print g_help_string return 0 if '-hist' in sys.argv: print g_history return 0 if '-show_valid_opts' in sys.argv: # show all valid options self.valid_opts.show('', 1) return 0 if '-ver' in sys.argv: print g_version return 0 # ------------------------------------------------------------ # now read user options self.user_opts = option_list.read_options(sys.argv, self.valid_opts) if not self.user_opts: return 1 # error condition return None # normal completion
def get_opts(): global g_help_string okopts = option_list.OptionList('for input') okopts.add_opt('-help', 0, [], \ helpstr='display program help') okopts.add_opt('-hist', 0, [], \ helpstr='display the modification history') okopts.add_opt('-show_valid_opts', 0, [], \ helpstr='display all valid options') okopts.add_opt('-ver', 0, [], \ helpstr='display the current version number') okopts.add_opt('-amplitudes', 0, [], \ helpstr='output is in -stim_times_AM1 format') okopts.add_opt('-files', -1, [], req=1, okdash=0, helpstr='set the list of input files') okopts.add_opt('-prefix', 1, [], req=1, \ helpstr='specify the prefix for output files') okopts.add_opt('-tr', 1, [], req=1, \ helpstr='set the TR time, in seconds') okopts.add_opt('-nt', 1, [], req=0, \ helpstr='set the number of TRs per run') okopts.add_opt('-nruns', 1, [], req=0, \ helpstr='set the number of runs') okopts.add_opt('-no_consec', 0, [], \ helpstr='do not allow consecutive events') okopts.add_opt('-offset', 1, [], \ helpstr='specify offset to add to all output times') okopts.add_opt('-run_trs', -1, [], req=0, \ helpstr='specify TRs per run, if they vary') okopts.add_opt('-labels', -1, [], okdash=0, helpstr='add these labels to the file names') okopts.add_opt('-verb', 1, [], \ helpstr='set the verbosity level') okopts.trailers = 1 # process any optlist_ options okopts.check_special_opts(sys.argv) # if argv has only the program name, or user requests help, show it if len(sys.argv) <= 1 or '-help' in sys.argv: print g_help_string return if '-hist' in sys.argv: # print history print g_mst_history return if '-show_valid_opts' in sys.argv: # show all valid options okopts.show('', 1) return if '-ver' in sys.argv: # print version print g_mst_version return opts = option_list.read_options(sys.argv, okopts) return opts
def process_options(self): """return 1 on valid and exit return 0 on valid and continue return -1 on invalid """ argv = sys.argv # process any optlist_ options self.valid_opts.check_special_opts(argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, do default processing if '-help' in argv or len(argv) < 2: print g_help_string return 1 if '-hist' in argv: print g_history return 1 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 1 if '-ver' in argv: print g_version return 1 # ============================================================ # read options specified by the user self.user_opts = OL.read_options(argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return -1 # error condition # ------------------------------------------------------------ # process verb first val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val # ------------------------------------------------------------ # process options sequentially, to make them like a script errs = 0 for opt in self.user_opts.olist: # check for anything to skip if opt.name == '-verb': pass elif opt.name == '-infiles': self.infiles, err = uopts.get_string_list('', opt=opt) if self.infiles == None or err: print '** failed to read -infiles list' errs += 1 # allow early and late error returns if errs: return -1 # ------------------------------------------------------------ # apply any trailing logic if len(self.infiles) < 1: print '** missing -infiles option' errs += 1 if errs: return -1 return 0
def process_options(valid_opts, argv): """return status and VarsObject structs of subject and control variables - given list of valid options, read and process the user options - if terminal option or -no_gui, return 0 (succesful quit) return 1 : on success and terminate 0 : on success and continue with GUI -1 : on error condition """ # a quick out if len(argv) == 0: return 0, None, None, None # process any optlist_ options valid_opts.check_special_opts(argv) # ------------------------------------------------------------ # check for terminal options before processing the rest if '-help' in sys.argv: print(g_command_help) valid_opts.show('', 1, show_count=0) print(g_help_trailer) return 1, None, None, None if '-help_gui' in sys.argv: print(USUBJ.helpstr_usubj_gui) return 1, None, None, None if '-help_howto_program' in sys.argv: print(USUBJ.helpstr_howto_program) return 1, None, None, None if '-help_install' in sys.argv: print(g_install_str) return 1, None, None, None if '-help_install_nokia' in sys.argv: print(g_install_nokia) return 1, None, None, None if '-hist' in sys.argv: print(USUBJ.g_history) return 1, None, None, None if '-show_default_vars' in sys.argv: USUBJ.g_ctrl_defs.show('default cvars :') USUBJ.g_subj_defs.show('default svars :') return 1, None, None, None if '-show_valid_opts' in sys.argv: valid_opts.show('', 1) return 1, None, None, None if '-show_svar_dict' in sys.argv: dict = USUBJ.g_svar_dict keys = list(dict.keys()) keys.sort() for key in keys: print(' %-20s : %s' % (key, dict[key])) return 1, None, None, None if '-todo' in sys.argv: print(USUBJ.helpstr_todo) return 1, None, None, None if '-ver' in sys.argv: print('uber_subject.py: version %s' % USUBJ.g_version) return 1, None, None, None # ------------------------------------------------------------ # read and process user options (no check for terminal opts) uopts = OPT.read_options(argv, valid_opts) if not uopts: return -1, None, None, None # init subject options struct svars = VO.VarsObject('subject vars from command line') cvars = VO.VarsObject('control vars from command line') guiopts = ['uber_subject.py'] # first set verbose level val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: verb = val else: verb = 1 USUBJ.set_vstr_from_def('cvars', 'verb', ['%d' % verb], cvars) use_gui = 1 # assume GUI unless we hear otherwise svar_keys = list(USUBJ.g_svar_dict.keys()) errs = 0 # ------------------------------------------------------------ # first process all setup options (e.g. -anal_type/domain) # - since they might go via -svar, we must search for opt in uopts.olist: # just check for 'rest' here if opt.name == '-anal_type': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return -1, None, None, None if val == 'rest': if verb > 1: print('-- init from rest defaults') svars.merge(USUBJ.g_rdef_strs) elif opt.name == '-anal_domain': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return -1, None, None, None if val == 'surface': print('** uber_subject.py: not ready for surface analysis') return -1, None, None, None elif opt.name == '-svar': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return -1, None, None, None if val[0] == '-anal_type': if val[1] == 'rest': if verb > 1: print('-- init from rest defaults') svars.merge(USUBJ.g_rdef_strs) elif val[0] == '-anal_domain': if val[1] == 'surface': print('** uber_subject.py: not ready for surface analysis') return -1, None, None, None # done with analysis init options # ------------------------------------------------------------ for opt in uopts.olist: # skip -verb and any terminal option (though they should not be here) if opt.name == '-help': continue elif opt.name == '-help_gui': continue elif opt.name == '-hist': continue elif opt.name == '-show_valid_opts': continue elif opt.name == '-todo': continue elif opt.name == '-ver': continue elif opt.name == '-verb': continue # and skip any pre-setup options ... elif opt.name == '-anal_type': continue elif opt.name == '-anal_domain': continue # and skip any post-setup options ... elif opt.name == '-print_ap_command': continue elif opt.name == '-save_ap_command': continue elif opt.name == '-exec_ap_command': continue elif opt.name == '-exec_proc_script': continue vname = opt.name[1:] # now go after "normal" options if opt.name == '-no_gui': use_gui = 0 continue # get any PyQt4 options elif opt.name == '-qt_opts': val, err = uopts.get_string_list('', opt=opt) if val != None and err: return -1, None, None, None guiopts.extend(val) # cvar requires at least 2 parameters, name and value elif opt.name == '-cvar': val, err = uopts.get_string_list('', opt=opt) if val != None and err: return -1, None, None, None # and set it from the form name = [value_list] if USUBJ.set_vstr_from_def( 'cvars', val[0], val[1:], cvars, verb=verb, spec=1) < 0: errs += 1 continue # svar requires at least 2 parameters, name and value elif opt.name == '-svar': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return -1, None, None, None # and set it from the form name = [value_list] if USUBJ.set_vstr_from_def( 'svars', val[0], val[1:], svars, verb=verb, spec=1) < 0: errs += 1 continue # go after a direct svar key elif vname in svar_keys: val, err = uopts.get_string_list('', opt=opt) if val == None or err: return -1, None, None, None if USUBJ.set_vstr_from_def( 'svars', vname, val, svars, verb=verb, spec=1) < 0: errs += 1 continue else: print('** invalid option: %s' % opt.name) errs += 1 continue if not errs: # then we can handle any processing options if uopts.find_opt('-print_ap_command'): print_ap_command(svars, cvars) if not errs: # then we can handle any processing options opt = uopts.find_opt('-save_ap_command') if opt != None: val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return -1, None, None, None save_ap_command(svars, cvars, val) if not errs: # then we can handle any processing options if uopts.find_opt('-exec_ap_command'): subj = run_ap_command(svars, cvars) if subj != None and uopts.find_opt('-exec_proc_script'): subj.exec_proc_script() if verb > 2: # show applied subject variables changestr = cvars.changed_attrs_str(USUBJ.g_cdef_strs, skiplist='name', showskip=0, showdel=0) print('++ applied control variables: %s\n' % changestr) changestr = svars.changed_attrs_str(USUBJ.g_sdef_strs, skiplist='name', showskip=0, showdel=0) print('++ applied subject variables: %s\n' % changestr) if errs: return -1, None, None, None if use_gui: return 0, svars, cvars, guiopts else: return 1, svars, cvars, guiopts
def process_options(self): """return 1 on valid and exit 0 on valid and continue -1 on invalid """ argv = sys.argv # a quick out (no help, continue and open GUI) if len(argv) == 0: return 0 # process any optlist_ options self.valid_opts.check_special_opts(argv) # ------------------------------------------------------------ # check for terminal options before processing the rest if '-help' in argv: print(g_command_help) return 1 if '-help_gui' in argv: print(LTT.helpstr_gui) return 1 if '-help_todo' in argv: print(LTT.helpstr_todo) return 1 if '-hist' in argv: print(LTT.g_history) return 1 if '-show_default_vars' in argv: LTT.g_user_defs.show('default uvars :') return 1 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 1 if '-show_cvar_dict' in sys.argv: dict = LTT.g_cvar_dict keys = list(dict.keys()) keys.sort() for key in keys: print(' %-20s : %s' % (key, dict[key])) return 1 if '-show_uvar_dict' in sys.argv: dict = LTT.g_uvar_dict keys = list(dict.keys()) keys.sort() for key in keys: print(' %-20s : %s' % (key, dict[key])) return 1 if '-ver' in argv: print('uber_ttest.py: version %s' % LTT.g_version) return 1 # ------------------------------------------------------------ # read and process user options (no check for terminal opts) self.uopts = OPT.read_options(argv, self.valid_opts) if not self.uopts: return -1 uopts = self.uopts # convenience # init subject options struct self.cvars = VO.VarsObject('control vars from command line') self.uvars = VO.VarsObject('user vars from command line') self.guiopts = ['uber_ttest.py'] # first set verbose level val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val else: self.verb = 1 SUBJ.set_var_str_from_def('cvars', 'verb', ['%d' % self.verb], self.cvars, defs=LTT.g_ctrl_defs) use_gui = 1 # assume GUI unless we hear otherwise cvar_keys = list(LTT.g_cvar_dict.keys()) uvar_keys = list(LTT.g_uvar_dict.keys()) # we already processed terminal options term_opts = [ '-help', '-help_gui', '-help_todo', '-hist', 'show_default_vars', '-ver', '-show_cvar_dict', '-show_uvar_dict' ] # skip post-setup options, to be checked later post_opts = ['-print_script', '-save_script'] # first process all setup options errs = 0 for opt in uopts.olist: # skip -verb (any terminal option should block getting here) if opt.name in term_opts: continue # and skip and post-setup options (print command, save, etc.) if opt.name in post_opts: continue vname = opt.name[1:] # now go after "normal" options if opt.name == '-no_gui': use_gui = 0 continue # get any PyQt4 options elif opt.name == '-qt_opts': val, err = uopts.get_string_list('', opt=opt) if val != None and err: errs += 1 continue self.guiopts.extend(val) # cvar requires at least 2 parameters, name and value elif opt.name == '-cvar': val, err = uopts.get_string_list('', opt=opt) if val != None and err: errs += 1 continue if self.cvars.set_var_with_defs(val[0], val[1:], LTT.g_ctrl_defs, oname='cvars', verb=self.verb) < 0: errs += 1 continue # uvar requires at least 2 parameters, name and value elif opt.name == '-uvar': val, err = uopts.get_string_list('', opt=opt) if val != None and err: errs += 1 continue if self.uvars.set_var_with_defs(val[0], val[1:], LTT.g_user_defs, oname='uvars', verb=self.verb) < 0: errs += 1 continue # maybe this is a control variable key elif vname in cvar_keys: val, err = uopts.get_string_list('', opt=opt) if val == None or err: errs += 1 continue if self.cvars.set_var_with_defs( vname, val, LTT.g_ctrl_defs, oname='cvars', verb=self.verb) < 0: errs += 1 continue # maybe this is a user variable key elif vname in uvar_keys: val, err = uopts.get_string_list('', opt=opt) if val == None or err: errs += 1 continue if self.uvars.set_var_with_defs( vname, val, LTT.g_user_defs, oname='uvars', verb=self.verb) < 0: errs += 1 continue else: print('** invalid option: %s' % opt.name) errs += 1 continue if not errs: # then we can handle any processing options if uopts.find_opt('-print_script'): self.print_script() use_gui = 0 #opt = uopts.find_opt('-save_script') #if opt != None: # val, err = uopts.get_string_opt('', opt=opt) val, err = uopts.get_string_opt('-save_script') if val != None and not err: self.save_script(val) use_gui = 0 if errs: return -1 if use_gui: return 0 # continue and open GUI else: return 1 # no error, but terminate on return
def process_options(self): # ============================================================ # read options specified by the user self.user_opts = OL.read_options(sys.argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return 1 # error condition # ------------------------------------------------------------ # check -test_libs separately, as we may want to apply -verb if '-test_libs' in sys.argv: val, err = self.user_opts.get_type_opt(int, '-verb') if val == None or err: val = 2 return self.test_libraries(verb=val) # attempting real work, load AM (locally) if self.set_afni_xmat(): return 1 # ------------------------------------------------------------ # check general options, esp. chrono if uopts.find_opt('-chrono'): self.chrono = 1 # if options are not chronological, process general options now # (so -show options are still in order) if not self.chrono: # general options might affect selection options val, err = self.user_opts.get_type_opt(float, '-cormat_cutoff') if val != None and not err: self.cormat_cut = val val, err = self.user_opts.get_type_opt(float, '-cosmat_cutoff') if val != None and not err: self.cosmat_cut = val val, err = self.user_opts.get_type_opt(float, '-cosmat_motion') if val != None and not err: self.cosmat_motion = 1 val, err = self.user_opts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val # selection options val, err = uopts.get_string_opt('-load_xmat') if val and not err: if self.set_xmat(val): return 1 val, err = uopts.get_string_opt('-load_1D') if val and not err: if self.set_1D(val): return 1 val, err = uopts.get_string_opt('-choose_cols') if val and not err: rstr = self.set_cols_from_string(val) if rstr: print "** failed to apply '-choose_cols':\n%s" % rstr return 1 # ------------------------------------------------------------ # selection and process options: # process sequentially, to make them like a script for opt in uopts.olist: # if all options are chronological, check load and general, too if self.chrono: # selection options if opt.name == '-load_xmat': if self.set_xmat(opt.parlist[0]): return 1 elif opt.name == '-load_1D': if self.set_1D(opt.parlist[0]): return 1 elif opt.name == '-choose_cols': rstr = self.set_cols_from_string(opt.parlist[0]) if rstr: print "** failed to apply '-choose_cols':\n%s" % rstr return 1 # general options elif opt.name == '-cormat_cutoff': val, err = self.user_opts.get_type_opt(float, '', opt=opt) if val != None and err: return 1 else: self.cormat_cut = val elif opt.name == '-cosmat_cutoff': val, err = self.user_opts.get_type_opt(float, '', opt=opt) if val != None and err: return 1 else: self.cosmat_cut = val elif opt.name == '-cosmat_motion': self.cosmat_motion = 1 elif opt.name == '-verb': val, err = self.user_opts.get_type_opt(int, '', opt=opt) if val != None and err: return 1 else: self.verb = val # 'show' options (allow these to fail?) if opt.name == '-show_col_types': if self.matX: err, str = self.make_col_type_string() print str else: print "** -show_col_types: needs -load_xmat" elif opt.name == '-show_conds': if self.matX: print self.matX.make_show_conds_str(self.col_list) else: print "** -show_conds: needs -load_xmat" elif opt.name == '-show_cormat': err, str = self.make_cormat_string() print '-- Correlation matrix for %s :' % self.fname_mat print str
def process_options(self): argv = sys.argv if len(argv) == 0: # non-gui out print g_command_help return 1 # process any optlist_ options self.valid_opts.check_special_opts(argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, apply -help if len(argv) <= 1 or '-help' in argv: print g_command_help return 1 if '-hist' in argv: print CLUST.g_history return 1 if '-show_default_cvars' in argv: CLUST.g_ctrl_defs.show('') return 1 if '-show_default_uvars' in argv: CLUST.g_user_defs.show('') return 1 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 1 if '-ver' in argv: print CLUST.g_version return 1 # ============================================================ # read options specified by the user self.user_opts = OPT.read_options(argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return -1 # error condition # ------------------------------------------------------------ # init subject options struct self.cvars = VO.VarsObject('control vars from command line') self.uvars = VO.VarsObject('user vars from command line') val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val SUBJ.set_var_str_from_def('cvars', 'verb', ['%d' % self.verb], self.cvars, defs=CLUST.g_ctrl_defs) # first process all setup options errs = 0 for opt in uopts.olist: # skip -verb (any terminal option should block getting here) if opt.name == '-verb': continue # and skip and post-setup options (print command, save, etc.) elif opt.name == '-print_script': continue elif opt.name == '-save_script': continue # now go after "normal" options elif opt.name == '-on_surface': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return -1 if self.cvars.set_var_with_defs(opt.name[1:], val, CLUST.g_ctrl_defs, as_type=1, oname='cvars', verb=self.verb) < 0: errs += 1 continue # cvar requires at least 2 parameters, name and value elif opt.name == '-cvar': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return -1 # go after verb, in particular if val[0] == 'verb': try: self.verb = int(val[1]) except: print "** failed to set 'verb' level" errs += 1 continue # and set it from the form name = [value_list] if SUBJ.set_var_str_from_def('cvars', val[0], val[1:], self.cvars, CLUST.g_ctrl_defs, verb=self.verb) < 0: errs += 1 continue # uvar requires at least 2 parameters, name and value elif opt.name == '-uvar': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return -1 # and set it from the form name = [value_list] if SUBJ.set_var_str_from_def('uvars', val[0], val[1:], self.uvars, CLUST.g_user_defs, verb=self.verb) < 0: errs += 1 continue else: print '** unknown option %s' % opt.name errs += 1 if self.verb > 2: print '-' * 75 self.uvars.show('post-init uvars', name=0) self.cvars.show('post-init cvars', name=0) print '-' * 75 if errs: return -1 else: return 0 # no error, and continue on return
def process_options(self): """return 1 on valid and exit return 0 on valid and continue return -1 on invalid """ argv = sys.argv # process any optlist_ options self.valid_opts.check_special_opts(argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, do default processing if '-help' in argv or len(argv) < 2: show_help() return 1 if '-help_examples' in argv: print g_help_examples return 1 if '-hist' in argv: print g_history return 1 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 1 if '-ver' in argv: print g_version return 1 # ============================================================ # read options specified by the user self.user_opts = OL.read_options(argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return -1 # error condition # ------------------------------------------------------------ # process verb first val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val # ------------------------------------------------------------ # process options sequentially, to make them like a script errs = 0 for opt in self.user_opts.olist: # check for anything to skip if opt.name == '-verb': pass elif opt.name == '-logfile': self.logfile, err = uopts.get_string_opt('', opt=opt) if self.logfile == None or err: print '** failed to read -logfile name' errs += 1 elif opt.name == '-labels': self.labels, err = uopts.get_string_list('', opt=opt) if self.labels == None or err: print '** option -labels: failed to process option' errs += 1 elif opt.name == '-show_all_orig': pass # process later elif opt.name == '-show_orig': self.show_vals = SHOW_ORIG elif opt.name == '-show_rank': self.show_vals = SHOW_RANK if self.user_opts.find_opt('-show_all_orig'): if not (self.show_vals & SHOW_ORIG): print "** -show_all_orig requires showing orig" errs += 1 self.show_vals |= SHOW_ALL_ORIG # allow early and late error returns if errs: return -1 # ------------------------------------------------------------ ## apply any trailing logic if self.logfile == '': print '** missing -logfile option' errs += 1 if len(self.labels) < 1: print '** missing -labels to search for' errs += 1 if errs: return -1 return 0
def process_options(self): """return 1 on valid and exit return 0 on valid and continue return -1 on invalid """ argv = sys.argv # process any optlist_ options self.valid_opts.check_special_opts(argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, do default processing if '-help' in argv or len(argv) < 2: print(g_help_string) return 1 if '-hist' in argv: print(g_history) return 1 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 1 if '-ver' in argv: print(g_version) return 1 # ============================================================ # read options specified by the user self.user_opts = OL.read_options(argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return -1 # error condition # ------------------------------------------------------------ # process verb first val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val # ------------------------------------------------------------ # process options sequentially, to make them like a script errs = 0 for opt in self.user_opts.olist: # check for anything to skip if opt.name == '-verb': pass elif opt.name == '-infiles': self.infiles, err = uopts.get_string_list('', opt=opt) if self.infiles == None or err: print('** failed to read -infiles list') errs += 1 self.parse_infile_names() elif opt.name == '-overwrite': self.overwrite = 1 elif opt.name == '-separator': self.separator, err = uopts.get_string_opt('', opt=opt) if self.separator == None or err: print("** bad -tablefile option") errs += 1 if self.separator == 'tab': self.separator = '\t' elif self.separator == 'whitespace': self.separator = 'ws' self.seplen = len(self.separator) elif opt.name == '-showlabs': self.showlabs = 1 elif opt.name == '-show_missing': self.show_missing = 1 elif opt.name == '-tablefile': self.tablefile, err = uopts.get_string_opt('', opt=opt) if self.tablefile == None or err: print("** bad -tablefile option") errs += 1 else: oind = self.user_opts.olist.index(opt) print('** unknown option # %d: %s' % (oind + 1, opt.name)) errs += 1 break # allow early and late error returns if errs: return -1 # ------------------------------------------------------------ # apply any trailing logic if len(self.infiles) < 1: print('** missing -infiles option') errs += 1 if errs: return -1 return 0
def process_options(self): """return 1 on valid and exit 0 on valid and continue -1 on invalid """ argv = sys.argv # a quick out (no help, continue and open GUI) if len(argv) == 0: return 0 # process any optlist_ options self.valid_opts.check_special_opts(argv) # ------------------------------------------------------------ # check for terminal options before processing the rest if '-help' in argv: print g_command_help return 1 if '-help_gui' in argv: print USKEL.helpstr_gui return 1 if '-help_howto_program' in argv: print USKEL.helpstr_create_program return 1 if '-help_todo' in argv: print USKEL.helpstr_todo return 1 if '-hist' in argv: print USKEL.g_history return 1 if '-show_default_vars' in argv: USKEL.g_user_defs.show('default uvars :') return 1 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 1 if '-ver' in argv: print 'uber_skel.py: version %s' % USKEL.g_version return 1 # ------------------------------------------------------------ # read and process user options (no check for terminal opts) self.uopts = OPT.read_options(argv, self.valid_opts) if not self.uopts: return -1 uopts = self.uopts # convenience # init subject options struct self.cvars = VO.VarsObject('control vars from command line') self.uvars = VO.VarsObject('user vars from command line') self.guiopts = ['uber_skel.py'] # first set verbose level val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val else: self.verb = 1 SUBJ.set_var_str_from_def('uvars', 'verb', ['%d' % self.verb], self.uvars, defs=USKEL.g_user_defs) use_gui = 1 # assume GUI unless we hear otherwise # first process all setup options errs = 0 for opt in uopts.olist: # skip -verb (any terminal option should block getting here) if opt.name == '-verb': continue # and skip and post-setup options (print command, save, etc.) elif opt.name == '-print_script': continue elif opt.name == '-save_script': continue # now go after "normal" options if opt.name == '-no_gui': use_gui = 0 continue # get any PyQt4 options elif opt.name == '-qt_opts': val, err = uopts.get_string_list('', opt=opt) if val != None and err: return -1 self.guiopts.extend(val) # cvar requires at least 2 parameters, name and value elif opt.name == '-cvar': val, err = uopts.get_string_list('', opt=opt) if val != None and err: return -1 # and set it from the form name = [value_list] if SUBJ.set_var_str_from_def('cvars', val[0], val[1:], self.cvars, USKEL.g_ctrl_defs, verb=self.verb) < 0: errs += 1 continue # uvar requires at least 2 parameters, name and value elif opt.name == '-uvar': val, err = uopts.get_string_list('', opt=opt) if val != None and err: return -1 # and set it from the form name = [value_list] if SUBJ.set_var_str_from_def('uvars', val[0], val[1:], self.uvars, USKEL.g_user_defs, verb=self.verb) < 0: errs += 1 continue if not errs: # then we can handle any processing options if uopts.find_opt('-print_script'): self.print_script() if not errs: # then we can handle any processing options opt = uopts.find_opt('-save_script') if opt != None: val, err = uopts.get_string_opt('', opt=opt) if val != None and not err: self.save_script(val) if errs: return -1 if use_gui: return 0 # continue and open GUI else: return 1 # no error, but terminate on return
def process_options(self, argv=sys.argv): # process any optlist_ options self.valid_opts.check_special_opts(argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, apply -help if '-help' in argv or len(argv) < 2: print(g_help_string) return 0 if '-help_rc_files' in argv or '-help_dot_files' in argv: print(g_help_rc_files) return 0 if '-hist' in argv: print(g_history) return 0 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 0 if '-todo' in argv: print(g_todo) return 0 if '-ver' in argv: print(g_version) return 0 # ============================================================ # read options specified by the user self.user_opts = OL.read_options(argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return 1 # error condition # ------------------------------------------------------------ # process options, go after -verb first val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val for opt in uopts.olist: if opt.name == '-casematch': if OL.opt_is_yes(opt): self.casematch = 1 else: self.casematch = 0 continue if opt.name == '-check_all': self.act = 1 self.sys_check = 1 continue if opt.name == '-data_root': self.data_root = opt.parlist[0] continue if opt.name == '-dot_file_list': self.dot_file_list = 1 self.act = 1 continue if opt.name == '-dot_file_pack': self.dot_file_pack = opt.parlist[0] self.act = 1 continue if opt.name == '-dot_file_show': self.dot_file_show = 1 self.act = 1 continue if opt.name == '-exact': if OL.opt_is_yes(opt): self.exact = 1 # default of casematching is 1 for this if self.casematch < 0: self.casematch = 1 else: self.exact = 0 continue if opt.name == '-find_prog': self.act = 1 self.find_prog = opt.parlist[0] continue # already processing options: just continue if opt.name == '-verb': continue # an unhandled option print('** option %s not yet supported' % opt.name) return 1 if not self.act: print('** no action option found, please see -help output\n') return 1 return None
def process_options(self, argv=sys.argv): # process any optlist_ options self.valid_opts.check_special_opts(argv) # process terminal options without the option_list interface # (so that errors are not reported) # if no arguments are given, apply -help if len(argv) <= 1 or '-help' in argv: print(g_help_string) return 0 if '-hist' in argv: print(g_history) return 0 if '-show_valid_opts' in argv: self.valid_opts.show('', 1) return 0 if '-ver' in argv: print(g_version) return 0 # ============================================================ # read options specified by the user self.user_opts = OL.read_options(argv, self.valid_opts) uopts = self.user_opts # convenience variable if not uopts: return 1 # error condition # ------------------------------------------------------------ # require a list of files, at least # ------------------------------------------------------------ # process options, go after -verb first val, err = uopts.get_type_opt(int, '-verb') if val != None and not err: self.verb = val for opt in uopts.olist: # main options if opt.name == '-AminusB': self.comp_dir = opt.name continue if opt.name == '-BminusA': self.comp_dir = opt.name continue if opt.name == '-command': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return 1 self.command = val continue if opt.name == '-dsets': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.dsets.append(val) # allow multiple such options continue if opt.name == '-dset_index0_list': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.index0_list.append(val) # allow multiple such options continue if opt.name == '-dset_index1_list': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.index1_list.append(val) # allow multiple such options continue if opt.name == '-factors': val, err = uopts.get_type_list(int, '', opt=opt) if val == None or err: return 1 self.factors = val continue if opt.name == '-keep_dirent_pre': self.dent_pre = 1 continue if opt.name == '-options': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.options = val continue if opt.name == '-prefix': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return 1 self.prefix = val continue if opt.name == '-set_labels': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.lablist = val continue if opt.name == '-subj_prefix': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return 1 self.subj_prefix = val continue if opt.name == '-subj_suffix': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return 1 self.subj_suffix = val continue if opt.name == '-subs_betas': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.betasubs = val continue if opt.name == '-subs_tstats': val, err = uopts.get_string_list('', opt=opt) if val == None or err: return 1 self.tstatsubs = val continue if opt.name == '-type': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return 1 self.ttype = val continue if opt.name == '-verb': continue # already handled if opt.name == '-write_script': val, err = uopts.get_string_opt('', opt=opt) if val == None or err: return 1 self.write_script = val continue # general options # an unhandled option print('** option %s not yet supported' % opt.name) return 1 if self.verb > 2: self.show() # process -dset_index_list_0 and _1 if self.update_dset_lists(): return 1 return None