Example #1
0
   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 = SUBJ.VarsObject('control vars from command line')
      self.uvars = SUBJ.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
Example #2
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
Example #3
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 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 = 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 = 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 = SUBJ.VarsObject('control vars from command line')
      self.uvars = SUBJ.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 = LTT.g_cvar_dict.keys()
      uvar_keys = 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
Example #4
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 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 = 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 = 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 = SUBJ.VarsObject('control vars from command line')
        self.uvars = SUBJ.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 = LTT.g_cvar_dict.keys()
        uvar_keys = 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