Browse Source

Debug: refactor debugging into its own module

teor 5 years ago
parent
commit
05d50aa45c
3 changed files with 29 additions and 9 deletions
  1. 26 0
      lib/chutney/Debug.py
  2. 2 0
      lib/chutney/TorNet.py
  3. 1 9
      lib/chutney/Traffic.py

+ 26 - 0
lib/chutney/Debug.py

@@ -0,0 +1,26 @@
+#!/usr/bin/env python2
+#
+# Copyright 2011 Nick Mathewson, Michael Stone
+# Copyright 2013 The Tor Project
+#
+#  You may do anything with this work that copyright law would normally
+#  restrict, so long as you retain the above notice(s) and this license
+#  in all redistributed copies and derived works.  There is no warranty.
+
+from __future__ import print_function
+
+import cgitb
+import os
+
+# Get verbose tracebacks, so we can diagnose better.
+cgitb.enable(format="plain")
+
+
+# Set debug_flag=True in order to debug this program or to get hints
+# about what's going wrong in your system.
+debug_flag = os.environ.get("CHUTNEY_DEBUG", "") != ""
+
+def debug(s):
+    "Print a debug message on stdout if debug_flag is True."
+    if debug_flag:
+        print("DEBUG: %s" % s)

+ 2 - 0
lib/chutney/TorNet.py

@@ -21,6 +21,8 @@ import time
 import shutil
 import importlib
 
+from chutney.Debug import debug_flag, debug
+
 import chutney.Templating
 import chutney.Traffic
 

+ 1 - 9
lib/chutney/Traffic.py

@@ -30,15 +30,7 @@ import errno
 import time
 import os
 
-# Set debug_flag=True in order to debug this program or to get hints
-# about what's going wrong in your system.
-debug_flag = os.environ.get("CHUTNEY_DEBUG", "") != ""
-
-def debug(s):
-    "Print a debug message on stdout if debug_flag is True."
-    if debug_flag:
-        print("DEBUG: %s" % s)
-
+from chutney.Debug import debug_flag, debug
 
 def socks_cmd(addr_port):
     """