当前位置: 首页>>代码示例>>Python>>正文


Python usage.UsageError方法代码示例

本文整理汇总了Python中twisted.python.usage.UsageError方法的典型用法代码示例。如果您正苦于以下问题:Python usage.UsageError方法的具体用法?Python usage.UsageError怎么用?Python usage.UsageError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.usage的用法示例。


在下文中一共展示了usage.UsageError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: opt_reactor

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def opt_reactor(self, shortName):
        """
        Which reactor to use (see --help-reactors for a list of possibilities)
        """
        # Actually actually actually install the reactor right at this very
        # moment, before any other code (for example, a sub-command plugin)
        # runs and accidentally imports and installs the default reactor.
        #
        # This could probably be improved somehow.
        try:
            installReactor(shortName)
        except NoSuchReactor:
            msg = ("The specified reactor does not exist: '%s'.\n"
                   "See the list of available reactors with "
                   "--help-reactors" % (shortName,))
            raise usage.UsageError(msg)
        except Exception as e:
            msg = ("The specified reactor cannot be used, failed with error: "
                   "%s.\nSee the list of available reactors with "
                   "--help-reactors" % (e,))
            raise usage.UsageError(msg)
        else:
            self["reactor"] = shortName 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:app.py

示例2: options

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def options(argv):
        """
        Parse command line options.

        @param argv: Command line arguments.
        @type argv: L{list}

        @return: The parsed options.
        @rtype: L{TwistOptions}
        """
        options = TwistOptions()

        try:
            options.parseOptions(argv[1:])
        except UsageError as e:
            exit(ExitStatus.EX_USAGE, "Error: {}\n\n{}".format(e, options))

        return options 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:_twist.py

示例3: opt_help_auth_type

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def opt_help_auth_type(self, authType):
        """
        Show help for a particular authentication type.
        """
        try:
            cf = findCheckerFactory(authType)
        except InvalidAuthType:
            raise usage.UsageError("Invalid auth type: %s" % authType)
        self.authOutput.write("Usage: --auth %s[:ArgString]\n" % authType)
        self.authOutput.write("ArgString format: %s\n" % cf.argStringFormat)
        self.authOutput.write('\n')
        for line in cf.authHelp.strip().splitlines():
            self.authOutput.write('  %s\n' % line.rstrip())
        self.authOutput.write('\n')
        if not self.supportsCheckerFactory(cf):
            self.authOutput.write('  %s\n' % notSupportedWarning)
            self.authOutput.write('\n')
        raise SystemExit(0) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:strcred.py

示例4: opt_maildirdbmdomain

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def opt_maildirdbmdomain(self, domain):
        """
        Generate an SMTP/POP3 virtual domain.

        This option requires an argument of the form 'NAME=PATH' where NAME is
        the DNS domain name for which email will be accepted and where PATH is
        a the filesystem path to a Maildir folder.
        [Example: 'example.com=/tmp/example.com']
        """
        try:
            name, path = domain.split('=')
        except ValueError:
            raise usage.UsageError("Argument to --maildirdbmdomain must be of the form 'name=path'")

        self.last_domain = maildir.MaildirDirdbmDomain(self.service, os.path.abspath(path))
        self.service.addDomain(name, self.last_domain) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:tap.py

示例5: opt_aliases

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def opt_aliases(self, filename):
        """
        Specify an aliases(5) file to use for the last specified domain.
        """
        if self.last_domain is not None:
            if mail.IAliasableDomain.providedBy(self.last_domain):
                aliases = alias.loadAliasFile(self.service.domains, filename)
                self.last_domain.setAliasGroup(aliases)
                self.service.monitor.monitorFile(
                    filename,
                    AliasUpdater(self.service.domains, self.last_domain)
                )
            else:
                raise usage.UsageError(
                    "%s does not support alias files" % (
                        self.last_domain.__class__.__name__,
                    )
                )
        else:
            raise usage.UsageError("Specify a domain before specifying aliases") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:tap.py

示例6: opt_secondary

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def opt_secondary(self, ip_domain):
        """Act as secondary for the specified domain, performing
        zone transfers from the specified IP (IP/domain)
        """
        args = ip_domain.split('/', 1)
        if len(args) != 2:
            raise usage.UsageError("Argument must be of the form IP[:port]/domain")
        address = args[0].split(':')
        if len(address) == 1:
            address = (address[0], dns.PORT)
        else:
            try:
                port = int(address[1])
            except ValueError:
                raise usage.UsageError(
                    "Specify an integer port number, not %r" % (address[1],))
            address = (address[0], port)
        self.secondaries.append((address, [args[1]])) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:tap.py

