From 167fc4e214b95a9cd789ba12e0f96f7647e5c457 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Tue, 16 Apr 2019 02:18:49 +0200 Subject: [PATCH] Instantiate Config instance instead of using class namespace --- restic_volume_backup/cli.py | 6 ++---- restic_volume_backup/config.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/restic_volume_backup/cli.py b/restic_volume_backup/cli.py index 0cc2a73..d9be495 100644 --- a/restic_volume_backup/cli.py +++ b/restic_volume_backup/cli.py @@ -7,9 +7,7 @@ from restic_volume_backup.containers import RunningContainers def main(): args = parse_args() - - Config.check() - + config = Config() containers = RunningContainers() if args.action == 'status': @@ -33,7 +31,7 @@ def main(): # restic.backup_volume(Config.repository, vol) elif args.mode == 'snapshots': - restic.snapshots(Config.repository) + restic.snapshots(config.repository) def parse_args(): diff --git a/restic_volume_backup/config.py b/restic_volume_backup/config.py index e26ed6c..8ef4214 100644 --- a/restic_volume_backup/config.py +++ b/restic_volume_backup/config.py @@ -2,14 +2,15 @@ import os class Config: - repository = os.environ['RESTIC_REPOSITORY'] - password = os.environ['RESTIC_PASSWORD'] - docker_base_url = os.environ.get('DOCKER_BASE_URL') or "unix://tmp/docker.sock" + def __init__(self): + self.repository = os.environ['RESTIC_REPOSITORY'] + self.password = os.environ['RESTIC_PASSWORD'] + self.docker_base_url = os.environ.get('DOCKER_BASE_URL') or "unix://tmp/docker.sock" + self.check() - @classmethod - def check(cls): - if not cls.repository: + def check(self): + if not self.repository: raise ValueError("CONTAINER env var not set") - if not cls.password: + if not self.password: raise ValueError("PASSWORD env var not set")