diff --git a/backup.py b/backup.py index 5d0e534..8120d6a 100644 --- a/backup.py +++ b/backup.py @@ -24,25 +24,31 @@ class Backup: tarball_size = "50M" save_location = "" - def __init__(self, key, bdd=None, save_mode=None, save_location=None, app_key_id=None, app_key=None, bucket_id=None): + def backblaze(self, key, bdd=None, app_key_id=None, app_key=None, bucket_id=None): self.key = key + self.save_mode = BACKBLAZE - if save_mode is None: - raise Exception("No save_mode") - elif save_mode == BACKBLAZE: - if None in (app_key_id, app_key, bucket_id): - raise Exception("Some arguments are not filled") - self.b2 = B2Api() - self.b2.authorize_account("production", app_key_id, app_key) - self.buk = self.b2.get_bucket_by_id(bucket_id) - self.bdd = DataBase(bdd) - elif save_mode == LOCAL: - if None in (save_location, bdd): - raise Exception("Some arguments are not filled") - self.save_location = save_location - self.bdd = DataBase(bdd) + if None in (app_key_id, app_key, bucket_id): + raise Exception("Some arguments are not filled") + self.b2 = B2Api() + self.b2.authorize_account("production", app_key_id, app_key) + self.buk = self.b2.get_bucket_by_id(bucket_id) + self.bdd = DataBase(bdd) + + return self + + + def local(self, key, bdd=None, save_location=None): + self.key = key + self.save_mode = LOCAL + + if None in (save_location, bdd): + raise Exception("Some arguments are not filled") + self.save_location = save_location + self.bdd = DataBase(bdd) + + return self - self.save_mode = save_mode def save(self, path, recurse=True): self.__save(path, recurse=recurse) diff --git a/main.py b/main.py index 4f107ba..c5cf32b 100644 --- a/main.py +++ b/main.py @@ -20,8 +20,8 @@ bucket_id = '6a1a9000075465fe7cc4021a' bdd = "bdd.db" -# bck = Backup(key, save_mode=backup.BACKBLAZE, bdd=bdd, app_key_id=application_key_id, app_key=application_key, bucket_id=bucket_id) -bck = Backup(key, save_mode=backup.LOCAL, bdd=bdd, save_location="crypted") +#bck = Backup().backblaze(key, bdd=bdd, app_key_id=application_key_id, app_key=application_key, bucket_id=bucket_id) +bck = Backup().local(key, bdd=bdd, save_location="crypted") rootdir = "test" bck.save(rootdir).save("share", recurse=False)