[Pkg-privacy-commits] [onionshare] 176/256: Add debug logging to Onion, OnionShare, and Settings objects
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 9c166a07d2d86c211db880b510a53fb2420be384
Author: Micah Lee <micah at micahflee.com>
Date: Tue May 16 11:23:18 2017 -0700
Add debug logging to Onion, OnionShare, and Settings objects
---
onionshare/__init__.py | 2 +-
onionshare/common.py | 9 +++++++--
onionshare/onion.py | 10 ++++++++++
onionshare/onionshare.py | 8 ++++++++
onionshare/settings.py | 13 +++++++++++++
5 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index f2180ce..145a25b 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -82,7 +82,7 @@ def main(cwd=None):
# Start the onionshare app
try:
- app = OnionShare(onion, debug, local_only, stay_open)
+ app = OnionShare(onion, local_only, stay_open)
app.set_stealth(stealth)
app.start_onion_service()
except KeyboardInterrupt:
diff --git a/onionshare/common.py b/onionshare/common.py
index 8d5ad79..798797d 100644
--- a/onionshare/common.py
+++ b/onionshare/common.py
@@ -21,13 +21,18 @@ import sys, os, inspect, hashlib, base64, platform, zipfile, tempfile, math, tim
from random import SystemRandom
debug = False
-def log(module, func, msg):
+def log(module, func, msg=None):
"""
If debug mode is on, log error messages to stdout
"""
global debug
if debug:
- print("[{}.{}] {}".format(module, func, msg))
+ timestamp = time.strftime("%b %d %Y %X")
+
+ final_msg = "[{}] {}.{}".format(timestamp, module, func)
+ if msg:
+ final_msg = '{}: {}'.format(final_msg, msg)
+ print(final_msg)
def set_debug(new_debug):
global debug
diff --git a/onionshare/onion.py b/onionshare/onion.py
index ef806a4..97965fb 100644
--- a/onionshare/onion.py
+++ b/onionshare/onion.py
@@ -120,6 +120,8 @@ class Onion(object):
is necessary for status updates to reach the GUI.
"""
def __init__(self):
+ common.log('Onion', '__init__')
+
self.stealth = False
self.service_id = None
@@ -138,6 +140,8 @@ class Onion(object):
self.tor_proc = None
def connect(self, settings=False, tor_status_update_func=None):
+ common.log('Onion', 'connect')
+
# Either use settings that are passed in, or load them from disk
if settings:
self.settings = settings
@@ -349,6 +353,8 @@ class Onion(object):
Start a onion service on port 80, pointing to the given port, and
return the onion hostname.
"""
+ common.log('Onion', 'start_onion_service')
+
self.auth_string = None
if not self.supports_ephemeral:
raise TorTooOld(strings._('error_ephemeral_not_supported'))
@@ -386,6 +392,8 @@ class Onion(object):
"""
Stop onion services that were created earlier. If there's a tor subprocess running, kill it.
"""
+ common.log('Onion', 'cleanup')
+
# Cleanup the ephemeral onion service
if self.service_id:
try:
@@ -406,6 +414,8 @@ class Onion(object):
"""
Returns a (address, port) tuple for the Tor SOCKS port
"""
+ common.log('Onion', 'get_tor_socks_port')
+
if self.settings.get('connection_type') == 'bundled':
return ('127.0.0.1', self.tor_socks_port)
elif self.settings.get('connection_type') == 'automatic':
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 71b8b9d..166afff 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -28,6 +28,8 @@ class OnionShare(object):
start_onion_service and it will do the magic.
"""
def __init__(self, onion, local_only=False, stay_open=False):
+ common.log('OnionShare', '__init__')
+
# The Onion object
self.onion = onion
@@ -45,6 +47,8 @@ class OnionShare(object):
self.stay_open = stay_open
def set_stealth(self, stealth):
+ common.log('OnionShare', 'set_stealth', 'stealth={}'.format(stealth))
+
self.stealth = stealth
self.onion.stealth = stealth
@@ -52,6 +56,8 @@ class OnionShare(object):
"""
Start the onionshare onion service.
"""
+ common.log('OnionShare', 'start_onion_service')
+
# Choose a random port
self.port = common.get_available_port(17600, 17650)
@@ -68,6 +74,8 @@ class OnionShare(object):
"""
Shut everything down and clean up temporary files, etc.
"""
+ common.log('OnionShare', 'cleanup')
+
# cleanup files
for filename in self.cleanup_filenames:
if os.path.isfile(filename):
diff --git a/onionshare/settings.py b/onionshare/settings.py
index 119d59a..d5d337e 100644
--- a/onionshare/settings.py
+++ b/onionshare/settings.py
@@ -30,6 +30,8 @@ class Settings(object):
settings.
"""
def __init__(self):
+ common.log('Settings', '__init__')
+
self.filename = self.build_filename()
# These are the default settings. They will get overwritten when loading from disk
@@ -56,6 +58,8 @@ class Settings(object):
If there are any missing settings from self._settings, replace them with
their default values.
"""
+ common.log('Settings', 'fill_in_defaults')
+
for key in self.default_settings:
if key not in self._settings:
self._settings[key] = self.default_settings[key]
@@ -64,6 +68,8 @@ class Settings(object):
"""
Returns the path of the settings file.
"""
+ common.log('Settings', 'build_filename')
+
p = platform.system()
if p == 'Windows':
appdata = os.environ['APPDATA']
@@ -77,6 +83,8 @@ class Settings(object):
"""
Load the settings from file.
"""
+ common.log('Settings', 'load')
+
# If the settings file exists, load it
if os.path.exists(self.filename):
try:
@@ -89,6 +97,8 @@ class Settings(object):
"""
Save settings to file.
"""
+ common.log('Settings', 'save')
+
try:
os.makedirs(os.path.dirname(self.filename))
except:
@@ -97,9 +107,12 @@ class Settings(object):
print(strings._('settings_saved').format(self.filename))
def get(self, key):
+ common.log('Settings', 'get', 'key={} (val={})'.format(key, self._settings[key]))
return self._settings[key]
def set(self, key, val):
+ common.log('Settings', 'set', 'key={}, val={}'.format(key, val))
+
# If typecasting int values fails, fallback to default values
if key == 'control_port_port' or key == 'socks_port':
try:
--
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