Working on it...

This commit is contained in:
Marcel Otte 2019-01-06 21:29:21 +01:00
parent 77e979886b
commit ee1ae9364a
6 changed files with 110 additions and 8 deletions

View File

@ -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 {}

View File

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

View File

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

20
backive/core/tool.py Normal file
View File

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

10
backive/tools/rsync.py Normal file
View File

@ -0,0 +1,10 @@
from backive.core.tool import AVAILABLE_TOOLS, register_tool
@register_tool("rsync")
class Rsync:
def __init__(self, options):
pass

View File

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