aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Stone <michael@laptop.org>2011-03-06 17:27:50 -0500
committerMichael Stone <michael@laptop.org>2011-03-06 17:27:50 -0500
commitebd05483b8073ac1eef16f3e2308faa958491336 (patch)
treefd4645319e44c0a821b0d1f5a8c07f9608c6c11e /lib
parent6a47e4488686d37db0ce607ac3d7fce1b35a60d8 (diff)
downloadchutney-ebd05483b8073ac1eef16f3e2308faa958491336.tar
chutney-ebd05483b8073ac1eef16f3e2308faa958491336.tar.gz
Give slightly better usage information.
Diffstat (limited to 'lib')
-rw-r--r--lib/chutney/TorNet.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index 5997bb4..d234fbc 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -387,12 +387,12 @@ def ConfigureNodes(nodelist):
for n in nodelist:
network._addNode(n)
-def runConfigFile(verb, f):
- global _BASE_ENVIRON
- global _THE_NETWORK
- _BASE_ENVIRON = TorEnviron(chutney.Templating.Environ(**DEFAULTS))
- _THE_NETWORK = Network(_BASE_ENVIRON)
+def usage(network):
+ return "\n".join(["Usage: chutney {command} {networkfile}",
+ "Known commands are: %s" % (
+ " ".join(x for x in dir(network) if not x.startswith("_")))])
+def runConfigFile(verb, f):
_GLOBALS = dict(_BASE_ENVIRON= _BASE_ENVIRON,
Node=Node,
ConfigureNodes=ConfigureNodes,
@@ -402,18 +402,25 @@ def runConfigFile(verb, f):
network = _GLOBALS['_THE_NETWORK']
if not hasattr(network, verb):
- print "I don't know how to %s. Known commands are: %s" % (
- verb, " ".join(x for x in dir(network) if not x.startswith("_")))
+ print usage(network)
+ print "Error: I don't know how to %s." % verb
return
getattr(network,verb)()
-if __name__ == '__main__':
+def main():
+ global _BASE_ENVIRON
+ global _THE_NETWORK
+ _BASE_ENVIRON = TorEnviron(chutney.Templating.Environ(**DEFAULTS))
+ _THE_NETWORK = Network(_BASE_ENVIRON)
+
if len(sys.argv) < 3:
- print "Syntax: chutney {command} {networkfile}"
+ print usage(_THE_NETWORK)
+ print "Error: Not enough arguments given."
sys.exit(1)
f = open(sys.argv[2])
runConfigFile(sys.argv[1], f)
-
+if __name__ == '__main__':
+ main()