From 70c7259ed4a4c64e519860e15589c3cd810e2815 Mon Sep 17 00:00:00 2001 From: Kozaka Date: Mon, 19 Sep 2022 03:34:49 +0200 Subject: [PATCH] #119 enabled option added for the ConfCDLCImporter --- config/config_data.py | 34 ++++++++++++------ config/config_ini_template.py | 1 + modules/cdlc_importer/load_cdlc_json_file.py | 38 +++++++++++--------- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/config/config_data.py b/config/config_data.py index ca4100f..ec67d2e 100644 --- a/config/config_data.py +++ b/config/config_data.py @@ -31,6 +31,9 @@ "Optionally, use the Tampermonkey script, what could be found under /misc/tampermonkey " \ "with the name: 'RS Playlist enhancer and simplifier.user.js'" + NL + \ "or install it from https://greasyfork.org/en/scripts/440738-rs-playlist-enhancer-and-simplifier" +ERR_MSG_CDLC_IMPORTER = "Please set your directory and file name where the json file is located " + NL + \ + "what contains all the CDLC information (exported from CFSM) what " + NL + \ + "the Servant have to import into the database!" ERR_MSG_RSPL_TAG = "Missing or undefined tag value of the tag '{}' in the config!" + NL + \ "Please create a tag in RS Playlist and enter the value into the config!" + NL + \ "BAD: {}={}" @@ -72,22 +75,25 @@ def __init__(self, conf): class ConfCDLCImporter: def __init__(self, conf): - self.cdlc_import_json_file = conf.get(SECTION_CDLC_IMPORTER, "cdlc_import_json_file") + self.enabled = conf.get_bool(SECTION_CDLC_IMPORTER, KEY_ENABLED) + self.cdlc_import_json_file = validate_and_get_cdlc_import_json_file( + conf.get(SECTION_CDLC_IMPORTER, "cdlc_import_json_file")) class ConfSongLoader: def __init__(self, conf): self.enabled = conf.get_bool(SECTION_SONG_LOADER, KEY_ENABLED) - self.twitch_channel = conf.get(SECTION_SONG_LOADER, "twitch_channel") - self.phpsessid = validate_and_get_phpsessid(conf.get(SECTION_SONG_LOADER, "PHPSESSID")) - self.cdlc_dir = conf.get(SECTION_SONG_LOADER, "cdlc_dir") - self.rspl_tags = RSPLTags(conf) - self.cfsm_file_name = conf.get(SECTION_SONG_LOADER, "cfsm_file_name") - self.cdlc_archive_dir = conf.get(SECTION_SONG_LOADER, "cdlc_archive_dir") - self.destination_directory = conf.get(SECTION_FILE_MANAGER, "destination_directory") - self.rocksmith_cdlc_dir = conf.get(SECTION_SONG_LOADER, "rocksmith_cdlc_dir") - self.cdlc_import_json_file = conf.get(SECTION_SONG_LOADER, "cdlc_import_json_file") - self.allow_load_when_in_game = conf.get_bool(SECTION_SONG_LOADER, "allow_load_when_in_game") + if self.enabled: + self.twitch_channel = conf.get(SECTION_SONG_LOADER, "twitch_channel") + self.phpsessid = validate_and_get_phpsessid(conf.get(SECTION_SONG_LOADER, "PHPSESSID")) + self.cdlc_dir = conf.get(SECTION_SONG_LOADER, "cdlc_dir") + self.rspl_tags = RSPLTags(conf) + self.cfsm_file_name = conf.get(SECTION_SONG_LOADER, "cfsm_file_name") + self.cdlc_archive_dir = conf.get(SECTION_SONG_LOADER, "cdlc_archive_dir") + self.destination_directory = conf.get(SECTION_FILE_MANAGER, "destination_directory") + self.rocksmith_cdlc_dir = conf.get(SECTION_SONG_LOADER, "rocksmith_cdlc_dir") + self.cdlc_import_json_file = conf.get(SECTION_SONG_LOADER, "cdlc_import_json_file") + self.allow_load_when_in_game = conf.get_bool(SECTION_SONG_LOADER, "allow_load_when_in_game") class RSPLTags: @@ -120,6 +126,12 @@ def validate_and_get_phpsessid(phpsessid): return phpsessid +def validate_and_get_cdlc_import_json_file(cdlc_import_json_file): + if cdlc_import_json_file is None or cdlc_import_json_file.startswith('" diff --git a/modules/cdlc_importer/load_cdlc_json_file.py b/modules/cdlc_importer/load_cdlc_json_file.py index 35cebc8..fe1f7de 100644 --- a/modules/cdlc_importer/load_cdlc_json_file.py +++ b/modules/cdlc_importer/load_cdlc_json_file.py @@ -18,26 +18,30 @@ class CDLCImporter: def __init__(self, config_data, db): - self.cdlc_import_json_file = config_data.cdlc_importer.cdlc_import_json_file + self.enabled = config_data.cdlc_importer.enabled + if self.enabled: + self.cdlc_import_json_file = config_data.cdlc_importer.cdlc_import_json_file + # TODO should be behind the enabled check? self.db = db def load(self): - logger.log("-----------------------------------", MODULE_NAME) - logger.warning("Importing CDLC files from CFSM json file...", MODULE_NAME) - - try: - self.init_db() - except Exception as e: - logger.error("Database init error: {0}".format(e)) - raise e - - try: - self.import_cdlc_files() - except Exception as e: - logger.error("Could not import CDLCs to the Database: {0}".format(e)) - raise e - - logger.log("-----------------------------------", MODULE_NAME) + if self.enabled: + logger.log("-----------------------------------", MODULE_NAME) + logger.warning("Importing CDLC files from CFSM json file...", MODULE_NAME) + + try: + self.init_db() + except Exception as e: + logger.error("Database init error: {0}".format(e)) + raise e + + try: + self.import_cdlc_files() + except Exception as e: + logger.error("Could not import CDLCs to the Database: {0}".format(e)) + raise e + + logger.log("-----------------------------------", MODULE_NAME) def create_tables(self): cursor = self.db.cursor()