Use the argument handler specified by twistd, if any.
This commit is contained in:
@@ -141,6 +141,7 @@ def _wrapper(func):
|
|||||||
return _wrapped
|
return _wrapped
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE = _wrapper(gflags.DEFINE)
|
||||||
DEFINE_string = _wrapper(gflags.DEFINE_string)
|
DEFINE_string = _wrapper(gflags.DEFINE_string)
|
||||||
DEFINE_integer = _wrapper(gflags.DEFINE_integer)
|
DEFINE_integer = _wrapper(gflags.DEFINE_integer)
|
||||||
DEFINE_bool = _wrapper(gflags.DEFINE_bool)
|
DEFINE_bool = _wrapper(gflags.DEFINE_bool)
|
||||||
@@ -152,6 +153,8 @@ DEFINE_spaceseplist = _wrapper(gflags.DEFINE_spaceseplist)
|
|||||||
DEFINE_multistring = _wrapper(gflags.DEFINE_multistring)
|
DEFINE_multistring = _wrapper(gflags.DEFINE_multistring)
|
||||||
DEFINE_multi_int = _wrapper(gflags.DEFINE_multi_int)
|
DEFINE_multi_int = _wrapper(gflags.DEFINE_multi_int)
|
||||||
|
|
||||||
|
ArgumentSerializer = gflags.ArgumentSerializer
|
||||||
|
|
||||||
|
|
||||||
def DECLARE(name, module_string, flag_values=FLAGS):
|
def DECLARE(name, module_string, flag_values=FLAGS):
|
||||||
if module_string not in sys.modules:
|
if module_string not in sys.modules:
|
||||||
|
@@ -44,6 +44,8 @@ flags.DEFINE_bool('use_syslog', True, 'output to syslog when daemonizing')
|
|||||||
flags.DEFINE_string('logfile', None, 'log file to output to')
|
flags.DEFINE_string('logfile', None, 'log file to output to')
|
||||||
flags.DEFINE_string('pidfile', None, 'pid file to output to')
|
flags.DEFINE_string('pidfile', None, 'pid file to output to')
|
||||||
flags.DEFINE_string('working_directory', './', 'working directory...')
|
flags.DEFINE_string('working_directory', './', 'working directory...')
|
||||||
|
flags.DEFINE_integer('uid', os.getuid(), 'uid under which to run')
|
||||||
|
flags.DEFINE_integer('gid', os.getgid(), 'gid under which to run')
|
||||||
|
|
||||||
|
|
||||||
def stop(pidfile):
|
def stop(pidfile):
|
||||||
@@ -135,6 +137,8 @@ def daemonize(args, name, main):
|
|||||||
threaded=False),
|
threaded=False),
|
||||||
stdin=stdin,
|
stdin=stdin,
|
||||||
stdout=stdout,
|
stdout=stdout,
|
||||||
stderr=stderr
|
stderr=stderr,
|
||||||
|
uid=FLAGS.uid,
|
||||||
|
gid=FLAGS.gid
|
||||||
):
|
):
|
||||||
main(args)
|
main(args)
|
||||||
|
@@ -48,6 +48,13 @@ class TwistdServerOptions(ServerOptions):
|
|||||||
def parseArgs(self, *args):
|
def parseArgs(self, *args):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
class FlagParser(object):
|
||||||
|
def __init__(self, parser):
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
|
def Parse(self, s):
|
||||||
|
return self.parser(s)
|
||||||
|
|
||||||
|
|
||||||
def WrapTwistedOptions(wrapped):
|
def WrapTwistedOptions(wrapped):
|
||||||
class TwistedOptionsToFlags(wrapped):
|
class TwistedOptionsToFlags(wrapped):
|
||||||
@@ -79,7 +86,10 @@ def WrapTwistedOptions(wrapped):
|
|||||||
reflect.accumulateClassList(self.__class__, 'optParameters', twistd_params)
|
reflect.accumulateClassList(self.__class__, 'optParameters', twistd_params)
|
||||||
for param in twistd_params:
|
for param in twistd_params:
|
||||||
key = param[0].replace('-', '_')
|
key = param[0].replace('-', '_')
|
||||||
flags.DEFINE_string(key, param[2], str(param[-1]))
|
if len(param) > 4:
|
||||||
|
flags.DEFINE(FlagParser(param[4]), key, param[2], str(param[3]), serializer=flags.ArgumentSerializer())
|
||||||
|
else:
|
||||||
|
flags.DEFINE_string(key, param[2], str(param[3]))
|
||||||
|
|
||||||
def _absorbHandlers(self):
|
def _absorbHandlers(self):
|
||||||
twistd_handlers = {}
|
twistd_handlers = {}
|
||||||
|
Reference in New Issue
Block a user