import asyncio from .. import utils class Backup(): name:str periode:int blocked:set to_backup:list def __init__(self, name:str, periode:int=None, blocked:list=[], to_backup:list=[]): # Check args utils.valid_name_check(name) if periode is not None and not isinstance(periode, int): raise TypeError("Periode have to be an integer or null.") if periode is not None and periode < 0: raise ValueError("periode can't be negetive.") blocked = set(blocked) for i in blocked: utils.valid_name_check(i) to_backup = set(to_backup) for i in to_backup: if not isinstance(i, str): raise TypeError("to_backup have to be a string.") if ":" in i: raise ValueError(": isn't allowed a char.") # Set values self.name = name self.periode = periode self.blocks = blocked self.to_backup = to_backup def get_next_scedule(self, latest, zero): if self.periode is not None: tmp = (latest - zero) // self.periode return zero + self.periode * (tmp + 1) else: raise NotImplementedError("No implemented types.") def dump_config(self): result = {} if self.blocked: result["blocked"] = ",".join(self.blocked) if self.periode is not None: result["periode"] = str(self.periode) if self.to_backup: result["to_backup"] = ":".join(self.to_backup) return result @staticmethod def load_backup(name:str, config): # Load informations config = dict(config.items()) periode = None if "periode" in config: periode = int(config["periode"]) del config["periode"] blocked = [] if "blocked" in config: blocked = config["blocked"].split(",") del config["blocked"] to_backup = [] if "to_backup" in config: to_backup = config["to_backup"].split(":") del config["to_backup"] # Generate backup utils.check_empty_data_dict(config) return Backup(name=name, periode=periode, blocked=blocked, to_backup=to_backup) async def run_backup(self, subvolumes:list): print("Subvolumes: %s" % repr(subvolumes))