Skip to content

Commit

Permalink
#119 enabled option added for the ConfCDLCImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
kozaka-tv committed Sep 19, 2022
1 parent 3795ed3 commit 70c7259
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
34 changes: 23 additions & 11 deletions config/config_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}={}"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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('<Enter your'):
raise ConfigError(ERR_MSG_CDLC_IMPORTER)
return cdlc_import_json_file


def get_tag(conf, tag_name):
value = conf.get(SECTION_SONG_LOADER, tag_name)
if value is None or value.startswith('<Create a tag in RS Playlist'):
Expand Down
1 change: 1 addition & 0 deletions config/config_ini_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"using_cfsm": False,
},
"CDLCImporter": {
"enabled": False,
"cdlc_import_json_file": "<Enter your directory, where do you want put your json file from CFSM, "
"what contains all your CDLC files need to be imported into the Servant database"
"You have to export from CFSM only the delta, only the newly enumerated songs>"
Expand Down
38 changes: 21 additions & 17 deletions modules/cdlc_importer/load_cdlc_json_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 70c7259

Please sign in to comment.