ckparser 0.3.3__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ckparser-0.3.3/ckparser.egg-info → ckparser-0.3.5}/PKG-INFO +1 -1
- {ckparser-0.3.3 → ckparser-0.3.5/ckparser.egg-info}/PKG-INFO +1 -1
- {ckparser-0.3.3 → ckparser-0.3.5}/ckparser.py +23 -9
- {ckparser-0.3.3 → ckparser-0.3.5}/pyproject.toml +1 -1
- {ckparser-0.3.3 → ckparser-0.3.5}/LICENSE +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/MANIFEST.in +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/README.md +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/ckparser.egg-info/SOURCES.txt +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/ckparser.egg-info/dependency_links.txt +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/ckparser.egg-info/entry_points.txt +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/ckparser.egg-info/requires.txt +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/ckparser.egg-info/top_level.txt +0 -0
- {ckparser-0.3.3 → ckparser-0.3.5}/setup.cfg +0 -0
|
@@ -41,7 +41,7 @@ import re
|
|
|
41
41
|
import time
|
|
42
42
|
|
|
43
43
|
# Script version
|
|
44
|
-
__version__ = "0.3.
|
|
44
|
+
__version__ = "0.3.5"
|
|
45
45
|
|
|
46
46
|
# Logger (because logging is awesome)
|
|
47
47
|
logger = logging.getLogger(__name__)
|
|
@@ -116,7 +116,7 @@ regex_inline = re.compile(r"([^\s\"]+\s*[?!<=>]+\s*(([^@\"]\[?[^\s]+\]?)|(\"[^\"
|
|
|
116
116
|
# Regex to parse blocks with bracket below the key/operator
|
|
117
117
|
regex_block = re.compile(r"(\s*([?!<=>]+)\s+\{)|(\s+\s*([?!<=>])+\s*\{)", re.MULTILINE)
|
|
118
118
|
# Regex to parse lines with format key=value
|
|
119
|
-
regex_line = re.compile(r"\"?(?P<key>[^\s\"]+)\"?\s*(?P<operator>[?!<=>]+)\s*(list\s*)?(?P<value>.*)")
|
|
119
|
+
regex_line = re.compile(r"\"?(?P<key>[^\s\"?!<=>]+)\"?\s*(?P<operator>[?!<=>]+)\s*(list\s*)?(?P<value>.*)")
|
|
120
120
|
# Regex to parse independent items in a list
|
|
121
121
|
regex_item = re.compile(r"(\"[^\"]+\"|[\d\.]+|[^\s]+)")
|
|
122
122
|
# Regex to parse dates
|
|
@@ -294,7 +294,7 @@ def parse_text(
|
|
|
294
294
|
if not isinstance(node[key], list):
|
|
295
295
|
node[key] = [node[key]]
|
|
296
296
|
if operator != "=":
|
|
297
|
-
node[key].append({"@operator": operator, "@value": item})
|
|
297
|
+
node[key].append({"@type": "operator", "@operator": operator, "@value": item})
|
|
298
298
|
else:
|
|
299
299
|
node[key].append(item)
|
|
300
300
|
# If this block name must be forced as list
|
|
@@ -303,7 +303,7 @@ def parse_text(
|
|
|
303
303
|
elif isinstance(node, list): # Only for on_actions...
|
|
304
304
|
node.append(item)
|
|
305
305
|
elif operator != "=":
|
|
306
|
-
node[key] = {"@operator": operator, "@value": item}
|
|
306
|
+
node[key] = {"@type": "operator", "@operator": operator, "@value": item}
|
|
307
307
|
else:
|
|
308
308
|
node[key] = item
|
|
309
309
|
# Change current node for next lines
|
|
@@ -340,7 +340,7 @@ def parse_text(
|
|
|
340
340
|
else:
|
|
341
341
|
# If operator is not equal
|
|
342
342
|
if operator != "=":
|
|
343
|
-
node[key] = {"@operator": operator, "@value": value}
|
|
343
|
+
node[key] = {"@type": "operator", "@operator": operator, "@value": value}
|
|
344
344
|
if isinstance(value, str):
|
|
345
345
|
if value == "":
|
|
346
346
|
node[key]["@value"] = item = {}
|
|
@@ -724,6 +724,14 @@ def objectify(data, name="Object", default=None):
|
|
|
724
724
|
:return: object-like dictionary
|
|
725
725
|
"""
|
|
726
726
|
|
|
727
|
+
def clean(item):
|
|
728
|
+
if isinstance(item, dict):
|
|
729
|
+
return {key: clean(value) for key, value in item.items() if not key.startswith("_")}
|
|
730
|
+
elif isinstance(item, list):
|
|
731
|
+
return [clean(value) for value in item]
|
|
732
|
+
else:
|
|
733
|
+
return item
|
|
734
|
+
|
|
727
735
|
def _getattr(s, k):
|
|
728
736
|
try:
|
|
729
737
|
object.__getattribute__(s, k)
|
|
@@ -734,12 +742,17 @@ def objectify(data, name="Object", default=None):
|
|
|
734
742
|
return [
|
|
735
743
|
objectify(item)
|
|
736
744
|
for item in data
|
|
737
|
-
if not (isinstance(item, str) and item.startswith("
|
|
745
|
+
if not (isinstance(item, str) and item.startswith("#") and item.endswith("#"))
|
|
738
746
|
]
|
|
739
747
|
elif isinstance(data, dict):
|
|
740
748
|
name = (data.get("@type") or name).title()
|
|
741
749
|
slots = set()
|
|
742
|
-
attrs = dict(
|
|
750
|
+
attrs = dict(
|
|
751
|
+
__getattr__=lambda s, k: _getattr(s, k),
|
|
752
|
+
__slots__=slots,
|
|
753
|
+
__str__=lambda s: str(clean(s)),
|
|
754
|
+
__repr__=lambda s: repr(clean(s)),
|
|
755
|
+
)
|
|
743
756
|
subdata = {}
|
|
744
757
|
for key, value in data.items():
|
|
745
758
|
if key.startswith("#"):
|
|
@@ -747,7 +760,8 @@ def objectify(data, name="Object", default=None):
|
|
|
747
760
|
skey = key.replace("@", "_").replace(":", "_")
|
|
748
761
|
if match := regex_date.match(skey):
|
|
749
762
|
skey = "_".join(match.groups())
|
|
750
|
-
|
|
763
|
+
if not skey.startswith("_"):
|
|
764
|
+
skey = f"_{skey}" if key != skey or key[0].isdigit() else skey
|
|
751
765
|
slots.add(skey)
|
|
752
766
|
if isinstance(value, (list, dict)):
|
|
753
767
|
subdata[key] = subdata[skey] = objectify(value)
|
|
@@ -973,7 +987,7 @@ def main():
|
|
|
973
987
|
Command-line main entrypoint
|
|
974
988
|
"""
|
|
975
989
|
parser = argparse.ArgumentParser(
|
|
976
|
-
description="Parse data from Paradox files in JSON or revert JSON files to Paradox format"
|
|
990
|
+
description=f"Parse data from Paradox files in JSON or revert JSON files to Paradox format ({__version__})"
|
|
977
991
|
)
|
|
978
992
|
parser.add_argument("path", type=str, help="path to a file or a directory to parse/revert")
|
|
979
993
|
parser.add_argument("--encoding", type=str, help="encoding for reading/writing files")
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ckparser"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.5"
|
|
8
8
|
description = "Parse Paradox Jomini data files to Python/JSON and revert them back experimentally."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|