def _process_long_opt(self, rargs, values): 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 arg = opt opt = self._match_long_opt(opt) if isinstance(opt, tuple): negate = opt[1] opt = opt[0] else: negate = False if arg != opt and not arg.startswith("--no-"): import sys print >>sys.stderr, 'Warning: assuming %s for given option %s' % \ (opt, arg) option = self._long_opt[opt] option.negate ^= negate nargs = option.nargs or 0 oargs = option.oargs or 0 if option.takes_value(): oargs += nargs args = self._get_arguments(rargs) if len(args) < nargs: if nargs == 1: self.error(_("%s option requires an argument") % opt) else: self.error(_("%s option requires %d arguments") % (opt, nargs)) elif len(args) == 0 or oargs == 0: value = None elif len(args) == 1 or oargs == 1: value = rargs.pop(0) else: value = tuple(rargs[0:oargs]) del rargs[0:oargs] 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): 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 if not option: if optparse_version >= '1.5.3': raise BadOptionError(opt) else: self.error(_("no such option: %s") % opt) nargs = option.nargs or 0 oargs = option.oargs or 0 if option.takes_value(): # 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 oargs += nargs args = self._get_arguments(rargs) if len(args) < nargs: if nargs == 1: self.error(_("%s option requires an argument") % opt) else: self.error(_("%s option requires %d arguments") % (opt, nargs)) elif len(args) == 0 or oargs == 0: value = None elif len(args) == 1 or oargs == 1: value = rargs.pop(0) else: value = tuple(rargs[0:oargs]) del rargs[0:oargs] else: # option doesn't take a value value = None option.process(opt, value, values, self) if stop: break
def format_option_help(self, formatter=None): formatter = IndentedHelpFormatterWithNL() if formatter is None: formatter = self.formatter formatter.store_option_strings(self) result = [] result.append(formatter.format_heading(optparse._("Options"))) formatter.indent() if self.option_list: result.append(optparse.OptionContainer.format_option_help(self, formatter)) result.append("\n") for group in self.option_groups: result.append(group.format_help(formatter)) result.append("\n") formatter.dedent() # Drop the last "\n", or the header if no options or option groups: return "".join(result[:-1])
def format_usage(self, usage): return _(" %s") % usage
def format_usage(self, usage): return optparse._("%s\n" % usage)
def format_usage(self, usage): return self._formatter(optparse._("Usage: %s\n") % usage)
def format_usage(self, usage): return optparse._("Usage: %s\n") % usage
def format_usage(self, usage): return optparse._("%s") % usage.lstrip()
def _add_version_option(self): self.add_option('-v', '--version', action='version', help=optparse._(u'отобразить версию программы и выйти'))
def format_usage(self, usage): template = u'{name} {version}\nИспользование:\n {usage}' message = template.format(name = self.longappname, version=self.appver, usage=usage) return optparse._(message)
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import sys, os from optparse import OptionParser, _ import MySQLdb parser = OptionParser() parser.remove_option('-h') parser.add_option("", "--help", action="help", help=_("show this help message and exit")) parser.add_option("-h", "--host", dest="host", default="localhost", help="Connect to host.", metavar="HOST") parser.add_option("-u", "--user", dest="user", help="User login if not current user.", metavar="USER") parser.add_option("-p", "--password", dest="password", default='', help="Password to use when connecting to server. If password is not given it's asked from the tty.", metavar="PASSWORD") parser.add_option("-P", "--port", dest="port", default=3306, help="Port number to use for connection",
def update_event(self, inp=-1): self.set_output_val(0, optparse._(self.input(0)))
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import sys, os from optparse import OptionParser, _ import MySQLdb parser = OptionParser() parser.remove_option('-h') parser.add_option("", "--help", action="help", help=_("show this help message and exit")) parser.add_option("-h", "--host", dest="host", default="localhost", help="Connect to host.", metavar="HOST") parser.add_option("-u", "--user", dest="user", help="User login if not current user.", metavar="USER") parser.add_option(