def option_callback_W(option, opt, value, parser): # Options preceded by a "-Wl," are simply treated as though the "-Wl," # is not there? I don't understand the purpose of this code... if len(value) < 4 or value[0:3] != "l,-": raise optparse.BadOptionError("not in '-Wl,<opt>' form: %s%s" % (opt, value)) opt = value[2:] if opt not in ["-L", "-R", "--rpath"]: raise optparse.BadOptionError("-Wl option must be -L, -R" " or --rpath, not " + value[2:]) # Push the linker option onto the list for further parsing. parser.rargs.insert(0, value)
def prepareOption(argv): """ memeriksa opsi unik dan mengembalikan opsi unik ke opsi normal """ for i in xrange(len(argv)): option = argv[i] if option not in uniqueOptDict.keys(): if isUniqueOption(option): raise optparse.BadOptionError(option) else: # kembalikan opsi unik ke opsi normal argv[i] = uniqueOptDict[option] return argv
def _match_long_opt(self, opt): """ Override optparse._match_long_opt method. This method disables prefix matching. Only exact match is supported. If ambiguous options are found, they are listed, and AmbiguousOptionError exception is raised. """ # Is there an exact match? if opt in self._long_opt: return opt else: # Isolate all words with s as a prefix. possibilities = [ word for word in self._long_opt.keys() if word.startswith(opt) ] if not possibilities: # No match. raise optparse.BadOptionError(opt) else: # Ambiguous prefix. possibilities.sort() raise optparse.AmbiguousOptionError(opt, possibilities)
def _match_long_opt(self, opt): """Disable abbreviations.""" if opt not in self._long_opt: raise optparse.BadOptionError(opt) return opt
def _process_long_opt(self, rargs, values): """ SCons-specific processing of long options. This is copied directly from the normal optparse._process_long_opt() method, except that, if configured to do so, we catch the exception thrown when an unknown option is encountered and just stick it back on the "leftover" arguments for later (re-)processing. """ arg = rargs.pop(0) # Value explicitly attached to arg? Pretend it's the next argument. if "=" in arg: (opt, next_arg) = arg.split("=", 1) rargs.insert(0, next_arg) had_explicit_value = True else: opt = arg had_explicit_value = False try: if opt != self._match_long_opt(opt): raise optparse.BadOptionError("'%s'. Did you mean '%s'?" % (opt, self._match_long_opt(opt))) except optparse.BadOptionError: if self.preserve_unknown_options: # SCons-specific: if requested, add unknown options to # the "leftover arguments" list for later processing. self.largs.append(arg) if had_explicit_value: # The unknown option will be re-processed later, # so undo the insertion of the explicit value. rargs.pop(0) return raise option = self._long_opt[opt] if option.takes_value(): nargs = option.nargs if nargs == '?': if had_explicit_value: value = rargs.pop(0) else: value = option.const elif len(rargs) < nargs: if nargs == 1: if not option.choices: self.error(_("%s option requires an argument") % opt) else: msg = _("%s option requires an argument " % opt) msg += _("(choose from %s)" % ', '.join(option.choices)) self.error(msg) else: self.error( _("%s option requires %d arguments") % (opt, nargs)) elif nargs == 1: value = rargs.pop(0) else: value = tuple(rargs[0:nargs]) del rargs[0:nargs] elif had_explicit_value: self.error(_("%s option does not take a value") % opt) else: value = None option.process(opt, value, values, self)
def _process_short_opts(self, rargs, values): """ SCons-specific processing of short options. This is copied directly from the normal optparse._process_short_opts() method, except that, if configured to do so, we catch the exception thrown when an unknown option is encountered and just stick it back on the "leftover" arguments for later (re-)processing. """ arg = rargs.pop(0) stop = False i = 1 for ch in arg[1:]: opt = "-" + ch option = self._short_opt.get(opt) i += 1 # we have consumed a character try: if not option: raise optparse.BadOptionError(opt) except optparse.BadOptionError: if self.preserve_unknown_options: # SCons-specific: if requested, add unknown options to # the "leftover arguments" list for later processing. self.largs.append(arg) return raise if option.takes_value(): had_explicit_value = False # Any characters left in arg? Pretend they're the # next arg, and stop consuming characters of arg. if i < len(arg): rargs.insert(0, arg[i:]) stop = True had_explicit_value = True nargs = option.nargs if len(rargs) < nargs: if nargs == 1: self.error(_("%s option requires an argument") % opt) else: self.error( _("%s option requires %d arguments") % (opt, nargs)) elif nargs == 1: value = rargs.pop(0) if not had_explicit_value: SCons.Script._Remove_Target(value) if '=' in value: SCons.Script._Remove_Argument(value) else: value = tuple(rargs[0:nargs]) del rargs[0:nargs] for i in range(len(value)): if not had_explicit_value or i > 0: SCons.Script._Remove_Target(value[i]) if '=' in value[i]: SCons.Script._Remove_Argument(value[i]) else: # option doesn't take a value value = None option.process(opt, value, values, self) if stop: break
def _match_long_opt(self, opt): match = optparse._match_abbrev(opt, self._long_opt) if not self.matchPartialOptions and opt != match: raise optparse.BadOptionError("no such option: %s" % opt) return match
def _match_long_opt(self, opt): # pragma: no cover # Unused """Disable abbreviations.""" if opt not in self._long_opt: raise optparse.BadOptionError(opt) return opt