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

This commit is contained in:
Micah Lee 2019-11-02 23:32:44 -07:00
parent 1bca467ce3
commit d61fc45862
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 37 additions and 26 deletions

View File

@ -193,24 +193,8 @@ def main(cwd=None):
else: else:
mode = "share" mode = "share"
# In share an website mode, you must supply a list of filenames # Verbose mode?
if mode == "share" or mode == "website": common.verbose = verbose
# 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()
# client_auth can only be set if legacy is also set # client_auth can only be set if legacy is also set
if client_auth and not legacy: if client_auth and not legacy:
@ -225,16 +209,15 @@ def main(cwd=None):
else: else:
common.load_settings() common.load_settings()
# Verbose mode?
common.verbose = verbose
# Mode settings # Mode settings
if persistent_filename: if persistent_filename:
mode_settings = ModeSettings(common, persistent_filename) mode_settings = ModeSettings(common, persistent_filename)
mode_settings.set("persistent", "enabled", True) mode_settings.set("persistent", "enabled", True)
else: else:
mode_settings = ModeSettings(common) mode_settings = ModeSettings(common)
if mode_settings.just_created: 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", "public", public)
mode_settings.set("general", "autostart_timer", autostart_timer) mode_settings.set("general", "autostart_timer", autostart_timer)
mode_settings.set("general", "autostop_timer", autostop_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) mode_settings.set("receive", "data_dir", data_dir)
if mode == "website": if mode == "website":
mode_settings.set("website", "disable_csp", disable_csp) 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 # Create the Web object
web = Web(common, False, mode_settings, mode) web = Web(common, False, mode_settings, mode)

View File

@ -47,15 +47,12 @@ class OnionThread(QtCore.QThread):
self.mode.web.generate_static_url_path() self.mode.web.generate_static_url_path()
# Choose port and password early, because we need them to exist in advance for scheduled shares # 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: if not self.mode.app.port:
self.mode.app.choose_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: if not self.mode.web.password:
self.mode.web.generate_password( self.mode.web.generate_password(
self.mode.common.settings.get("password") self.mode.settings.get("persistent", "password")
) )
try: try: