diff --git a/backup.py b/backup.py index 31763ab..d13a322 100644 --- a/backup.py +++ b/backup.py @@ -1,5 +1,31 @@ import sys -from src import Backup +from src import Backup, file_exists -Backup().backup_all() \ No newline at end of file +# Back up a single file by path +def file_backup(): + path = sys.argv[2] + + if len(sys.argv) < 3: + return print("Invalid argument length: Expected path to file or folder") + + if not file_exists(path): + return print(f"File or folder at '{path}' does not exist") + + return Backup().backup_item(path, False) + +def run(method): + methods = { + "file": file_backup, + "all" : Backup().backup_all + } + + if method not in methods: + return print(f"Invalid argument '{method}'") + + return methods[method]() + +if len(sys.argv) > 1: + run(sys.argv[1]) +else: + run("all") \ No newline at end of file diff --git a/resolve.py b/resolve.py new file mode 100644 index 0000000..35b5c7a --- /dev/null +++ b/resolve.py @@ -0,0 +1,23 @@ +import sys + +from src import Database + +class Resolve(Database): + def __init__(self): + super().__init__() + + if self.item_exists(sys.argv[1]): + self.path_to_chksum() + else: + self.chksum_to_path() + + def path_to_chksum(self): + print("Something") + + def chksum_to_path(self): + print("Something else") + +if len(sys.argv) > 2: + Resolve() +else: + print("Invalid argument length: Need at least two") \ No newline at end of file diff --git a/src/backup.py b/src/backup.py index 7799ae2..9b9848c 100644 --- a/src/backup.py +++ b/src/backup.py @@ -16,7 +16,7 @@ class Backup(FileSystem): self.compress = self.db.get_flag("COMPRESS") # Backup a file or folder - def backup_item(self, item: Union[list, str]) -> bool: + def backup_item(self, item: Union[list, str], silent: bool = True) -> bool: if isinstance(item, str): item = self.get_item(item) @@ -54,6 +54,10 @@ class Backup(FileSystem): # Remove temp zip if self.compress: FileSystem.delete(blob) + + if not silent and not self.has_change: + print("✓ | Up to date. No changes found") + return # Scan TARGET_FOLDER for files and folders to back up