ckparser 0.2__tar.gz → 0.2.1__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.2/ckparser.egg-info → ckparser-0.2.1}/PKG-INFO +1 -1
- {ckparser-0.2 → ckparser-0.2.1/ckparser.egg-info}/PKG-INFO +1 -1
- {ckparser-0.2 → ckparser-0.2.1}/ckparser.py +22 -12
- {ckparser-0.2 → ckparser-0.2.1}/pyproject.toml +1 -1
- {ckparser-0.2 → ckparser-0.2.1}/LICENSE +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/MANIFEST.in +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/README.md +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/ckparser.egg-info/SOURCES.txt +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/ckparser.egg-info/dependency_links.txt +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/ckparser.egg-info/entry_points.txt +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/ckparser.egg-info/requires.txt +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/ckparser.egg-info/top_level.txt +0 -0
- {ckparser-0.2 → ckparser-0.2.1}/setup.cfg +0 -0
|
@@ -41,7 +41,7 @@ import re
|
|
|
41
41
|
import time
|
|
42
42
|
|
|
43
43
|
# Script version
|
|
44
|
-
__version__ = "0.2"
|
|
44
|
+
__version__ = "0.2.1"
|
|
45
45
|
|
|
46
46
|
# Logger (because logging is awesome)
|
|
47
47
|
logger = logging.getLogger(__name__)
|
|
@@ -64,9 +64,19 @@ class JominiJSONEncoder(json.JSONEncoder):
|
|
|
64
64
|
|
|
65
65
|
def jomini_object_hook(obj):
|
|
66
66
|
# JSON specific decoder for dates
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if isinstance(obj, dict):
|
|
68
|
+
for key, value in obj.items():
|
|
69
|
+
if isinstance(value, str) and regex_date.fullmatch(value):
|
|
70
|
+
obj[key] = convert_date(value) or value
|
|
71
|
+
elif isinstance(value, list):
|
|
72
|
+
obj[key] = jomini_object_hook(value)
|
|
73
|
+
elif isinstance(obj, list):
|
|
74
|
+
for index in range(len(obj)):
|
|
75
|
+
item = obj[index]
|
|
76
|
+
if isinstance(item, str) and regex_date.fullmatch(item):
|
|
77
|
+
obj[index] = convert_date(item) or item
|
|
78
|
+
elif isinstance(item, list):
|
|
79
|
+
obj[index] = jomini_object_hook(item)
|
|
70
80
|
return obj
|
|
71
81
|
|
|
72
82
|
|
|
@@ -277,7 +287,7 @@ def parse_text(text, return_text_on_error=False, comments=False, dates=False, fi
|
|
|
277
287
|
value = val
|
|
278
288
|
elif value:
|
|
279
289
|
# Try to convert value to Python value
|
|
280
|
-
if dates and regex_date.
|
|
290
|
+
if dates and regex_date.fullmatch(value):
|
|
281
291
|
value = convert_date(value) or value
|
|
282
292
|
else:
|
|
283
293
|
try:
|
|
@@ -360,7 +370,7 @@ def parse_text(text, return_text_on_error=False, comments=False, dates=False, fi
|
|
|
360
370
|
node[key] = {"@type": "variable", "@value": value, "@result": result}
|
|
361
371
|
if result is not None and (key.startswith("@") or len(nodes) == 1):
|
|
362
372
|
set_variable(key, result)
|
|
363
|
-
elif result := variables.get(value):
|
|
373
|
+
elif (result := variables.get(value)) is not None:
|
|
364
374
|
if not isinstance(result, str):
|
|
365
375
|
node[key] = {"@type": "variable", "@value": value, "@result": result}
|
|
366
376
|
if result is not None and (key.startswith("@") or len(nodes) == 1):
|
|
@@ -455,7 +465,7 @@ def parse_text(text, return_text_on_error=False, comments=False, dates=False, fi
|
|
|
455
465
|
logger.warning(f"Filename: {filename}")
|
|
456
466
|
logger.warning(f'Value for "{value}" cannot be found (line: {line_number})')
|
|
457
467
|
node.append({"@type": "variable", "@value": item, "@result": result})
|
|
458
|
-
elif dates and regex_date.
|
|
468
|
+
elif dates and regex_date.fullmatch(item):
|
|
459
469
|
item = convert_date(item) or item
|
|
460
470
|
node.append(item)
|
|
461
471
|
else:
|
|
@@ -602,14 +612,14 @@ def parse_all_files(
|
|
|
602
612
|
return success
|
|
603
613
|
|
|
604
614
|
|
|
605
|
-
def parse_all_locales(path, encoding="utf_8_sig", language="english", save=False,
|
|
615
|
+
def parse_all_locales(path, encoding="utf_8_sig", language="english", save=False, output="_locales.json"):
|
|
606
616
|
"""
|
|
607
617
|
Parse all locales strings
|
|
608
618
|
:param path: Path where to find locale files
|
|
609
619
|
:param encoding: Encoding for reading files
|
|
610
620
|
:param language: Target language
|
|
611
621
|
:param save: (default false) save locales in file
|
|
612
|
-
:param
|
|
622
|
+
:param output: locales output file location
|
|
613
623
|
:return: Locales in dictionary
|
|
614
624
|
"""
|
|
615
625
|
locales = {}
|
|
@@ -637,7 +647,7 @@ def parse_all_locales(path, encoding="utf_8_sig", language="english", save=False
|
|
|
637
647
|
key, _, value = match.groups()
|
|
638
648
|
locales[key] = value
|
|
639
649
|
if save:
|
|
640
|
-
with open(
|
|
650
|
+
with open(output, "w") as file:
|
|
641
651
|
json_dump(locales, file, sort_keys=True)
|
|
642
652
|
return locales
|
|
643
653
|
|
|
@@ -813,7 +823,7 @@ def revert_file(path, output_dir=None, encoding="utf_8_sig", base_dir=None, save
|
|
|
813
823
|
base_dir = os.path.dirname(path.replace(base_dir, ""))
|
|
814
824
|
base_dir = base_dir or "."
|
|
815
825
|
with open(path) as file:
|
|
816
|
-
data =
|
|
826
|
+
data = json.load(file)
|
|
817
827
|
filename = os.path.join(str(base_dir), os.path.basename(path))
|
|
818
828
|
logger.debug(f"Reverting {filename}")
|
|
819
829
|
text = revert(data)
|
|
@@ -837,7 +847,7 @@ def load_variables(filepath="_variables.json"):
|
|
|
837
847
|
if not os.path.exists(filepath):
|
|
838
848
|
return
|
|
839
849
|
with open(filepath) as file:
|
|
840
|
-
global_variables =
|
|
850
|
+
global_variables = json.load(file)
|
|
841
851
|
|
|
842
852
|
|
|
843
853
|
def save_variables(filepath="_variables.json"):
|
|
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
|