From ff792776ffa168733f9450d1e66cd2748ab20fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20L=C3=A1n?= Date: Mon, 17 Apr 2023 16:26:11 +0200 Subject: [PATCH] Minor fix of logging --- .gitignore | 11 ++++++++--- src/config_parser.py | 12 +++++++----- src/main.py | 7 ++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 53c71e1..14c831f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,16 @@ /src/__pycache__ -/res /.venv +/.vscode + +/res !/res/examples !/res/examples/* !/res/examples_git/ !/res/examples_git/* + /doc -/.vscode + /conf -!/conf/conf.json +/conf/* +!/conf/db.json + diff --git a/src/config_parser.py b/src/config_parser.py index 44603ec..ea92a65 100644 --- a/src/config_parser.py +++ b/src/config_parser.py @@ -26,6 +26,7 @@ def save_preset(filters, params, preset_name): new_filt = [] for i, filter in enumerate(filt): new_filt.append(filt[filter]) + log.print_message("Saving filters as:", preset_name) # Store preset to database store_to_db(new_filt, preset_name) @@ -45,14 +46,14 @@ def store_to_db(preset, preset_name): preset = json.loads(preset) # If database doesn't exist, create it - if not exists("db.json"): + if not exists("conf/db.json"): log.print_message("Storing preset to database") - with open("db.json", 'w') as db: + with open("conf/db.json", 'w') as db: json.dump(preset, db) else: # If database exists, load it and check if preset already exists try: - with open("db.json", 'r') as db: + with open("conf/db.json", 'r') as db: db_presets = json.load(db) # Empty file is an error, so we don't read it @@ -67,7 +68,7 @@ def store_to_db(preset, preset_name): db_presets.update(preset) # Finally write the updated entries to db file - with open("db.json", 'w') as db: + with open("conf/db.json", 'w') as db: json.dump(db_presets, db, indent=4) @@ -91,10 +92,11 @@ def parse_conf(preset_name, filters, params, config_file): if attribute != "name": params[i][attribute] = value parse_params(params[i]) + log.print_message("Loaded preset:", preset_name, "from file:", config_file) else: - log.print_message("Preset not found") + log.print_message("Warning: Preset not found in config file") def parse_params(params): diff --git a/src/main.py b/src/main.py index 0bc1f8e..abf6ab6 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ import filters as flt import config_parser as cp import log -class app: +class fingerprint_app: '''Main class for the application. ''' @@ -58,7 +58,8 @@ class app: self.params[filter_index][key] = value cp.parse_params(self.params[filter_index]) - # If database flag is set, save filters to database as a new preset + + # If database flag is set, save filters to database as a new preset if self.args.database: cp.save_preset(self.filters, self.params, self.args.database[0]) @@ -724,4 +725,4 @@ class app: self.write_stl_header() -app() +fingerprint_app()