From d61fc45862acbccd07c4f0e972f5c2ab18697f0a Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 2 Nov 2019 23:32:44 -0700 Subject: [PATCH] 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 --- onionshare/__init__.py | 56 ++++++++++++++++++++++++--------------- onionshare_gui/threads.py | 7 ++--- 2 files changed, 37 insertions(+), 26 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) diff --git a/onionshare_gui/threads.py b/onionshare_gui/threads.py index 90a0fbb9..fa0f6c7b 100644 --- a/onionshare_gui/threads.py +++ b/onionshare_gui/threads.py @@ -47,15 +47,12 @@ class OnionThread(QtCore.QThread): self.mode.web.generate_static_url_path() # Choose port and password early, because we need them to exist in advance for scheduled shares - self.mode.app.stay_open = not self.mode.common.settings.get( - "close_after_first_download" - ) if not self.mode.app.port: self.mode.app.choose_port() - if not self.mode.common.settings.get("public_mode"): + if not self.mode.settings.get("general", "public"): if not self.mode.web.password: self.mode.web.generate_password( - self.mode.common.settings.get("password") + self.mode.settings.get("persistent", "password") ) try: