From addbdb87dfa79d0f8dc94c740e837acbc4939fe5 Mon Sep 17 00:00:00 2001 From: furtest Date: Thu, 1 Jan 2026 23:19:57 +0100 Subject: [PATCH] main : adds subcommands, move to Path and improve Multiple changes to the main file, after this unisync becomes kind of usable. Add subcommands : this uses the 2 previous commits to add the subcommands to unisync it is now possible to sync, add and mount. pathlib : move from PosixPath to Path Remove unused imports Rename base_namespace to cli_args Add some comments and TODOs --- src/unisync/main.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/unisync/main.py b/src/unisync/main.py index e957c09..828aa3f 100644 --- a/src/unisync/main.py +++ b/src/unisync/main.py @@ -3,24 +3,29 @@ import os from argparser import create_argparser -from config import RootsConfig, ServerConfig, Config, load_config +from runners import unisync_sync, unisync_add, unisync_mount +from config import load_config from synchroniser import Synchroniser -from pathlib import Path, PosixPath +from pathlib import Path from paths import * def main(): - parser = create_argparser() - base_namespace = parser.parse_args() + parser = create_argparser(unisync_sync, unisync_add, unisync_mount) + cli_args = parser.parse_args() config_path = os.path.expanduser("~/.config/unisync/config.ini") - if base_namespace.config != None and os.path.isfile(base_namespace.config): - config = load_config(base_namespace.config) + # Check if --config is set + if cli_args.config != None and os.path.isfile(cli_args.config): + config = load_config(cli_args.config) elif os.path.isfile(config_path): config = load_config(config_path) else: - # TODO make the command line arguments work and override the config options + # TODO replace the next line with something to do if no config file is found + config = load_config(config_path) pass + # TODO make the command line arguments work and override the config options + synchroniser = Synchroniser( config.roots.remote, config.roots.local, @@ -33,18 +38,7 @@ def main(): paths_manager = PathsManager(Path(config.roots.local), config.other.cache_dir_path) - if synchroniser.create_ssh_master_connection() != 0: - print("Connection failed quitting") - return 1 - print("Connected to the remote.") - - #synchroniser.sync_files() - #synchroniser.update_links(background=False) - #synchroniser.mount_remote_dir() - - synchroniser.close_ssh_master_connection() - print(paths_manager.get_paths_to_sync()) - + cli_args.func(synchroniser, paths_manager) if __name__ == "__main__":