From 2aaacd7a810be3aa7e13d829df03e1f154b1945b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Barroso=20Galindo?= Date: Fri, 11 Nov 2022 23:59:01 +0100 Subject: [PATCH] Adding setname folders from MGL --- .github/calculate_db.py | 35 ++++++++++++++++++++++++++++++++++ .github/update_distribution.sh | 30 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/.github/calculate_db.py b/.github/calculate_db.py index 63c620b5d..409a0527d 100755 --- a/.github/calculate_db.py +++ b/.github/calculate_db.py @@ -220,6 +220,13 @@ class Tags: if nodates in ['gba2p', 'gameboy2p']: self._append(result, self._use_term('handheld2p')) + elif suffix == '.mgl': + self._append(result, self._use_term('cores')) + self._append(result, self._use_term(stem)) + rbf, setname = read_mgl_fields(path) + if rbf is not None: + self._append(result, self._use_term(Path(rbf).name)) + if parent == 'games': first_level = path.parts[1].lower() self._append(result, self._use_term(first_level)) @@ -877,6 +884,34 @@ def read_mra_fields(mra_path): return rbf, list(zips) +def read_mgl_fields(mgl_path): + rbf = None + setname = None + + try: + context = et_iterparse(str(mgl_path), events=("start",)) + for _, elem in context: + elem_tag = elem.tag.lower() + if elem_tag == 'rbf': + if rbf is not None: + print('WARNING! Duplicated rbf tag on file %s, first value %s, later value %s' % (str(mgl_path),rbf,elem.text)) + continue + if elem.text is None: + continue + rbf = elem.text.strip().lower() + elif setname == 'rom': + if setname is not None: + print('WARNING! Duplicated setname tag on file %s, first value %s, later value %s' % (str(mgl_path),setname,elem.text)) + continue + if elem.text is None: + continue + setname = elem.text.strip().lower() + except xml.etree.ElementTree.ParseError as e: + print('ERROR: Defect XML for mgl file: ' + str(mgl_path)) + raise e + + return rbf, setname + if __name__ == '__main__': dryrun = len(sys.argv) == 2 and sys.argv[1] == '-d' try: diff --git a/.github/update_distribution.sh b/.github/update_distribution.sh index df6fc3ead..d351cc6cc 100755 --- a/.github/update_distribution.sh +++ b/.github/update_distribution.sh @@ -798,6 +798,18 @@ mra_files() { } game_folders() { + local TMP_FOLDER="${1}" + for folder in $(game_folders_from_conf_str "${TMP_FOLDER}") ; do + echo "${folder}" + for file in $(files_with_no_date "${TMP_FOLDER}/releases") ; do + if is_mgl_file "${file}" ; then + extract_from_setname_tag "${file}" + fi + done + done +} + +game_folders_from_conf_str() { local FOLDER="${1}" pushd "${FOLDER}" > /dev/null 2>&1 extract_from_conf_str "localparam" @@ -805,6 +817,7 @@ game_folders() { popd > /dev/null 2>&1 } + extract_from_conf_str() { local PARAMETER="${1}" for conf_line in $(grep -H * -e "\s*${PARAMETER}\s\s*CONF_STR1\{0,1\}\s*=" 2> /dev/null) ; do @@ -819,6 +832,23 @@ extract_from_conf_str() { done } +extract_from_setname_tag() { + local FILE="${1}" + source <(python3 -c " +import xml.etree.ElementTree as ET +try: + context = ET.iterparse('${FILE}', events=('start',)) + for _, elem in context: + elem_tag = elem.tag.lower() + if elem_tag == 'setname': + if elem.text is None: + continue + print('echo %s' % elem.text.strip()) +except ET.ParseError as e: + pass +") +} + if [[ "${BASH_SOURCE[0]}" == "${0}" ]] ; then update_distribution "${1}" "${2:-}" fi