Python twisted.python.usage.error() Examples

The following are 26 code examples of twisted.python.usage.error(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.python.usage , or try the search function .
Example #1
Source File: app.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #2
Source File: server.py    From maas with GNU Affero General Public License v3.0 6 votes vote down vote up
def runService(service):
    """Run the `service`."""
    config = Options()
    args = [
        "--logger=provisioningserver.logger.EventLogger",
        "--nodaemon",
        "--pidfile=",
    ]
    args += sys.argv[1:]
    args += [service]
    try:
        config.parseOptions(args)
    except usage.error as exc:
        print(config)
        print("%s: %s" % (sys.argv[0], exc))
    else:
        UnixApplicationRunner(config).run() 
Example #3
Source File: app.py    From learn_python3_spider with MIT License 6 votes vote down vote up
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 
Example #4
Source File: app.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
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, 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) 
Example #5
Source File: app.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def run(runApp, ServerOptions):
    config = ServerOptions()
    try:
        config.parseOptions()
    except usage.error, ue:
        print config
        print "%s: %s" % (sys.argv[0], ue) 
Example #6
Source File: bk_buildbot.py    From buildbot-contrib with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
        opts = Options()
        try:
            opts.parseOptions()
            if not opts['branch']:
                print("You must supply a branch with -b or --branch.")
                sys.exit(1)

        except usage.error as ue:
            print(opts)
            print("%s: %s" % (sys.argv[0], ue))
            sys.exit()

        changes = self.getChanges(opts)
        if opts['dryrun']:
            for k in changes.keys():
                print("[%10s]: %s" % (k, changes[k]))
            print("*NOT* sending any changes")
            return

        d = self.sendChanges(opts, changes)

        def quit(*why):
            print("quitting! because", why)
            reactor.stop()

        @d.addErrback(failed)
        def failed(f):
            print("FAILURE: %s" % f)
            reactor.stop()

        d.addCallback(quit, "SUCCESS")
        reactor.callLater(60, quit, "TIMEOUT")

        reactor.run() 
Example #7
Source File: bk_buildbot.py    From buildbot-contrib with GNU General Public License v2.0 5 votes vote down vote up
def postOptions(self):
        if self['repository'] is None:
            raise usage.error("You must pass --repository") 
Example #8
Source File: svn_buildbot.py    From buildbot-contrib with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
        opts = Options()
        try:
            opts.parseOptions()
        except usage.error as ue:
            print(opts)
            print("%s: %s" % (sys.argv[0], ue))
            sys.exit()

        changes = self.getChanges(opts)
        if opts['dryrun']:
            for i, c in enumerate(changes):
                print("CHANGE #%d" % (i + 1))
                keys = sorted(c.keys())
                for k in keys:
                    print("[%10s]: %s" % (k, c[k]))
            print("*NOT* sending any changes")
            return

        d = self.sendChanges(opts, changes)

        def quit(*why):
            print("quitting! because", why)
            reactor.stop()

        d.addCallback(quit, "SUCCESS")

        @d.addErrback
        def failed(f):
            print("FAILURE")
            print(f)
            reactor.stop()

        reactor.callLater(60, quit, "TIMEOUT")
        reactor.run() 
Example #9
Source File: svn_buildbot.py    From buildbot-contrib with GNU General Public License v2.0 5 votes vote down vote up
def postOptions(self):
        if self['repository'] is None:
            raise usage.error("You must pass --repository")
        if self._includes:
            self['includes'] = '(%s)' % ('|'.join(self._includes), )
        if self._excludes:
            self['excludes'] = '(%s)' % ('|'.join(self._excludes), ) 
Example #10
Source File: trial.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def run():
    if len(sys.argv) == 1:
        sys.argv.append("--help")
    config = Options()
    try:
        config.parseOptions()
    except usage.error, ue:
        raise SystemExit, "%s: %s" % (sys.argv[0], ue) 
Example #11
Source File: trial.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def _supportsColor(self):
        # assuming stderr
        import sys
        if not sys.stderr.isatty():
            return False # auto color only on TTYs
        try:
            import curses
            curses.setupterm()
            return curses.tigetnum("colors") > 2
        except:
            # guess false in case of error
            return False 
Example #12
Source File: tap2deb.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def run():

    try:
        config = MyOptions()
        config.parseOptions()
    except usage.error, ue:
        sys.exit("%s: %s" % (sys.argv[0], ue)) 
Example #13
Source File: tap2rpm.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def run():
    #  parse options
    try:
        config = MyOptions()
        config.parseOptions()
    except usage.error, ue:
         sys.exit("%s: %s" % (sys.argv[0], ue))

    #  set up some useful local variables 
