runner.py: spoke too soon. Really fix #51 this time.

This commit is contained in:
Brian Warner 2007-05-24 11:20:39 -07:00
parent d0db98cc40
commit 4c7c5df41e
1 changed files with 14 additions and 16 deletions

View File

@ -41,23 +41,29 @@ if not twistd:
if not twistd: if not twistd:
print "Can't find twistd (it comes with Twisted). Aborting." print "Can't find twistd (it comes with Twisted). Aborting."
sys.exit(1) sys.exit(1)
class StartOptions(usage.Options): class BasedirMixin:
def postOptions(self):
if self['basedir'] is None:
raise usage.UsageError("<basedir> parameter is required")
self['basedir'] = os.path.abspath(os.path.expanduser(self['basedir']))
class StartOptions(BasedirMixin, usage.Options):
optParameters = [ optParameters = [
["basedir", "C", ".", "which directory to start the node in"], ["basedir", "C", ".", "which directory to start the node in"],
] ]
class StopOptions(usage.Options): class StopOptions(BasedirMixin, usage.Options):
optParameters = [ optParameters = [
["basedir", "C", ".", "which directory to stop the node in"], ["basedir", "C", ".", "which directory to stop the node in"],
] ]
class RestartOptions(usage.Options): class RestartOptions(BasedirMixin, usage.Options):
optParameters = [ optParameters = [
["basedir", "C", ".", "which directory to restart the node in"], ["basedir", "C", ".", "which directory to restart the node in"],
] ]
class CreateClientOptions(usage.Options): class CreateClientOptions(BasedirMixin, usage.Options):
optParameters = [ optParameters = [
["basedir", "C", None, "which directory to create the client in"], ["basedir", "C", None, "which directory to create the client in"],
] ]
@ -71,12 +77,7 @@ class CreateClientOptions(usage.Options):
if len(args) > 1: if len(args) > 1:
raise usage.UsageError("I wasn't expecting so many arguments") raise usage.UsageError("I wasn't expecting so many arguments")
def postOptions(self): class CreateIntroducerOptions(BasedirMixin, usage.Options):
if self['basedir'] is None:
raise usage.UsageError("<basedir> parameter is required")
self['basedir'] = os.path.abspath(os.path.expanduser(self['basedir']))
class CreateIntroducerOptions(usage.Options):
optParameters = [ optParameters = [
["basedir", "C", None, "which directory to create the introducer in"], ["basedir", "C", None, "which directory to create the introducer in"],
] ]
@ -90,11 +91,6 @@ class CreateIntroducerOptions(usage.Options):
if len(args) > 1: if len(args) > 1:
raise usage.UsageError("I wasn't expecting so many arguments") raise usage.UsageError("I wasn't expecting so many arguments")
def postOptions(self):
if self['basedir'] is None:
raise usage.UsageError("<basedir> parameter is required")
self['basedir'] = os.path.abspath(self['basedir'])
client_tac = """ client_tac = """
# -*- python -*- # -*- python -*-
@ -212,6 +208,8 @@ def start(config):
type = "introducer" type = "introducer"
else: else:
print "%s does not look like a node directory" % basedir print "%s does not look like a node directory" % basedir
if not os.path.isdir(basedir):
print " in fact, it doesn't look like a directory at all!"
sys.exit(1) sys.exit(1)
os.chdir(basedir) os.chdir(basedir)
rc = subprocess.call(["python", twistd, "-y", tac,]) rc = subprocess.call(["python", twistd, "-y", tac,])