From 0774fcd83bee4089e5aba4f05538123d3579a4fc Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Thu, 30 Apr 2015 09:45:27 +0200 Subject: [PATCH] [OE-Drucken] Started implementation of config parser Signed-off-by: Jim Martens --- oe/Drucken/oeprint/config.py | 30 ++++++++++++++++++++++++++++++ oe/Drucken/oeprint/oeprint.py | 9 +++++++++ 2 files changed, 39 insertions(+) create mode 100644 oe/Drucken/oeprint/config.py diff --git a/oe/Drucken/oeprint/config.py b/oe/Drucken/oeprint/config.py new file mode 100644 index 0000000..be56f14 --- /dev/null +++ b/oe/Drucken/oeprint/config.py @@ -0,0 +1,30 @@ +"""config.py: Provides functions to read the config""" + +__author__ = 'Jim Martens' + +import json + + +class Config: + def __init__(self, config_file): + self.config_file = config_file + self.config_data = self.load_json_file() + + def load_build(self, build): + """ + Loads the data of a particular build + :type build: str + :rtype: object + """ + build_data = self.config_data[build] + return build_data + + def load_json_file(self): + """ + Loads the JSON config file + :type self: oeprint.config.Config + :rtype : object + """ + file = open(self.config_file, 'r', encoding='utf-8') + json_data = json.load(file) + return json_data diff --git a/oe/Drucken/oeprint/oeprint.py b/oe/Drucken/oeprint/oeprint.py index 57e5033..4dd77fd 100755 --- a/oe/Drucken/oeprint/oeprint.py +++ b/oe/Drucken/oeprint/oeprint.py @@ -1,6 +1,13 @@ #!/usr/bin/python3 + +"""oeprint.py: The main file of the print tool""" + +__author__ = 'Jim Martens' + import argparse +from config import Config + def main(): """Main function for oeprint""" @@ -9,6 +16,8 @@ def main(): parser.add_argument('prints', metavar='numberOfPrints', type=int, help='how often the build is printed') parser.add_argument('--printer', dest='printer', help='a valid printer name like d116_sw', default='d116_sw') arguments = parser.parse_args() + config = Config() + build_data = config.load_build(arguments.build) # TODO add actual functionality if __name__ == '__main__':