From 5dd19bbf808e7f1387c8517657bdbf41afe6b0d2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 22 Jun 2014 10:15:59 -0400 Subject: [PATCH 1/2] commit so I can pull --- onionshare_gui/onionshare_gui.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 945813e6..b58441d3 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -2,10 +2,11 @@ import os, sys, subprocess, inspect from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * - from os import path -sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) -import onionshare, webapp +print "after path import" +print "after path change" +import onionshare +import webapp window_icon = None @@ -70,6 +71,7 @@ def select_file(strings): return filename, basename def main(): + print "start main" onionshare.strings = onionshare.load_strings() # start the Qt app @@ -112,6 +114,7 @@ def main(): onionshare.tails_open_port(webapp_port) webapp_thread = WebAppThread(webapp_port) webapp_thread.start() + print "after webapp functs" # clean up when app quits def shutdown(): @@ -122,7 +125,7 @@ def main(): # launch the window web = Window(basename, webapp_port) web.show() - + print "after show happens" # all done sys.exit(app.exec_()) From 5c27838379b9200079c47a5ffaac21feaf6be3c2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 23 Jun 2014 21:09:26 -0400 Subject: [PATCH 2/2] Reworked code to work with PyInstaller dev version 34be811. --- onionshare_gui/__init__.py | 1 - onionshare_gui/onionshare.py | 4 +++- onionshare_gui/onionshare_gui.py | 10 +--------- onionshare_gui/webapp.py | 11 +++++++++-- 4 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 onionshare_gui/__init__.py diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py deleted file mode 100644 index 011371cd..00000000 --- a/onionshare_gui/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from onionshare_gui import * diff --git a/onionshare_gui/onionshare.py b/onionshare_gui/onionshare.py index 06b0816e..33992264 100644 --- a/onionshare_gui/onionshare.py +++ b/onionshare_gui/onionshare.py @@ -42,8 +42,10 @@ def add_request(type, path, data=None): @app.route("/{0}".format(slug)) def index(): - global filename, filesize, filehash, slug, strings, REQUEST_LOAD + global filename, filesize, filehash, slug, strings, REQUEST_LOAD, onionshare_dir add_request(REQUEST_LOAD, request.path) + if getattr(sys, "frozen", False): + onionshare_dir = os.path.dirname(sys.executable) return render_template_string(open('{0}/index.html'.format(onionshare_dir)).read(), slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 05305027..d81004c7 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -2,11 +2,6 @@ import os, sys, subprocess, inspect from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * -from os import path -print "after path import" -print "after path change" -import onionshare -import webapp onionshare_gui_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) @@ -17,7 +12,6 @@ except ImportError: import onionshare import webapp - window_icon = None class Application(QApplication): @@ -81,7 +75,6 @@ def select_file(strings): return filename, basename def main(): - print "start main" onionshare.strings = onionshare.load_strings() # start the Qt app @@ -123,7 +116,6 @@ def main(): onionshare.tails_open_port(webapp_port) webapp_thread = WebAppThread(webapp_port) webapp_thread.start() - print "after webapp functs" # clean up when app quits def shutdown(): @@ -134,7 +126,7 @@ def main(): # launch the window web = Window(basename, webapp_port) web.show() - print "after show happens" + # all done sys.exit(app.exec_()) diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index 80f2c3f8..12a8729d 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -7,7 +7,6 @@ filename = None onion_host = None qtapp = None clipboard = None - url = None # figure out this platform's temp dir @@ -26,7 +25,15 @@ import logging log_handler = logging.FileHandler('{0}/onionshare.web.log'.format(temp_dir)) log_handler.setLevel(logging.WARNING) -app = Flask(__name__, template_folder='./templates') +# pyinstaller sets sys.frozen=1 on run +application_path = "" +if getattr(sys, "frozen", False): + application_path = os.path.dirname(sys.executable) +elif __file__: + application_path = os.path.dirname(__file__) +template_path = os.path.join(application_path, "templates") + +app = Flask(__name__, template_folder=template_path) app.logger.addHandler(log_handler) @app.route("/")