示例7: test_malformedSecondary

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def test_malformedSecondary(self):
        """
        If the value supplied for an I{--secondary} option does not provide a
        server IP address, optional port number, and domain name,
        L{Options.parseOptions} raises L{UsageError}.
        """
        options = Options()
        self.assertRaises(
            UsageError, options.parseOptions, ['--secondary', ''])
        self.assertRaises(
            UsageError, options.parseOptions, ['--secondary', '1.2.3.4'])
        self.assertRaises(
            UsageError, options.parseOptions, ['--secondary', '1.2.3.4:hello'])
        self.assertRaises(
            UsageError, options.parseOptions,
            ['--secondary', '1.2.3.4:hello/example.com']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_tap.py

示例8: makeService

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def makeService(config):
    if not len(config.groups):
        raise usage.UsageError("No newsgroups specified")
    
    db = database.NewsShelf(config['mailhost'], config['datadir'])
    for (g, m) in config.groups:
        if m:
            db.addGroup(g, 'm')
            db.addModerator(g, m)
        else:
            db.addGroup(g, 'y')
    for s in config.subscriptions:
        print(s)
        db.addSubscription(s)
    s = config['port']
    if config['interface']:
        # Add a warning here
        s += ':interface='+config['interface']
    return strports.service(s, news.UsenetServerFactory(db, config.servers)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:tap.py

示例9: run

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def run():
#    import hotshot
#    prof = hotshot.Profile('cftp.prof')
#    prof.start()
    args = sys.argv[1:]
    if '-l' in args: # cvs is an idiot
        i = args.index('-l')
        args = args[i:i+2]+args
        del args[i+2:i+4]
    options = ClientOptions()
    try:
        options.parseOptions(args)
    except usage.UsageError as u:
        print('ERROR: %s' % u)
        sys.exit(1)
    if options['log']:
        realout = sys.stdout
        log.startLogging(sys.stderr)
        sys.stdout = realout
    else:
        log.discardLogs()
    doConnect(options)
    reactor.run()
#    prof.stop()
#    prof.close() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:cftp.py

示例10: test_reactorSelectionMixinNonExistent

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def test_reactorSelectionMixinNonExistent(self):
        """
        Test that the usage mixin exits when trying to use a non existent
        reactor (the name not matching to any reactor), giving an error
        message.
        """
        class ReactorSelectionOptions(usage.Options, app.ReactorSelectionMixin):
            pass
        self.pluginResults = []

        options = ReactorSelectionOptions()
        options.messageOutput = NativeStringIO()
        e = self.assertRaises(usage.UsageError, options.parseOptions,
                              ['--reactor', 'fakereactortest', 'subcommand'])
        self.assertIn("fakereactortest", e.args[0])
        self.assertIn("help-reactors", e.args[0]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_application.py

示例11: test_reactorSelectionMixinNotAvailable

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def test_reactorSelectionMixinNotAvailable(self):
        """
        Test that the usage mixin exits when trying to use a reactor not
        available (the reactor raises an error at installation), giving an
        error message.
        """
        class ReactorSelectionOptions(usage.Options, app.ReactorSelectionMixin):
            pass
        message = "Missing foo bar"
        def install():
            raise ImportError(message)

        name = 'fakereactortest'
        package = __name__
        description = 'description'
        self.pluginResults = [FakeReactor(install, name, package, description)]

        options = ReactorSelectionOptions()
        options.messageOutput = NativeStringIO()
        e =  self.assertRaises(usage.UsageError, options.parseOptions,
                               ['--reactor', 'fakereactortest', 'subcommand'])
        self.assertIn(message, e.args[0])
        self.assertIn("help-reactors", e.args[0]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_application.py

示例12: run

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def run():
    options = Options()
    try:
        options.parseOptions()
    except usage.UsageError as e:
        print(str(e))
        sys.exit(1)
    filename = options['filename']
    if options.get('stylesheet') is not None:
        stylesheet = styleLink % (options['stylesheet'],)
    else:
        stylesheet = ''

    with open(filename + '.html', 'wb') as output:
        outHeader = (header % {
            'title': filename,
            'generator': 'htmlizer/%s' % (copyright.longversion,),
            'alternate': alternateLink % {'source': filename},
            'stylesheet': stylesheet
            })
        output.write(outHeader.encode("utf-8"))
        with open(filename, 'rb') as f:
            htmlizer.filter(f, output, htmlizer.SmallerHTMLWriter)
        output.write(footer.encode("utf-8")) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:htmlizer.py

示例13: _checkKnownRunOrder

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def _checkKnownRunOrder(order):
    """
    Check that the given order is a known test running order.

    Does nothing else, since looking up the appropriate callable to sort the
    tests should be done when it actually will be used, as the default argument
    will not be coerced by this function.

    @param order: one of the known orders in C{_runOrders}
    @return: the order unmodified
    """
    if order not in _runOrders:
        raise usage.UsageError(
            "--order must be one of: %s. See --help-orders for details" %
            (", ".join(repr(order) for order in _runOrders),))
    return order 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:trial.py

示例14: main

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def main(reactor, argv, environ):
    # Setup eliot to print better human-readable output to standard
    # output
    eliot_to_stdout(MESSAGE_FORMATS, ACTION_START_FORMATS)

    options = ContainerOptions()
    try:
        options.parseOptions(argv[1:])
    except usage.UsageError as e:
        sys.stderr.write(e.args[0])
        sys.stderr.write('\n\n')
        sys.stderr.write(options.getSynopsis())
        sys.stderr.write('\n')
        sys.stderr.write(options.getUsage())
        raise SystemExit(1)

    container_deployment = ClusterContainerDeployment.from_options(reactor,
                                                                   options)

    return container_deployment.deploy(options['apps-per-node']) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:cluster_containers_setup.py

示例15: initialize_release_main

# 需要导入模块: from twisted.python import usage [as 别名]
# 或者: from twisted.python.usage import UsageError [as 别名]
def initialize_release_main(args, base_path, top_level):
    """
    Clone the Flocker repo and install a new virtual environment for
    a release.

    :param list args: The arguments passed to the script.
    :param FilePath base_path: The executable being run.
    :param FilePath top_level: The top-level of the flocker repository.
    """
    options = InitializeReleaseOptions()

    try:
        options.parseOptions(args)
    except UsageError as e:
        sys.stderr.write("%s: %s\n" % (base_path.basename(), e))
        raise SystemExit(1)

    version = options['flocker-version']
    path = options['path']
    initialize_release(version, path, top_level) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:release.py


注:本文中的twisted.python.usage.UsageError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。