示例#1
0
    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
示例#2
0
   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