Example #14
Source File: app.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def run(runApp, ServerOptions):
    config = ServerOptions()
    try:
        config.parseOptions()
    except usage.error, ue:
        print config
        print "%s: %s" % (sys.argv[0], ue) 
Example #15
Source File: trial.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def run():
    if len(sys.argv) == 1:
        sys.argv.append("--help")
    config = Options()
    try:
        config.parseOptions()
    except usage.error, ue:
        raise SystemExit, "%s: %s" % (sys.argv[0], ue) 
Example #16
Source File: tap2rpm.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def run(options=None):
    #  parse options
    try:
        config = MyOptions()
        config.parseOptions(options)
    except usage.error, ue:
         sys.exit("%s: %s" % (sys.argv[0], ue))

    #  create RPM build environment 
Example #17
Source File: app.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def _reportImportError(self, module, e):
        """
        Helper method to report an import error with a profile module. This
        has to be explicit because some of these modules are removed by
        distributions due to them being non-free.
        """
        s = "Failed to import module %s: %s" % (module, e)
        s += """
This is most likely caused by your operating system not including
the module due to it being non-free. Either do not use the option
--profile, or install the module; your operating system vendor
may provide it in a separate package.
"""
        raise SystemExit(s) 
Example #18
Source File: app.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def _reportImportError(self, module, e):
        """
        Helper method to report an import error with a profile module. This
        has to be explicit because some of these modules are removed by
        distributions due to them being non-free.
        """
        s = "Failed to import module %s: %s" % (module, e)
        s += """
This is most likely caused by your operating system not including
the module due to it being non-free. Either do not use the option
--profile, or install the module; your operating system vendor
may provide it in a separate package.
"""
        raise SystemExit(s) 
Example #19
Source File: trial.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def run():
    if len(sys.argv) == 1:
        sys.argv.append("--help")
    config = Options()
    try:
        config.parseOptions()
    except usage.error as ue:
        raise SystemExit("%s: %s" % (sys.argv[0], ue))
    _initialDebugSetup(config)

    try:
        trialRunner = _makeRunner(config)
    except _DebuggerNotFound as e:
        raise SystemExit('%s: %s' % (sys.argv[0], str(e)))

    suite = _getSuite(config)
    if config['until-failure']:
        test_result = trialRunner.runUntilFailure(suite)
    else:
        test_result = trialRunner.run(suite)
    if config.tracer:
        sys.settrace(None)
        results = config.tracer.results()
        results.write_results(show_missing=1, summary=False,
                              coverdir=config.coverdir().path)
    sys.exit(not test_result.wasSuccessful()) 
Example #20
Source File: app.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def run(runApp, ServerOptions):
    config = ServerOptions()
    try:
        config.parseOptions()
    except usage.error as ue:
        print(config)
        print("%s: %s" % (sys.argv[0], ue))
    else:
        runApp(config) 
Example #21
Source File: app.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def _reportImportError(self, module, e):
        """
        Helper method to report an import error with a profile module. This
        has to be explicit because some of these modules are removed by
        distributions due to them being non-free.
        """
        s = "Failed to import module %s: %s" % (module, e)
        s += """
This is most likely caused by your operating system not including
the module due to it being non-free. Either do not use the option
--profile, or install the module; your operating system vendor
may provide it in a separate package.
"""
        raise SystemExit(s) 
Example #22
Source File: trial.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def run():
    if len(sys.argv) == 1:
        sys.argv.append("--help")
    config = Options()
    try:
        config.parseOptions()
    except usage.error as ue:
        raise SystemExit("%s: %s" % (sys.argv[0], ue))
    _initialDebugSetup(config)

    try:
        trialRunner = _makeRunner(config)
    except _DebuggerNotFound as e:
        raise SystemExit('%s: %s' % (sys.argv[0], str(e)))

    suite = _getSuite(config)
    if config['until-failure']:
        test_result = trialRunner.runUntilFailure(suite)
    else:
        test_result = trialRunner.run(suite)
    if config.tracer:
        sys.settrace(None)
        results = config.tracer.results()
        results.write_results(show_missing=1, summary=False,
                              coverdir=config.coverdir().path)
    sys.exit(not test_result.wasSuccessful()) 
Example #23
Source File: app.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def run(runApp, ServerOptions):
    config = ServerOptions()
    try:
        config.parseOptions()
    except usage.error as ue:
        print(config)
        print("%s: %s" % (sys.argv[0], ue))
    else:
        runApp(config) 
