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

[tor-commits] [bridgedb/master] Add docstring and use loadConfig() in reload().



commit 4607e64ad63584343eb9fbcbf4048a7a9b3a6c8e
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Tue Nov 5 08:18:32 2013 +0000

    Add docstring and use loadConfig() in reload().
---
 lib/bridgedb/Main.py |   52 ++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 12 deletions(-)

diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
index 1480c10..750ad1e 100644
--- a/lib/bridgedb/Main.py
+++ b/lib/bridgedb/Main.py
@@ -346,19 +346,47 @@ def startup(cfg, options):
     for p in cfg.FILE_BUCKETS.keys():
         splitter.addPseudoRing(p)
 
-    # Make the parse-bridges function get re-called on SIGHUP.
     def reload(*args):
-        logging.info("Caught SIGHUP")
-
-        # reparse the config file
-        configuration = {}
-        if options['config']:
-            execfile(options['config'], configuration)
-            cfg = Conf(**configuration)
-            # update loglevel on (re)load
-            level = getattr(cfg, 'LOGLEVEL', 'WARNING')
-            level = getattr(logging, level)
-            logging.getLogger().setLevel(level)
+        """Reload settings, proxy lists, and bridges.
+
+        The contents of the config file should be compiled (it's roughly 20-30
+        times faster to use the ``compile`` builtin on a string before
+        ``exec``ing it) first, and then ``exec``ed -- not ``execfile``! -- in
+        order to get the contents of the config file to exist within the scope
+        of the configuration object. Otherwise, Python *will* default to
+        placing them directly within the ``globals()`` scope.
+
+        For a more detailed explanation, see http://stackoverflow.com/q/17470193
+        and http://lucumr.pocoo.org/2011/2/1/exec-in-python/
+
+        :type cfg: :class:`Conf`
+        :param cfg: The current configuration, including any in-memory
+            settings (i.e. settings whose values were not obtained from the
+            config file, but were set via a function somewhere)
+        :type options: :class:`twisted.python.usage.Options`
+        :param options: Any commandline options.
+
+        :param splitter: XXX
+
+        :type proxyList: :class:`ProxyCategory`
+        :param proxyList: The container for the IP addresses of any currently
+             known open proxies.
+
+        :param IPDistributor: A :class:`Dist.IPBasedDistributor`.
+        :param emailDistributor: A :class:`Dist.EmailDistributor`.
+        :param dict tasks: A dictionary of {'name': Task}, where Task is some
+            scheduled event, repetitive or otherwise, for the :class:`reactor
+            <twisted.internet.epollreactor.EPollReactor>`
+        """
+        logging.debug("Caught SIGHUP")
+        logging.info("Reloading...")
+
+        cfg = loadConfig(options, cfg)
+
+        # update loglevel on (re)load
+        level = getattr(cfg, 'LOGLEVEL', 'WARNING')
+        level = getattr(logging, level)
+        logging.getLogger().setLevel(level)
 
         load(cfg, splitter, clear=True)
         proxyList.replaceProxyList(loadProxyList(cfg))



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