[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [chutney/master] Merge remote-tracking branch 'houqp/miss_network_error'



commit d91cf28d17c31ba57d94fe8a9acaecff287473a0
Merge: f5f6773 489bc2b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Oct 9 10:49:02 2014 -0400

    Merge remote-tracking branch 'houqp/miss_network_error'

 lib/chutney/TorNet.py |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --cc lib/chutney/TorNet.py
index f18503a,042610c..7e64035
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@@ -859,15 -712,18 +859,20 @@@ def ConfigureNodes(nodelist)
          if n._env['bridgeauthority']:
              network._dfltEnv['hasbridgeauth'] = True
  
 +
  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("_")))])
 +                      "Known commands are: %s" % (
 +                          " ".join(x for x in dir(network) if not x.startswith("_")))])
 +
  
+ def exit_on_error(err_msg):
+     print "Error: {0}\n".format(err_msg)
+     print usage(_THE_NETWORK)
+     sys.exit(1)
+ 
  def runConfigFile(verb, f):
 -    _GLOBALS = dict(_BASE_ENVIRON= _BASE_ENVIRON,
 +    _GLOBALS = dict(_BASE_ENVIRON=_BASE_ENVIRON,
                      Node=Node,
                      ConfigureNodes=ConfigureNodes,
                      _THE_NETWORK=_THE_NETWORK)
@@@ -880,27 -736,24 +885,30 @@@
          print "Error: I don't know how to %s." % verb
          return
  
 -    return getattr(network,verb)()
 +    return getattr(network, verb)()
 +
  
+ def parseArgs():
+     if len(sys.argv) < 3:
+         exit_on_error("Not enough arguments given.")
+     if not os.path.isfile(sys.argv[2]):
+         exit_on_error("Cannot find networkfile: {0}.".format(sys.argv[2]))
+     return {'network_cfg': sys.argv[2], 'action': sys.argv[1]}
+ 
  def main():
      global _BASE_ENVIRON
 +    global _TORRC_OPTIONS
      global _THE_NETWORK
      _BASE_ENVIRON = TorEnviron(chutney.Templating.Environ(**DEFAULTS))
 +    # _TORRC_OPTIONS gets initialised on demand as a map of
 +    # "/path/to/tor" => ["SupportedOption1", "SupportedOption2", ...]
 +    # Or it can be pre-populated as a static whitelist of options
 +    _TORRC_OPTIONS = dict()
      _THE_NETWORK = Network(_BASE_ENVIRON)
  
-     if len(sys.argv) < 3:
-         print usage(_THE_NETWORK)
-         print "Error: Not enough arguments given."
-         sys.exit(1)
- 
-     f = open(sys.argv[2])
-     result = runConfigFile(sys.argv[1], f)
+     args = parseArgs()
+     f = open(args['network_cfg'])
+     result = runConfigFile(args['action'], f)
      if result is False:
          return -1
      return 0

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits