From 5d0e725d2bd6208a7342394886a589045f645b94 Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Sat, 4 Sep 2021 10:08:23 +0200
Subject: Implement Config Parsing

---
 README.md             |  2 +-
 config/default.json   |  3 +++
 src/xbackup/config.py | 25 +++++++++++++++++++++++++
 src/xbackup/script.py |  4 ++++
 4 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 config/default.json
 create mode 100644 src/xbackup/config.py

diff --git a/README.md b/README.md
index 31ab10c..06be63c 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@ This is a convenience wrapper around the Borg backup tool.
 
 (Last finished task first)
 
+- [x] config parsing
 - [x] argument parsing
 - [x] implement Arch Linux Packaging
 - [x] setup project structure
@@ -18,7 +19,6 @@ This is a convenience wrapper around the Borg backup tool.
 
 (Highest priority first)
 
-- [ ] config parsing
 - [ ] manual backup functionality / MVP
 - [ ] XMPP notification via [xbot](https://gitea.xengineering.eu/xengineering/xbot)
 - [ ] backup systemd daemon
diff --git a/config/default.json b/config/default.json
new file mode 100644
index 0000000..2bfd471
--- /dev/null
+++ b/config/default.json
@@ -0,0 +1,3 @@
+{
+	"test":4
+}
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:
-- 
cgit v1.2.3-70-g09d2