[tor-commits] [chutney/master] Debug: refactor debugging into its own module

teor at torproject.org teor at torproject.org
Tue Oct 30 11:30:02 UTC 2018


commit 05d50aa45c1daacbd3b9ffa304d4d692a58f0b30
Author: teor <teor at torproject.org>
Date:   Tue Oct 23 13:28:56 2018 +1000

    Debug: refactor debugging into its own module
---
 lib/chutney/Debug.py   | 26 ++++++++++++++++++++++++++
 lib/chutney/TorNet.py  |  2 ++
 lib/chutney/Traffic.py | 10 +---------
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/lib/chutney/Debug.py b/lib/chutney/Debug.py
new file mode 100644
index 0000000..556ac5c
--- /dev/null
+++ b/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)
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index bf26978..1814d2e 100644
--- a/lib/chutney/TorNet.py
+++ b/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
 
diff --git a/lib/chutney/Traffic.py b/lib/chutney/Traffic.py
index cbeddd7..283f286 100644
--- a/lib/chutney/Traffic.py
+++ b/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):
     """





More information about the tor-commits mailing list