summaryrefslogtreecommitdiff
path: root/onionshare
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-11-02 23:32:44 -0700
committerMicah Lee <micah@micahflee.com>2019-11-02 23:32:44 -0700
commitd61fc45862acbccd07c4f0e972f5c2ab18697f0a (patch)
tree1a4bb138e855329c42da7c781a5d058d307757ab /onionshare
parent1bca467ce36654dd5abebfc53f4902c06391d756 (diff)
downloadonionshare-d61fc45862acbccd07c4f0e972f5c2ab18697f0a.tar.gz
onionshare-d61fc45862acbccd07c4f0e972f5c2ab18697f0a.zip
Make it so passing in --persistent [filename] in the CLI, with no other args, will load that persistent mode settings file and start the server, without needing to do other validations like passing in a list of filenames
Diffstat (limited to 'onionshare')
-rw-r--r--onionshare/__init__.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index f532ec0e..5b95e3a1 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -193,24 +193,8 @@ def main(cwd=None):
else:
mode = "share"
- # In share an website mode, you must supply a list of filenames
- if mode == "share" or mode == "website":
- # Make sure filenames given if not using receiver mode
- if len(filenames) == 0:
- parser.print_help()
- sys.exit()
-
- # Validate filenames
- valid = True
- for filename in filenames:
- if not os.path.isfile(filename) and not os.path.isdir(filename):
- print(f"{filename} is not a valid file.")
- valid = False
- if not os.access(filename, os.R_OK):
- print(f"{filename} is not a readable file.")
- valid = False
- if not valid:
- sys.exit()
+ # Verbose mode?
+ common.verbose = verbose
# client_auth can only be set if legacy is also set
if client_auth and not legacy:
@@ -225,16 +209,15 @@ def main(cwd=None):
else:
common.load_settings()
- # Verbose mode?
- common.verbose = verbose
-
# Mode settings
if persistent_filename:
mode_settings = ModeSettings(common, persistent_filename)
mode_settings.set("persistent", "enabled", True)
else:
mode_settings = ModeSettings(common)
+
if mode_settings.just_created:
+ # This means the mode settings were just created, not loaded from disk
mode_settings.set("general", "public", public)
mode_settings.set("general", "autostart_timer", autostart_timer)
mode_settings.set("general", "autostop_timer", autostop_timer)
@@ -247,6 +230,37 @@ def main(cwd=None):
mode_settings.set("receive", "data_dir", data_dir)
if mode == "website":
mode_settings.set("website", "disable_csp", disable_csp)
+ else:
+ # See what the persistent mode was
+ mode = mode_settings.get("persistent", "mode")
+
+ # In share an website mode, you must supply a list of filenames
+ if mode == "share" or mode == "website":
+ # Unless you passed in a persistent filename, in which case get the filenames from
+ # the mode settings
+ if persistent_filename and not mode_settings.just_created:
+ filenames = mode_settings.get(mode, "filenames")
+
+ else:
+ # Make sure filenames given if not using receiver mode
+ if len(filenames) == 0:
+ if persistent_filename:
+ mode_settings.delete()
+
+ parser.print_help()
+ sys.exit()
+
+ # Validate filenames
+ valid = True
+ for filename in filenames:
+ if not os.path.isfile(filename) and not os.path.isdir(filename):
+ print(f"{filename} is not a valid file.")
+ valid = False
+ if not os.access(filename, os.R_OK):
+ print(f"{filename} is not a readable file.")
+ valid = False
+ if not valid:
+ sys.exit()
# Create the Web object
web = Web(common, False, mode_settings, mode)