Update fluentscan.py

added: initial error checking support, detecting of unused entries
This commit is contained in:
xstraok 2023-04-17 13:14:03 -04:00 committed by GitHub
parent f9bf0accf8
commit 2739006b52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,17 @@
import os import os
import sys import sys
import glob
valid_args=["diff","unused"]
if len(sys.argv)<3 or len(sys.argv) == 0:
print("missing arguments")
sys.exit()
if sys.argv[2] not in valid_args:
print(f"invalid argument:{sys.argv[2]}")
sys.exit()
path = "assets/locales/" + sys.argv[1] + "/" path = "assets/locales/" + sys.argv[1] + "/"
@ -48,8 +59,27 @@ for filename in os.listdir("assets/locales/en"):
# TODO: why modified is not used? # TODO: why modified is not used?
added, removed, modified, same = dict_compare(expected, expected2) added, removed, modified, same = dict_compare(expected, expected2)
if sys.argv[2] == "unused" or sys.argv[2] == "missing":
files = glob.glob("src/" + '/**/*.rs', recursive=True)
used=[]
for i in files:
with open(i,"r") as script:
text=script.read()
if sys.argv[2] == "unused":
for j in expected:
if '"'+j+'"' in text:
used.append(j)
#elif sys.argv[2] == "missing":
#for j in text.split():
#find all cases of tr(
if added or removed or same: for i in expected:
if i not in used:
print(f"{i} is not used ({locale_file.name})")
continue
if (added or removed or same) and sys.argv[2] == "diff":
print(f"[{created_locale.name[15:]}]") print(f"[{created_locale.name[15:]}]")
if added: if added:
@ -72,3 +102,5 @@ for filename in os.listdir("assets/locales/en"):
print(f" {i} = {expected[i]}") print(f" {i} = {expected[i]}")
print("") print("")