mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-14 06:12:31 +03:00
Added the ability to compare to another LANG file
This commit is contained in:
parent
5bdbf334ae
commit
dbea29194b
@ -1,6 +1,8 @@
|
|||||||
"""Search all given paths recursively for localised string calls."""
|
"""Search all given paths recursively for localised string calls."""
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import itertools
|
||||||
import ast
|
import ast
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
@ -26,6 +28,8 @@ def get_arg(call: ast.Call) -> str:
|
|||||||
arg = call.args[0]
|
arg = call.args[0]
|
||||||
if isinstance(arg, ast.Constant):
|
if isinstance(arg, ast.Constant):
|
||||||
return arg.value
|
return arg.value
|
||||||
|
elif isinstance(arg, ast.Name):
|
||||||
|
return f"VARIABLE! CHECK CODE! {arg.id}"
|
||||||
else:
|
else:
|
||||||
return f'Unknown! {type(arg)=} {ast.dump(arg)} ||| {ast.unparse(arg)}'
|
return f'Unknown! {type(arg)=} {ast.dump(arg)} ||| {ast.unparse(arg)}'
|
||||||
|
|
||||||
@ -81,6 +85,19 @@ def scan_directory(path: pathlib.Path, skip: list[pathlib.Path] = None) -> dict[
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def parse_template(path) -> set[str]:
|
||||||
|
lang_re = re.compile(r'\s*"((?:[^"]|(?:\"))+)"\s*=\s*"((?:[^"]|(?:\"))+)"\s*;\s*$')
|
||||||
|
out = set()
|
||||||
|
for line in pathlib.Path(path).read_text().splitlines():
|
||||||
|
match = lang_re.match(line)
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
if match.group(1) != "!Language":
|
||||||
|
out.add(match.group(1))
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--directory", help="Directory to search from", default=".")
|
parser.add_argument("--directory", help="Directory to search from", default=".")
|
||||||
@ -88,13 +105,29 @@ if __name__ == '__main__':
|
|||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
group.add_argument('--json', action='store_true', help='JSON output')
|
group.add_argument('--json', action='store_true', help='JSON output')
|
||||||
group.add_argument('--lang', action='store_true', help='lang file outpot')
|
group.add_argument('--lang', action='store_true', help='lang file outpot')
|
||||||
|
group.add_argument('--compare-lang')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
directory = pathlib.Path(args.directory)
|
directory = pathlib.Path(args.directory)
|
||||||
res = scan_directory(directory, [pathlib.Path(p) for p in args.ignore])
|
res = scan_directory(directory, [pathlib.Path(p) for p in args.ignore])
|
||||||
|
|
||||||
if args.json:
|
if args.compare_lang is not None and len(args.compare_lang) > 0:
|
||||||
|
seen = set()
|
||||||
|
template = parse_template(args.compare_lang)
|
||||||
|
|
||||||
|
for file, calls in res.items():
|
||||||
|
for c in calls:
|
||||||
|
arg = get_arg(c)
|
||||||
|
if arg in template:
|
||||||
|
seen.add(arg)
|
||||||
|
else:
|
||||||
|
print(f"NEW! {file}:{c.lineno}: {arg!r}")
|
||||||
|
|
||||||
|
for old in set(template) ^ seen:
|
||||||
|
print(f"No longer used: {old}")
|
||||||
|
|
||||||
|
elif args.json:
|
||||||
to_print = json.dumps({
|
to_print = json.dumps({
|
||||||
str(path): [{
|
str(path): [{
|
||||||
"string": get_arg(c),
|
"string": get_arg(c),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user