diff --git a/backive/backive_service b/backive/backive_service index 56c6ebc..cc66abc 100644 --- a/backive/backive_service +++ b/backive/backive_service @@ -4,11 +4,12 @@ Service startup script. """ from backive.core.events import EventInterface +from backive.config.config import Config class Backive: def __init__(self): - self._config = None + self._config = Config() self._events = None def serve(self): diff --git a/backive/config/config.py b/backive/config/config.py index 9474090..70471c4 100644 --- a/backive/config/config.py +++ b/backive/config/config.py @@ -27,8 +27,12 @@ class Config: if uid == 0: config_file = "/etc/backive.yml" else: - config_file = os.path.join(os.path.expanduser("~"), ".backive", "backive.yml") - pass + config_file = os.path.join( + os.path.expanduser("~"), + ".config", + "backive", + "backive.yml" + ) with open(config_file, "r") as cfg: self._config = YAML().load(cfg) diff --git a/backive/config/schema.yml b/backive/config/schema.yml index 0cd5c03..fd62493 100644 --- a/backive/config/schema.yml +++ b/backive/config/schema.yml @@ -52,6 +52,7 @@ definitions: enum: [ "local", "remote" ] script: type: string + execute: [ "before", "after" ] additionalProperties: false tool: type: object diff --git a/backive/core/backup.py b/backive/core/backup.py index c354ed8..803be54 100644 --- a/backive/core/backup.py +++ b/backive/core/backup.py @@ -6,9 +6,11 @@ class Backup: self.name = name self.config = cfg - def run(self): - pass + def get_frequency(self): + return self.config.get("frequency", None) + + def run(self): + + if self.config.get("scripts", None): + pass - @classmethod - def instance(cls, name, cfg): - return Backup(name, cfg) diff --git a/backive/core/device.py b/backive/core/device.py index 4de7cf9..db192de 100644 --- a/backive/core/device.py +++ b/backive/core/device.py @@ -9,10 +9,6 @@ class Device: self.uuid = uuid self.config = config - @classmethod - def instance(cls, uuid, config): - return Device(uuid, config) - @classmethod def get_list(cls): if os.path.exists(cls.disks_by_uuid): diff --git a/backive/core/scheduler.py b/backive/core/scheduler.py new file mode 100644 index 0000000..0e32bd5 --- /dev/null +++ b/backive/core/scheduler.py @@ -0,0 +1,49 @@ +import os +import json + + +class Singleton(type): + _instances = {} + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) + return cls._instances[cls] + + +class Scheduler(metaclass=Singleton): + def __init__(self): + self._data = dict() + # who are we? + uid = os.getuid() + if uid == 0: + self._data_file = "/var/lib/backive/data.json" + else: + self._data_file = os.path.join( + os.path.expanduser("~"), + ".config", + "backive", + "data.json" + ) + if not os.path.exists(os.path.dirname(self._data_file)): + os.makedirs(os.path.dirname(self._data_file)) + self.save() + + def save(self): + with open(self._data_file, "w") as stream: + json.dump(self._data, stream, indent=2) + + def load(self): + with open(self._data_file, "r") as stream: + self._data = json.load(stream) + + def register_backup(self, name, frequency): + pass + + def register_run(self, name): + pass + + def should_run(self, name): + pass + + def get_overtimed(self): + return list() diff --git a/doc/architecture.puml b/doc/architecture.puml index 1268693..b0ed1cb 100644 --- a/doc/architecture.puml +++ b/doc/architecture.puml @@ -46,12 +46,15 @@ class Device class Tool +class Scheduler + backive_service --> Service : provides startup to EventInterface --* Service Config --* Service Backup --* Service Device --* Backup Tool --* Backup +Backup <..> Scheduler: registers,\nasks for next run,\nstores run-data Config ..> Backup : generates Backup objects backive_udev ..> EventInterface : sends data through unix socket