All panels and lex files updating now
This commit is contained in:
parent
2eb8c32e30
commit
a54c9f1c12
112
lex_scan.py
112
lex_scan.py
@ -68,55 +68,83 @@ def extract_title_prefix(controller_path):
|
|||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return prefix
|
return prefix
|
||||||
|
|
||||||
|
def find_matching_files_variable_part(input_string, directory):
|
||||||
|
# Extract the first alphanumeric part from the input string
|
||||||
|
match = re.match(r"([A-Za-z0-9]+)", input_string)
|
||||||
|
if not match:
|
||||||
|
return []
|
||||||
|
variable_part = match.group(1)
|
||||||
|
|
||||||
|
# Try matching the full variable_part, then progressively remove last characters
|
||||||
|
for length in range(len(variable_part), 1, -1):
|
||||||
|
sub_part = variable_part[:length]
|
||||||
|
matching_files = []
|
||||||
|
for fname in os.listdir(directory):
|
||||||
|
name, ext = os.path.splitext(fname)
|
||||||
|
if name.startswith(sub_part): # match with extra characters allowed
|
||||||
|
matching_files.append(os.path.join(directory, fname))
|
||||||
|
if matching_files:
|
||||||
|
return matching_files
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def scan_application_files(system, panel, prefix, scan_general=False):
|
def scan_application_files(system, panel, prefix, scan_general=False):
|
||||||
extracted_strings = {}
|
extracted_strings = {}
|
||||||
|
|
||||||
full_base_path = get_full_base_path(system)
|
|
||||||
|
|
||||||
# Controller file
|
full_base_path = get_full_base_path(system)
|
||||||
controller_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}.pm")
|
|
||||||
logger.info(f"Scanning controller file: {controller_path}")
|
|
||||||
scan_file_for_lexical_strings(controller_path, prefix, extracted_strings, scan_general)
|
|
||||||
|
|
||||||
#Controller file custom code
|
|
||||||
controller_custom_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}-Custom.pm")
|
|
||||||
logger.info(f"Scanning Custom controller file: {controller_custom_path}")
|
|
||||||
scan_file_for_lexical_strings(controller_custom_path, prefix, extracted_strings, scan_general)
|
|
||||||
|
|
||||||
|
|
||||||
# Template files
|
# Controller file
|
||||||
themes = ["default", "AdminLTE"]
|
controller_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}.pm")
|
||||||
for theme in themes:
|
logger.info(f"Scanning controller file: {controller_path}")
|
||||||
template_base_path = os.path.join(full_base_path, "themes", theme, "templates")
|
scan_file_for_lexical_strings(controller_path, prefix, extracted_strings, scan_general)
|
||||||
panel_template_path = os.path.join(template_base_path, f"{panel.lower()}.html.ep")
|
|
||||||
logger.info(f"Scanning panel template file: {panel_template_path}")
|
|
||||||
scan_file_for_lexical_strings(panel_template_path, prefix, extracted_strings, scan_general)
|
|
||||||
|
|
||||||
# Scan partials
|
#Controller file custom code
|
||||||
partials_dir = os.path.join(template_base_path, "partials")
|
controller_custom_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}-Custom.pm")
|
||||||
if os.path.exists(partials_dir):
|
logger.info(f"Scanning Custom controller file: {controller_custom_path}")
|
||||||
for filename in os.listdir(partials_dir):
|
scan_file_for_lexical_strings(controller_custom_path, prefix, extracted_strings, scan_general)
|
||||||
# Only scan partial files that match the pattern _<prefix>_<anything>.html.ep
|
|
||||||
if filename.startswith(f"_{prefix.lower()}_") and filename.endswith(".html.ep"):
|
|
||||||
partial_path = os.path.join(partials_dir, filename)
|
|
||||||
logger.info(f"Scanning partial template file: {partial_path}")
|
|
||||||
scan_file_for_lexical_strings(partial_path, prefix, extracted_strings, scan_general)
|
|
||||||
|
|
||||||
# Deduplicate lists of dicts in extracted_strings
|
# Template files
|
||||||
for key, value in extracted_strings.items():
|
themes = ["default", "AdminLTE"]
|
||||||
if isinstance(value, list) and value and isinstance(value[0], dict):
|
for theme in themes:
|
||||||
# Deduplicate list of dicts using JSON serialization
|
template_base_path = os.path.join(full_base_path, "themes", theme, "templates")
|
||||||
seen = set()
|
if panel in ['Backup','Yum','Bugreport']:
|
||||||
deduped = []
|
#find the extra layout type files that these use (they do not have partials)
|
||||||
for d in value:
|
template_files = find_matching_files_variable_part(panel.lower(),template_base_path)
|
||||||
ser = json.dumps(d, sort_keys=True)
|
# print(f"Matching template files: {panel.lower()!r} -> Matches: {[os.path.basename(m) for m in template_files]}")
|
||||||
if ser not in seen:
|
for file_path in template_files:
|
||||||
seen.add(ser)
|
panel_template_path = os.path.join(template_base_path, f"{file_path}")
|
||||||
deduped.append(d)
|
logger.warning(f"Scanning panel template file: {panel_template_path}")
|
||||||
extracted_strings[key] = deduped
|
scan_file_for_lexical_strings(panel_template_path, prefix, extracted_strings, scan_general)
|
||||||
|
else:
|
||||||
|
panel_template_path = os.path.join(template_base_path, f"{panel.lower()}.html.ep")
|
||||||
|
logger.info(f"Scanning panel template file: {panel_template_path}")
|
||||||
|
scan_file_for_lexical_strings(panel_template_path, prefix, extracted_strings, scan_general)
|
||||||
|
|
||||||
return extracted_strings
|
# Scan partials
|
||||||
|
partials_dir = os.path.join(template_base_path, "partials")
|
||||||
|
if os.path.exists(partials_dir):
|
||||||
|
for filename in os.listdir(partials_dir):
|
||||||
|
# Only scan partial files that match the pattern _<prefix>_<anything>.html.ep
|
||||||
|
if filename.startswith(f"_{prefix.lower()}_") and filename.endswith(".html.ep"):
|
||||||
|
partial_path = os.path.join(partials_dir, filename)
|
||||||
|
logger.info(f"Scanning partial template file: {partial_path}")
|
||||||
|
scan_file_for_lexical_strings(partial_path, prefix, extracted_strings, scan_general)
|
||||||
|
|
||||||
|
# Deduplicate lists of dicts in extracted_strings
|
||||||
|
for key, value in extracted_strings.items():
|
||||||
|
if isinstance(value, list) and value and isinstance(value[0], dict):
|
||||||
|
# Deduplicate list of dicts using JSON serialization
|
||||||
|
seen = set()
|
||||||
|
deduped = []
|
||||||
|
for d in value:
|
||||||
|
ser = json.dumps(d, sort_keys=True)
|
||||||
|
if ser not in seen:
|
||||||
|
seen.add(ser)
|
||||||
|
deduped.append(d)
|
||||||
|
extracted_strings[key] = deduped
|
||||||
|
|
||||||
|
return extracted_strings
|
||||||
|
|
||||||
def scan_file_for_lexical_strings(filepath, prefix, extracted_strings_dict, scan_general):
|
def scan_file_for_lexical_strings(filepath, prefix, extracted_strings_dict, scan_general):
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user