All panels and lex files updating now

This commit is contained in:
Brian Read 2025-07-08 09:49:14 +01:00
parent 2eb8c32e30
commit a54c9f1c12

View File

@ -69,54 +69,82 @@ 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) full_base_path = get_full_base_path(system)
# Controller file # Controller file
controller_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}.pm") controller_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}.pm")
logger.info(f"Scanning controller file: {controller_path}") logger.info(f"Scanning controller file: {controller_path}")
scan_file_for_lexical_strings(controller_path, prefix, extracted_strings, scan_general) scan_file_for_lexical_strings(controller_path, prefix, extracted_strings, scan_general)
#Controller file custom code #Controller file custom code
controller_custom_path = os.path.join(full_base_path, "lib/SrvMngr/Controller", f"{panel}-Custom.pm") 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}") logger.info(f"Scanning Custom controller file: {controller_custom_path}")
scan_file_for_lexical_strings(controller_custom_path, prefix, extracted_strings, scan_general) scan_file_for_lexical_strings(controller_custom_path, prefix, extracted_strings, scan_general)
# Template files
themes = ["default", "AdminLTE"]
for theme in themes:
template_base_path = os.path.join(full_base_path, "themes", theme, "templates")
if panel in ['Backup','Yum','Bugreport']:
#find the extra layout type files that these use (they do not have partials)
template_files = find_matching_files_variable_part(panel.lower(),template_base_path)
# print(f"Matching template files: {panel.lower()!r} -> Matches: {[os.path.basename(m) for m in template_files]}")
for file_path in template_files:
panel_template_path = os.path.join(template_base_path, f"{file_path}")
logger.warning(f"Scanning panel template file: {panel_template_path}")
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)
# Template files # Scan partials
themes = ["default", "AdminLTE"] partials_dir = os.path.join(template_base_path, "partials")
for theme in themes: if os.path.exists(partials_dir):
template_base_path = os.path.join(full_base_path, "themes", theme, "templates") for filename in os.listdir(partials_dir):
panel_template_path = os.path.join(template_base_path, f"{panel.lower()}.html.ep") # Only scan partial files that match the pattern _<prefix>_<anything>.html.ep
logger.info(f"Scanning panel template file: {panel_template_path}") if filename.startswith(f"_{prefix.lower()}_") and filename.endswith(".html.ep"):
scan_file_for_lexical_strings(panel_template_path, prefix, extracted_strings, scan_general) 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)
# Scan partials # Deduplicate lists of dicts in extracted_strings
partials_dir = os.path.join(template_base_path, "partials") for key, value in extracted_strings.items():
if os.path.exists(partials_dir): if isinstance(value, list) and value and isinstance(value[0], dict):
for filename in os.listdir(partials_dir): # Deduplicate list of dicts using JSON serialization
# Only scan partial files that match the pattern _<prefix>_<anything>.html.ep seen = set()
if filename.startswith(f"_{prefix.lower()}_") and filename.endswith(".html.ep"): deduped = []
partial_path = os.path.join(partials_dir, filename) for d in value:
logger.info(f"Scanning partial template file: {partial_path}") ser = json.dumps(d, sort_keys=True)
scan_file_for_lexical_strings(partial_path, prefix, extracted_strings, scan_general) if ser not in seen:
seen.add(ser)
deduped.append(d)
extracted_strings[key] = deduped
# Deduplicate lists of dicts in extracted_strings return 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):