wip(22w9c): add single item backup

This commit is contained in:
Victor Westerlund 2022-03-05 18:38:55 +01:00
parent ff0b3529e0
commit d9a6183d63
3 changed files with 56 additions and 3 deletions

View file

@ -1,5 +1,31 @@
import sys
from src import Backup
from src import Backup, file_exists
Backup().backup_all()
# 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")

23
resolve.py Normal file
View file

@ -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")

View file

@ -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