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 6b35a44d41
commit 410a71b702
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) stay_open = bool(args.stay_open)
stealth = bool(args.stealth) stealth = bool(args.stealth)
# Debug mode?
if debug:
common.set_debug(debug)
web.debug_mode()
# Validation # Validation
valid = True valid = True
for filename in filenames: for filename in filenames:
@ -66,7 +71,7 @@ def main(cwd=None):
sys.exit() sys.exit()
# Start the Onion object # Start the Onion object
onion = Onion(debug) onion = Onion()
try: try:
onion.connect() onion.connect()
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e: except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
@ -84,10 +89,6 @@ def main(cwd=None):
print("") print("")
sys.exit() sys.exit()
# Debug mode?
if debug:
web.debug_mode()
# Prepare files to share # Prepare files to share
print(strings._("preparing_files")) print(strings._("preparing_files"))
web.set_file_info(filenames) 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 import sys, os, inspect, hashlib, base64, platform, zipfile, tempfile, math, time, socket, random
from random import SystemRandom 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(): 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 call this function and pass in a status string while connecting to tor. This
is necessary for status updates to reach the GUI. is necessary for status updates to reach the GUI.
""" """
def __init__(self, debug): def __init__(self):
self.debug = debug
self.stealth = False self.stealth = False
self.service_id = None self.service_id = None

View file

@ -27,7 +27,7 @@ class OnionShare(object):
OnionShare is the main application class. Pass in options and run OnionShare is the main application class. Pass in options and run
start_onion_service and it will do the magic. 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 # The Onion object
self.onion = onion self.onion = onion

View file

@ -76,6 +76,11 @@ def main():
stay_open = bool(args.stay_open) stay_open = bool(args.stay_open)
debug = bool(args.debug) debug = bool(args.debug)
# Debug mode?
if debug:
common.set_debug(debug)
web.debug_mode()
# Validation # Validation
if filenames: if filenames:
valid = True valid = True
@ -87,14 +92,14 @@ def main():
sys.exit() sys.exit()
# Start the Onion # Start the Onion
onion = Onion(debug) onion = Onion()
# Start the OnionShare app # Start the OnionShare app
web.set_stay_open(stay_open) web.set_stay_open(stay_open)
app = OnionShare(onion, debug, local_only, stay_open) app = OnionShare(onion, local_only, stay_open)
# Launch the gui # Launch the gui
gui = OnionShareGui(onion, debug, qtapp, app, filenames) gui = OnionShareGui(onion, qtapp, app, filenames)
# Clean up when app quits # Clean up when app quits
def shutdown(): def shutdown():

View file

@ -44,10 +44,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
starting_server_step3 = QtCore.pyqtSignal() starting_server_step3 = QtCore.pyqtSignal()
starting_server_error = QtCore.pyqtSignal(str) 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__() super(OnionShareGui, self).__init__()
self.onion = onion self.onion = onion
self.debug = debug
self.qtapp = qtapp self.qtapp = qtapp
self.app = app self.app = app