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.
"""
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):

View File

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

View File

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

View File

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

View File

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

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