adding argparse to GUI (#58, also #50)

This commit is contained in:
Micah Lee 2014-06-26 14:22:32 -04:00
parent 4e3c32cbff
commit 2b8be2781c

View File

@ -1,4 +1,4 @@
import os, sys, subprocess, inspect, platform
import os, sys, subprocess, inspect, platform, argparse
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
@ -54,11 +54,9 @@ def alert(msg, icon=QMessageBox.NoIcon):
dialog.setIcon(icon)
dialog.exec_()
def select_file(strings):
def select_file(strings, filename=None):
# get filename, either from argument or file chooser dialog
if len(sys.argv) == 2:
filename = sys.argv[1]
else:
if not filename:
args = {}
if onionshare.get_platform() == 'Tails':
args['directory'] = '/home/amnesia'
@ -89,6 +87,19 @@ def main():
subprocess.call(['/usr/bin/gksudo']+sys.argv)
return
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('--local-only', action='store_true', dest='local_only', help='Do not attempt to use tor: for development only')
parser.add_argument('--stay-open', action='store_true', dest='stay_open', help='Keep hidden service running after download has finished')
parser.add_argument('--debug', action='store_true', dest='debug', help='Log errors to disk')
parser.add_argument('filename', nargs='?', help='File to share')
args = parser.parse_args()
filename = args.filename
local_only = args.local_only
stay_open = args.stay_open
debug = args.debug
# create the onionshare icon
global window_icon, onionshare_gui_dir
window_icon = QIcon("{0}/onionshare-icon.png".format(onionshare_gui_dir))
@ -103,7 +114,7 @@ def main():
onionshare.tails_open_port(onionshare_port)
# select file to share
filename, basename = select_file(onionshare.strings)
filename, basename = select_file(onionshare.strings, filename)
if not filename:
return