Instantiate Config instance instead of using class namespace

This commit is contained in:
Einar Forselv 2019-04-16 02:18:49 +02:00
parent 2884fc1eec
commit 167fc4e214
2 changed files with 10 additions and 11 deletions

View File

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

View File

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