def handle_noargs(self, **options): self.check_home_dir(settings.HOME_PATH) cmd = "twistd " if not options.get('daemonize', False): cmd += "-n " cmd += "codenode " cmd += "--env_path=%s " % settings.HOME_PATH cmd += "--server_log=%s " % os.path.join(settings.HOME_PATH, 'server.log') cmd += "--static_files=%s " % settings.MEDIA_ROOT run(cmd.split()[1:])
def run_twistd(): # This is a (somewhat awful hack) based on twistd. # Twistd plugins have great difficulty being packaged # by distutils, pip, etc., and there is no # current workaround. # This function basically recreates twistd, # and inserts the EMEN2 Service as the only plugin. # This gets around having to have twisted/plugins/emen2_plugin.py # in a directory without an __init__.py # Run: # python -m emen2.tap [twistd options] emen2 [emen2 options] from twisted.application.service import ServiceMaker from twisted.application import app from twisted.python.runtime import platformType from twisted import plugin #### From twisted/plugins/emen2_plugin.py ##### EMEN2Server = ServiceMaker("EMEN2", "emen2.tap", ("EMEN2 server"), "emen2") #### Copied from twisted/scripts/twistd.py ##### if platformType == "win32": from twisted.scripts._twistw import ServerOptions, \ WindowsApplicationRunner as _SomeApplicationRunner else: from twisted.scripts._twistd_unix import ServerOptions, \ UnixApplicationRunner as _SomeApplicationRunner #Create an altered ServerOptions that only runs EMEN2. class TestOptions(ServerOptions): def _getPlugins(self, interface, package=None): f = plugin.getPlugins(interface, package=None) return list(f) + [EMEN2Server] def runApp(config): _SomeApplicationRunner(config).run() app.run(runApp, TestOptions)
def main(args): if args.nodaemon: sys.argv = ['', '-ny', TAC_FILE, '--umask=022'] else: sys.argv = ['', '-y', TAC_FILE, '--umask=022'] if args.pidfile: sys.argv.append(f'--pidfile={args.pidfile}') if args.logfile: sys.argv.append(f'--logfile={args.logfile}') from twisted.application import app from twisted.scripts._twistd_unix import ServerOptions, UnixApplicationRunner def runApp(config): runner = UnixApplicationRunner(config) runner.run() if runner._exitSignal is not None: app._exitWithSignal(runner._exitSignal) app.run(runApp, ServerOptions)
def run_script (_f) : _found = False _n = list() _n.append(sys.argv[0], ) for i in sys.argv[1:] : if _found : _found = False continue elif i in ServerOptions.unused_short : _found = True continue elif filter(i.startswith, ServerOptions.unused_long, ) : continue _n.append(i, ) _n.extend(["-y", _f, ], ) sys.argv = _n from twisted.application import app from twisted.scripts.twistd import runApp app.run(runApp , ServerOptions, )
def run(): app.run(runApp, ServerOptions)
def run(): from twisted.application import app app.run(runApp, GettextOptions)
#!/usr/bin/env python #------------------------------------------------------------------------------- # Author: Lukasz Janyst <*****@*****.**> # Date: 26.11.2017 # # Licensed under the 3-Clause BSD License, see the LICENSE file for details. #------------------------------------------------------------------------------- from twisted.scripts.twistd import _SomeApplicationRunner, ServerOptions from twisted.application import app from scrapy_do.app import ScrapyDoServiceMaker class ScrapyDoRunnerOptions(ServerOptions): @property def subCommands(self): sm = ScrapyDoServiceMaker() self.loadedPlugins = {sm.tapname: sm} yield (sm.tapname, None, sm.options, sm.description) def run_app(config): _SomeApplicationRunner(config).run() app.run(run_app, ScrapyDoRunnerOptions)
def run(): app.run(runApp, Options)
def run(): """ Replace twisted.application.app.run() To use our ServerOptions. """ app.run(runApp, MyServerOptions)
_n.append(sys.argv[0], ) for i in sys.argv[1:] : if _found : _found = False continue elif i in Options.unused_short : _found = True continue elif filter(i.startswith, Options.unused_long, ) : continue _n.append(i, ) _n.extend(["-y", __file__, ], ) sys.argv = _n from twisted.application import app from twisted.scripts.twistd import runApp app.run(runApp , Options, ) if __name__ == "__main__" : import doctest doctest.testmod()
def run(): _monkey_patch_twistd_loggers() app.run(runApp, ServerOptions)