Example #24
Source File: app.py    From python-for-android with Apache License 2.0 4 votes vote down vote up
def runReactorWithLogging(config, oldstdout, oldstderr, profiler=None, reactor=None):
    """
    Start the reactor, using profiling if specified by the configuration, and
    log any error happening in the process.

    @param config: configuration of the twistd application.
    @type config: L{ServerOptions}

    @param oldstdout: initial value of C{sys.stdout}.
    @type oldstdout: C{file}

    @param oldstderr: initial value of C{sys.stderr}.
    @type oldstderr: C{file}

    @param profiler: object used to run the reactor with profiling.
    @type profiler: L{AppProfiler}

    @param reactor: The reactor to use.  If C{None}, the global reactor will
        be used.
    """
    if reactor is None:
        from twisted.internet import reactor
    try:
        if config['profile']:
            if profiler is not None:
                profiler.run(reactor)
        elif config['debug']:
            sys.stdout = oldstdout
            sys.stderr = oldstderr
            if runtime.platformType == 'posix':
                signal.signal(signal.SIGUSR2, lambda *args: pdb.set_trace())
                signal.signal(signal.SIGINT, lambda *args: pdb.set_trace())
            fixPdb()
            pdb.runcall(reactor.run)
        else:
            reactor.run()
    except:
        if config['nodaemon']:
            file = oldstdout
        else:
            file = open("TWISTD-CRASH.log",'a')
        traceback.print_exc(file=file)
        file.flush() 
Example #25
Source File: app.py    From learn_python3_spider with MIT License 4 votes vote down vote up
def runReactorWithLogging(config, oldstdout, oldstderr, profiler=None,
                          reactor=None):
    """
    Start the reactor, using profiling if specified by the configuration, and
    log any error happening in the process.

    @param config: configuration of the twistd application.
    @type config: L{ServerOptions}

    @param oldstdout: initial value of C{sys.stdout}.
    @type oldstdout: C{file}

    @param oldstderr: initial value of C{sys.stderr}.
    @type oldstderr: C{file}

    @param profiler: object used to run the reactor with profiling.
    @type profiler: L{AppProfiler}

    @param reactor: The reactor to use.  If L{None}, the global reactor will
        be used.
    """
    if reactor is None:
        from twisted.internet import reactor
    try:
        if config['profile']:
            if profiler is not None:
                profiler.run(reactor)
        elif config['debug']:
            sys.stdout = oldstdout
            sys.stderr = oldstderr
            if runtime.platformType == 'posix':
                signal.signal(signal.SIGUSR2, lambda *args: pdb.set_trace())
                signal.signal(signal.SIGINT, lambda *args: pdb.set_trace())
            fixPdb()
            pdb.runcall(reactor.run)
        else:
            reactor.run()
    except:
        close = False
        if config['nodaemon']:
            file = oldstdout
        else:
            file = open("TWISTD-CRASH.log", "a")
            close = True
        try:
            traceback.print_exc(file=file)
            file.flush()
        finally:
            if close:
                file.close() 
Example #26
Source File: app.py    From Safejumper-for-Desktop with GNU General Public License v2.0 4 votes vote down vote up
def runReactorWithLogging(config, oldstdout, oldstderr, profiler=None,
                          reactor=None):
    """
    Start the reactor, using profiling if specified by the configuration, and
    log any error happening in the process.

    @param config: configuration of the twistd application.
    @type config: L{ServerOptions}

    @param oldstdout: initial value of C{sys.stdout}.
    @type oldstdout: C{file}

    @param oldstderr: initial value of C{sys.stderr}.
    @type oldstderr: C{file}

    @param profiler: object used to run the reactor with profiling.
    @type profiler: L{AppProfiler}

    @param reactor: The reactor to use.  If L{None}, the global reactor will
        be used.
    """
    if reactor is None:
        from twisted.internet import reactor
    try:
        if config['profile']:
            if profiler is not None:
                profiler.run(reactor)
        elif config['debug']:
            sys.stdout = oldstdout
            sys.stderr = oldstderr
            if runtime.platformType == 'posix':
                signal.signal(signal.SIGUSR2, lambda *args: pdb.set_trace())
                signal.signal(signal.SIGINT, lambda *args: pdb.set_trace())
            fixPdb()
            pdb.runcall(reactor.run)
        else:
            reactor.run()
    except:
        close = False
        if config['nodaemon']:
            file = oldstdout
        else:
            file = open("TWISTD-CRASH.log", "a")
            close = True
        try:
            traceback.print_exc(file=file)
            file.flush()
        finally:
            if close:
                file.close()