Catch UnknownSSHError and do not use return codes
The runners were still checking for the return codes of create_ssh_master_connection instead of catching the exception. We now catch the exceptions we calling the runners in main.
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from unisync.argparser import create_argparser
|
from unisync.argparser import create_argparser
|
||||||
|
from unisync.errors import UnknownSSHError, unisync_exit_fatal
|
||||||
from unisync.runners import unisync_sync, unisync_add, unisync_mount
|
from unisync.runners import unisync_sync, unisync_add, unisync_mount
|
||||||
from unisync.config import load_config
|
from unisync.config import load_config
|
||||||
from unisync.synchroniser import Synchroniser
|
from unisync.synchroniser import Synchroniser
|
||||||
@@ -38,7 +39,10 @@ def main():
|
|||||||
|
|
||||||
paths_manager = PathsManager(Path(config.roots.local), config.other.cache_dir_path)
|
paths_manager = PathsManager(Path(config.roots.local), config.other.cache_dir_path)
|
||||||
|
|
||||||
cli_args.func(synchroniser, paths_manager, config)
|
try:
|
||||||
|
cli_args.func(synchroniser, paths_manager, config)
|
||||||
|
except UnknownSSHError:
|
||||||
|
unisync_exit_fatal("Connection failed quitting")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ from unisync.synchroniser import Synchroniser
|
|||||||
from unisync.paths import PathsManager
|
from unisync.paths import PathsManager
|
||||||
from unisync.config import Config
|
from unisync.config import Config
|
||||||
|
|
||||||
|
|
||||||
def unisync_sync(synchroniser:Synchroniser, paths_manager:PathsManager, config: Config):
|
def unisync_sync(synchroniser:Synchroniser, paths_manager:PathsManager, config: Config):
|
||||||
del config # The function signature must be the same for all runners
|
del config # The function signature must be the same for all runners
|
||||||
if synchroniser.create_ssh_master_connection() != 0:
|
|
||||||
print("Connection failed quitting")
|
synchroniser.create_ssh_master_connection()
|
||||||
return 1
|
|
||||||
print("Connected to the remote.")
|
print("Connected to the remote.")
|
||||||
|
|
||||||
synchroniser.sync_files(paths_manager.get_paths_to_sync())
|
synchroniser.sync_files(paths_manager.get_paths_to_sync())
|
||||||
@@ -24,9 +24,8 @@ def unisync_sync(synchroniser:Synchroniser, paths_manager:PathsManager, config:
|
|||||||
|
|
||||||
def unisync_add(synchroniser:Synchroniser, paths_manager:PathsManager, config: Config):
|
def unisync_add(synchroniser:Synchroniser, paths_manager:PathsManager, config: Config):
|
||||||
del config # The function signature must be the same for all runners
|
del config # The function signature must be the same for all runners
|
||||||
if synchroniser.create_ssh_master_connection() != 0:
|
|
||||||
print("Connection failed quitting")
|
synchroniser.create_ssh_master_connection()
|
||||||
return 1
|
|
||||||
print("Connected to the remote.")
|
print("Connected to the remote.")
|
||||||
|
|
||||||
# TODO config or cli to skip this first sync
|
# TODO config or cli to skip this first sync
|
||||||
|
|||||||
Reference in New Issue
Block a user