[Pkg-privacy-commits] [onionshare] 175/256: Add log() method to onionshare.common, which logs to stdout if in debug mode

Ulrike Uhlig ulrike at moszumanska.debian.org
Fri May 26 12:53:35 UTC 2017


This is an automated email from the git hooks/post-receive script.

ulrike pushed a commit to branch master
in repository onionshare.

commit 7003349873ba81693945098041d182e3a158785b
Author: Micah Lee <micah at micahflee.com>
Date:   Tue May 16 11:12:55 2017 -0700

    Add log() method to onionshare.common, which logs to stdout if in debug mode
---
 onionshare/__init__.py           | 11 ++++++-----
 onionshare/common.py             | 13 +++++++++++++
 onionshare/onion.py              |  4 +---
 onionshare/onionshare.py         |  2 +-
 onionshare_gui/__init__.py       | 11 ++++++++---
 onionshare_gui/onionshare_gui.py |  3 +--
 6 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index 1043334..f2180ce 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -56,6 +56,11 @@ def main(cwd=None):
     stay_open = bool(args.stay_open)
     stealth = bool(args.stealth)
 
+    # Debug mode?
+    if debug:
+        common.set_debug(debug)
+        web.debug_mode()
+
     # Validation
     valid = True
     for filename in filenames:
@@ -66,7 +71,7 @@ def main(cwd=None):
         sys.exit()
 
     # Start the Onion object
-    onion = Onion(debug)
+    onion = Onion()
     try:
         onion.connect()
     except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
@@ -84,10 +89,6 @@ def main(cwd=None):
         print("")
         sys.exit()
 
-    # Debug mode?
-    if debug:
-        web.debug_mode()
-
     # Prepare files to share
     print(strings._("preparing_files"))
     web.set_file_info(filenames)
diff --git a/onionshare/common.py b/onionshare/common.py
index 5f3d119..8d5ad79 100644
--- a/onionshare/common.py
+++ b/onionshare/common.py
@@ -20,6 +20,19 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 import sys, os, inspect, hashlib, base64, platform, zipfile, tempfile, math, time, socket, random
 from random import SystemRandom
 
+debug = False
+def log(module, func, msg):
+    """
+    If debug mode is on, log error messages to stdout
+    """
+    global debug
+    if debug:
+        print("[{}.{}] {}".format(module, func, msg))
+
+def set_debug(new_debug):
+    global debug
+    debug = new_debug
+
 
 def get_platform():
     """
diff --git a/onionshare/onion.py b/onionshare/onion.py
index 8b67377..ef806a4 100644
--- a/onionshare/onion.py
+++ b/onionshare/onion.py
@@ -119,9 +119,7 @@ class Onion(object):
     call this function and pass in a status string while connecting to tor. This
     is necessary for status updates to reach the GUI.
     """
-    def __init__(self, debug):
-        self.debug = debug
-
+    def __init__(self):
         self.stealth = False
         self.service_id = None
 
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 43c1969..71b8b9d 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -27,7 +27,7 @@ class OnionShare(object):
     OnionShare is the main application class. Pass in options and run
     start_onion_service and it will do the magic.
     """
-    def __init__(self, onion, debug=False, local_only=False, stay_open=False):
+    def __init__(self, onion, local_only=False, stay_open=False):
         # The Onion object
         self.onion = onion
 
diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py
index 8b7bdf3..3cc4c07 100644
--- a/onionshare_gui/__init__.py
+++ b/onionshare_gui/__init__.py
@@ -76,6 +76,11 @@ def main():
     stay_open = bool(args.stay_open)
     debug = bool(args.debug)
 
+    # Debug mode?
+    if debug:
+        common.set_debug(debug)
+        web.debug_mode()
+
     # Validation
     if filenames:
         valid = True
@@ -87,14 +92,14 @@ def main():
             sys.exit()
 
     # Start the Onion
-    onion = Onion(debug)
+    onion = Onion()
 
     # Start the OnionShare app
     web.set_stay_open(stay_open)
-    app = OnionShare(onion, debug, local_only, stay_open)
+    app = OnionShare(onion, local_only, stay_open)
 
     # Launch the gui
-    gui = OnionShareGui(onion, debug, qtapp, app, filenames)
+    gui = OnionShareGui(onion, qtapp, app, filenames)
 
     # Clean up when app quits
     def shutdown():
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index db1c783..84f3ab3 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -44,10 +44,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
     starting_server_step3 = QtCore.pyqtSignal()
     starting_server_error = QtCore.pyqtSignal(str)
 
-    def __init__(self, onion, debug, qtapp, app, filenames):
+    def __init__(self, onion, qtapp, app, filenames):
         super(OnionShareGui, self).__init__()
         self.onion = onion
-        self.debug = debug
         self.qtapp = qtapp
         self.app = app
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list