Add list of singleton pamraeters to custom, refine letsencrypt json
This commit is contained in:
39
sm2gen.py
39
sm2gen.py
@@ -399,6 +399,35 @@ def convert_lex_to_dict(pairs_string):
|
||||
formatted_dict = [{"id": key, "text": value} for key, value in data_dict.items()]
|
||||
return formatted_dict
|
||||
|
||||
def extract_input_fields(json_data, value_type):
|
||||
result = {}
|
||||
|
||||
# Pattern to identify and strip the specified value type and surrounding brackets
|
||||
pattern = re.compile(rf"{value_type}\((.*?)\)")
|
||||
|
||||
# Iterate over each panel in the 'html' array
|
||||
for panel in json_data['html']:
|
||||
panel_name = panel['route']
|
||||
# Initialize an empty list for each panel
|
||||
result[panel_name] = []
|
||||
|
||||
# Iterate over each item in the panel
|
||||
for key, value in panel.items():
|
||||
if key.startswith('Input') and isinstance(value, dict):
|
||||
if value.get('Type').lower() in ['readonlytext', 'text']:
|
||||
input_value = value.get('Value', '')
|
||||
# Match and extract the value without the value_type and parentheses
|
||||
match = pattern.search(input_value)
|
||||
if match:
|
||||
# Extract the inner content of the matching pattern
|
||||
clean_value = match.group(1)
|
||||
# Take out any double quotes
|
||||
clean_value = clean_value.replace('"','')
|
||||
# Add the clean value to the list for the current panel
|
||||
result[panel_name].append(clean_value)
|
||||
|
||||
# Note: Empty lists are not removed, so all panels will be present in the result
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -526,16 +555,16 @@ if __name__ == "__main__":
|
||||
# print(strVersion,tablecontrols,routes)
|
||||
|
||||
# Generate controller file
|
||||
dbfields = [] #extract_input_fields(json5_dict, 'db') # Params which correspond to Db fields - TBD
|
||||
try:
|
||||
controller_template = PageTemplateFile(
|
||||
"Templates/controller.pm.tem", CHAMELEON_DEBUG="true"
|
||||
)
|
||||
dbentries = get_db_fields() # Params which correspond to Db fields
|
||||
try:
|
||||
controller_perl = controller_template.render(
|
||||
version=strVersion,
|
||||
tablecontrols=tablecontrols,
|
||||
dbentries=dbentries,
|
||||
dbfields=dbfields,
|
||||
**json5_dict,
|
||||
panels=routes,
|
||||
lcPackageName=json5_dict["PackageName"].lower(),
|
||||
@@ -551,9 +580,13 @@ if __name__ == "__main__":
|
||||
# Generate Custom controller file
|
||||
try:
|
||||
custom_controller_template = PageTemplateFile("Templates/custom.pm.tem")
|
||||
fields = extract_input_fields(json5_dict, 'stash') # Params which correspond to singleton values
|
||||
#flatfields = flatten_hash_of_lists(fields)
|
||||
#print(fields)
|
||||
#quit(0)
|
||||
try:
|
||||
custom_controller_perl = custom_controller_template.render(
|
||||
version=strVersion, panels=routes, tablecontrols=tablecontrols
|
||||
version=strVersion, panels=routes, tablecontrols=tablecontrols, fields=fields, dbfields=dbfields
|
||||
)
|
||||
# We must be careful to not overwrite the custom file if the developer has already written to it - TBD
|
||||
with open(custom_controller_file, "w") as file:
|
||||
|
Reference in New Issue
Block a user