summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2021-09-04 10:08:23 +0200
committerxengineering <me@xengineering.eu>2021-09-04 10:11:53 +0200
commit5d0e725d2bd6208a7342394886a589045f645b94 (patch)
treed8605586e3aab164eb0399d6f3e4dac17bbf022b /src
parent48a2e73883d52236b76d4988a335b4752dd137da (diff)
downloadxbackup-5d0e725d2bd6208a7342394886a589045f645b94.tar
xbackup-5d0e725d2bd6208a7342394886a589045f645b94.tar.zst
xbackup-5d0e725d2bd6208a7342394886a589045f645b94.zip
Implement Config Parsing
Diffstat (limited to 'src')
-rw-r--r--src/xbackup/config.py25
-rw-r--r--src/xbackup/script.py4
2 files changed, 29 insertions, 0 deletions
diff --git a/src/xbackup/config.py b/src/xbackup/config.py
new file mode 100644
index 0000000..1e115a5
--- /dev/null
+++ b/src/xbackup/config.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python3
+# vim: shiftwidth=4 tabstop=4 expandtab
+
+
+"""Module for Configuration Parsing Functionality of xbackup"""
+
+
+import json
+
+
+def get(path):
+ """read and parse the xbackup configuration file"""
+
+ with open(path, "r", encoding="utf-8") as _file:
+ content = _file.read()
+
+ return json.loads(content)
+
+def dump(config, pretty=True):
+ """returns the given configuration as JSON string"""
+
+ if pretty:
+ return json.dumps(config, indent=4)
+
+ return json.dumps(config)
diff --git a/src/xbackup/script.py b/src/xbackup/script.py
index 9424b83..b69da00 100644
--- a/src/xbackup/script.py
+++ b/src/xbackup/script.py
@@ -9,14 +9,18 @@ import argparse
import time
import sys
+from xbackup import config
+
def run():
"""runs xbackup script functionality"""
args = parse_arguments()
+ cfg = config.get(args.config)
if args.command == "backup":
print("Performing dummy backup based on '{}'".format(args.config))
+ print("Config is:\n{}".format(config.dump(cfg)))
time.sleep(1)
print("Done!")
else: