Another progress commit

This commit is contained in:
Marcel Otte 2019-05-03 21:36:44 +02:00
parent 5ca75cc900
commit 88c83cc1d8
7 changed files with 68 additions and 12 deletions

View File

@ -4,11 +4,12 @@
Service startup script. Service startup script.
""" """
from backive.core.events import EventInterface from backive.core.events import EventInterface
from backive.config.config import Config
class Backive: class Backive:
def __init__(self): def __init__(self):
self._config = None self._config = Config()
self._events = None self._events = None
def serve(self): def serve(self):

View File

@ -27,8 +27,12 @@ class Config:
if uid == 0: if uid == 0:
config_file = "/etc/backive.yml" config_file = "/etc/backive.yml"
else: else:
config_file = os.path.join(os.path.expanduser("~"), ".backive", "backive.yml") config_file = os.path.join(
pass os.path.expanduser("~"),
".config",
"backive",
"backive.yml"
)
with open(config_file, "r") as cfg: with open(config_file, "r") as cfg:
self._config = YAML().load(cfg) self._config = YAML().load(cfg)

View File

@ -52,6 +52,7 @@ definitions:
enum: [ "local", "remote" ] enum: [ "local", "remote" ]
script: script:
type: string type: string
execute: [ "before", "after" ]
additionalProperties: false additionalProperties: false
tool: tool:
type: object type: object

View File

@ -6,9 +6,11 @@ class Backup:
self.name = name self.name = name
self.config = cfg self.config = cfg
def get_frequency(self):
return self.config.get("frequency", None)
def run(self): def run(self):
if self.config.get("scripts", None):
pass pass
@classmethod
def instance(cls, name, cfg):
return Backup(name, cfg)

View File

@ -9,10 +9,6 @@ class Device:
self.uuid = uuid self.uuid = uuid
self.config = config self.config = config
@classmethod
def instance(cls, uuid, config):
return Device(uuid, config)
@classmethod @classmethod
def get_list(cls): def get_list(cls):
if os.path.exists(cls.disks_by_uuid): if os.path.exists(cls.disks_by_uuid):

49
backive/core/scheduler.py Normal file
View File

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

View File

@ -46,12 +46,15 @@ class Device
class Tool class Tool
class Scheduler
backive_service --> Service : provides startup to backive_service --> Service : provides startup to
EventInterface --* Service EventInterface --* Service
Config --* Service Config --* Service
Backup --* Service Backup --* Service
Device --* Backup Device --* Backup
Tool --* Backup Tool --* Backup
Backup <..> Scheduler: registers,\nasks for next run,\nstores run-data
Config ..> Backup : generates Backup objects Config ..> Backup : generates Backup objects
backive_udev ..> EventInterface : sends data through unix socket backive_udev ..> EventInterface : sends data through unix socket