Add log() method to onionshare.common, which logs to stdout if in debug mode

This commit is contained in:
Micah Lee 2017-05-16 11:12:55 -07:00
parent 1591888863
commit 7003349873
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
6 changed files with 30 additions and 14 deletions

View File

@ -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)

View File

@ -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():
"""

View File

@ -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

View File

@ -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

View File

@ -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():

View File

@ -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