diff --git a/backive/config/config.py b/backive/config/config.py index 8fec439..520ae32 100644 --- a/backive/config/config.py +++ b/backive/config/config.py @@ -3,11 +3,14 @@ import pwd from ruamel.yaml import YAML import logging +from backive.core.backup import Backup +from backive.core.device import Device + class Config: def __init__(self): - pass + self._config = dict() def find_config(self): # who are we? @@ -16,12 +19,43 @@ class Config: user = pwd.getpwuid(uid).pw_name try: if uid == 0: - config_file = "/etc/mbd.yml" + config_file = "/etc/backive.yml" else: - config_file = os.path.join(os.path.expanduser("~"), ".mbd", "mbd.yml") + config_file = os.path.join(os.path.expanduser("~"), ".backive", "backive.yml") pass with open(config_file, "r") as cfg: self._config = YAML().load(cfg) except Exception as e: logging.error(e) + + def get_devices(self): + devices = [] + if self._config.get("devices", None): + data = self._config.get("devices") + for device in data: + devices.append( + Device.instance( + device, + data.get(device) + ) + ) + return devices + + def get_backups(self): + backups = [] + if self._config.get("backups", None): + data = self._config.get("backups") + for name in data: + backups.append( + Backup.instance( + name, + data.get(name) + ) + ) + return backups + + def get_globals(self): + if self._config.get("defaults", None): + return self._config.get("defaults") + return {} diff --git a/backive/core/backup.py b/backive/core/backup.py index 12c6f54..65dca4b 100644 --- a/backive/core/backup.py +++ b/backive/core/backup.py @@ -5,10 +5,12 @@ class Backup: config = {} - def __init__(self): + def __init__(self, name, cfg=None): pass def run(self): pass - + @classmethod + def instance(cls, name, cfg): + return Backup(name, cfg) diff --git a/backive/core/device.py b/backive/core/device.py index fced780..4de7cf9 100644 --- a/backive/core/device.py +++ b/backive/core/device.py @@ -1,15 +1,28 @@ import os +import backive.config.config as cfg class Device: disks_by_uuid = "/dev/disk/by-uuid" - def __init__(self): - pass + def __init__(self, uuid, config=None): + self.uuid = uuid + self.config = config @classmethod - def get_device_list(cls): + def instance(cls, uuid, config): + return Device(uuid, config) + + @classmethod + def get_list(cls): if os.path.exists(cls.disks_by_uuid): uuids = os.listdir(cls.disks_by_uuid) return uuids return [] + + def mount(self): + pass + + def unmount(self): + pass + diff --git a/backive/core/tool.py b/backive/core/tool.py new file mode 100644 index 0000000..8b11c4a --- /dev/null +++ b/backive/core/tool.py @@ -0,0 +1,20 @@ +import os + + +AVAILABLE_TOOLS = {} + +def register_tool(name): + def decorator(Cls): + AVAILABLE_TOOLS.update({name: Cls}) + return decorator + + +class Tool: + def __init__(self, options): + pass + + @classmethod + def instance(cls, name, options): + if name in AVAILABLE_TOOLS: + return AVAILABLE_TOOLS.get(name)(options) + return None diff --git a/backive/tools/rsync.py b/backive/tools/rsync.py new file mode 100644 index 0000000..37178c9 --- /dev/null +++ b/backive/tools/rsync.py @@ -0,0 +1,10 @@ +from backive.core.tool import AVAILABLE_TOOLS, register_tool + + +@register_tool("rsync") +class Rsync: + def __init__(self, options): + pass + + + diff --git a/setup.py b/setup.py index e69de29..f1fb221 100644 --- a/setup.py +++ b/setup.py @@ -0,0 +1,23 @@ +import setuptools +from setuptools import setup, find_packages + + +VERSION="0.1.0" + +setup_info = dict( + name="backive", + version=VERSION, + author="Marcel M. Otte", + author_email="qwc+backive@mmo.to", + url="tbd", + description="", + license="BSD", + classifiers=[ + ], + packages=find_packages(), + + ) + +setup(**setup_info) + +