diff --git a/Targets/Nfsshare.pm b/Targets/Nfsshare.pm
index 18b23bb..67de87a 100644
--- a/Targets/Nfsshare.pm
+++ b/Targets/Nfsshare.pm
@@ -87,12 +87,12 @@ sub do_update {
if ($trt eq 'PARAMS'){
#Validate for panel PARAMS
- # set $ret = $c->l(''Error message') if invalid'
+ # set $ret = $c->l('Error message') if invalid'
}
if ($trt eq 'TABLE'){
#Validate for panel TABLE
- # set $ret = $c->l(''Error message') if invalid'
+ # set $ret = $c->l('Error message') if invalid'
}
if ($ret ne "ok"){
diff --git a/Targets/_nfs_PARAMS.html.ep b/Targets/_nfs_PARAMS.html.ep
index 1d901a5..32d994d 100644
--- a/Targets/_nfs_PARAMS.html.ep
+++ b/Targets/_nfs_PARAMS.html.ep
@@ -15,13 +15,13 @@
%# Inputs etc in here.
Manage NFS Ibay settings:
These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays/$(STASH:ibayname)/files
- %=l('Information Bay name'), class => 'label'
+ %=l('nfs_Information Bay name'), class => 'label'
%= stash("IbayName"), class => 'data'
- %=l('Share owner Group')
+ %=l('nfs_Share owner Group')
% my @ShareOwnerGrp_options = ['Write = admin, Read = group', 'Write = group, Read = everyone', 'Write = group, Read = group'];
% param 'ShareOwnerGrp' => $nfs_data->{ShareOwnerGrp} unless param 'ShareOwnerGrp';
@@ -29,7 +29,7 @@
- %=l('Enable the NFS Share')
+ %=l('nfs_Enable the NFS Share')
% my @EnableNFSshare_options = ['Disabled', 'Enabled'];
% param 'EnableNFSshare' => $nfs_data->{EnableNFSshare} unless param 'EnableNFSshare';
@@ -37,7 +37,7 @@
- %=l('EnableShare on local network')
+ %=l('nfs_EnableShare on local network')
% my @ShareOnLocalNetwork_options = ['Disabled', 'Enabled'];
% param 'ShareOnLocalNetwork' => $nfs_data->{ShareOnLocalNetwork} unless param 'ShareOnLocalNetwork';
@@ -45,14 +45,14 @@
For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).
- %=l('NFS Client(s) allowed')
+ %=l('nfs_NFS Client(s) allowed')
% param 'NFSClientsAllowed' => $nfs_data->{NFSClientsAllowed} unless param 'NFSClientsAllowed';
%= text_area 'NFSClientsAllowed', cols=>40, rows=>5
- %=l('File system permissions')
+ %=l('nfs_File system permissions')
% my @FileSystemPermissions_options = ['Read only', 'Read and Write'];
% param 'FileSystemPermissions' => $nfs_data->{FileSystemPermissions} unless param 'FileSystemPermissions';
@@ -60,7 +60,7 @@
- %=l('Write (a)synchronously.')
+ %=l('nfs_Write (a)synchronously.')
% my @WriteAsync_options = ['Synchronous', 'Asynchronous'];
% param 'WriteAsync' => $nfs_data->{WriteAsync} unless param 'WriteAsync';
@@ -68,7 +68,7 @@
- %=l('Delays the disk writings.')
+ %=l('nfs_Delays the disk writings.')
% my @DelayWrite_options = ['Write delay', 'No write delay'];
% param 'DelayWrite' => $nfs_data->{DelayWrite} unless param 'DelayWrite';
@@ -76,7 +76,7 @@
- %=l('Squash the power of users.')
+ %=l('nfs_Squash the power of users.')
% my @Squash_options = ['All users squash', 'No root squash', 'root squash'];
% param 'Squash' => $nfs_data->{Squash} unless param 'Squash';
@@ -84,7 +84,7 @@
- %=l('Browse the parent folders')
+ %=l('nfs_Browse the parent folders')
% my @BrowseParents_options = ['Hide folder', 'Show folder'];
% param 'BrowseParents' => $nfs_data->{BrowseParents} unless param 'BrowseParents';
@@ -92,7 +92,7 @@
- %=l('Requests on secure ports.')
+ %=l('nfs_Requests on secure ports.')
% my @SecurePorts_options = ['Secure', 'Insecure'];
% param 'SecurePorts' => $nfs_data->{SecurePorts} unless param 'SecurePorts';
@@ -100,14 +100,14 @@
Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank.
- %=l('Set the UID.')
+ %=l('nfs_Set the UID.')
% param 'SetUID' => $nfs_data->{SetUID} unless param 'SetUID';
%= text_field 'SetUID', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'SetUID'
- %=l('Set the GID.')
+ %=l('nfs_Set the GID.')
% param 'SetGID' => $nfs_data->{SetGID} unless param 'SetGID';
%= text_field 'SetGID', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'SetGID'
diff --git a/Targets/nfsshare_en.lex b/Targets/nfsshare_en.lex
new file mode 100644
index 0000000..8b34ad9
--- /dev/null
+++ b/Targets/nfsshare_en.lex
@@ -0,0 +1,20 @@
+'nfs_APPLY' => 'APPLY'
+'nfs_Save' => 'Save'
+'nfs_Squash the power of users.' => 'Squash the power of users.'
+'nfs Hello PARAMS' => 'Hello PARAMS'
+'nfs_Requests on secure ports.' => 'Requests on secure ports.'
+'nfs_Error message' => 'Error message'
+'nfs_Enable the NFS Share' => 'Enable the NFS Share'
+'nfs_NFS data share' => 'NFS data share'
+'nfs_Delays the disk writings.' => 'Delays the disk writings.'
+'nfs_Browse the parent folders' => 'Browse the parent folders'
+'nfs_Write (a)synchronously.' => 'Write (a)synchronously.'
+'nfs_NFS Client(s) allowed' => 'NFS Client(s) allowed'
+'nfs_EnableShare on local network' => 'EnableShare on local network'
+'nfs_Information Bay name' => 'Information Bay name'
+'nfs_ok message' => 'ok message'
+'nfs_Set the GID.' => 'Set the GID.'
+'nfs_Share owner Group' => 'Share owner Group'
+'nfs Hello TABLE' => 'Hello TABLE'
+'nfs_Set the UID.' => 'Set the UID.'
+'nfs_File system permissions' => 'File system permissions'
diff --git a/Templates/controller.pm.tem b/Templates/controller.pm.tem
index d76f8c1..6f6daf1 100644
--- a/Templates/controller.pm.tem
+++ b/Templates/controller.pm.tem
@@ -87,7 +87,7 @@ sub do_update {
if ($trt eq '${condition}'){
#Validate for panel ${condition}
- # set $ret = $c->l(''Error message') if invalid'
+ # set $ret = $c->l('Error message') if invalid'
}
if ($ret ne "ok"){
diff --git a/Templates/html_controls.html.ep.xml b/Templates/html_controls.html.ep.xml
index 684a20e..1aa69d3 100644
--- a/Templates/html_controls.html.ep.xml
+++ b/Templates/html_controls.html.ep.xml
@@ -1,7 +1,7 @@
- %=l('${Label}'), class => 'label'
+ %=l('${prefix}_${Label}'), class => 'label'
%= ${Value}, class => 'data'
@@ -9,7 +9,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
% my @${Name}_options = ${Value};
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
@@ -19,7 +19,7 @@
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
%= text_area '${Name}', cols=>${cols | 40}, rows=>${rows | 10}
@@ -28,7 +28,7 @@
- %=$%=l('${Label}')
+ %=$%=l('${prefix}_${Label}')
%=date_field '${Name}' =>$$${Name}, pattern=>${regexp | .*}
@@ -36,7 +36,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
%= text_field '${Name}', size => '${size | 50}', class => 'input' , pattern=>'${regexp | ".*"}' , placeholder=>'${placeholder | Name}'
@@ -54,7 +54,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
span>
]]>
@@ -62,7 +62,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
span>
]]>
@@ -70,7 +70,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
span>
]]>
@@ -78,7 +78,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
span>
]]>
@@ -86,7 +86,7 @@
- %=l('${Label}')
+ %=l('${prefix}_${Label}')
span>
]]>
diff --git a/sm2gen-ImportJSON5.py b/sm2gen-ImportJSON5.py
index dc64465..bf991ba 100644
--- a/sm2gen-ImportJSON5.py
+++ b/sm2gen-ImportJSON5.py
@@ -5,6 +5,7 @@ import argparse
from chameleon import PageTemplateFile,PageTemplate
import pkg_resources
import xml.etree.ElementTree as ET
+import re
version = 0.5
@@ -140,6 +141,16 @@ def parse_xml_to_dict(xml_file):
return xml_dict
+def deduplicate_array(arr):
+ # Convert the array to a set to remove duplicates
+ unique_set = set(arr)
+
+ # Convert the set back to a list to maintain the order
+ deduplicated_list = list(unique_set)
+
+ return deduplicated_list
+
+
if __name__ == "__main__":
filename = '/home/brianr/clients/SM2/SM2Gen/nfsshare.json5'
@@ -148,9 +159,10 @@ if __name__ == "__main__":
parser.add_argument('-f', '--filename', help='Specify a filename for the JSON5 file', default=filename)
parser.add_argument('-nc', '--noController', help='Stop it creating a controller file', default="no")
parser.add_argument('-nh', '--noHtml', help='Stop it creating html files(s)', default="no")
+ parser.add_argument('-nl', '--noLang', help='Stop it creating language localise files(s)', default="no")
args = parser.parse_args()
filename = args.filename
- print(f"JSON5 from {filename} with noController={args.noController} and noHtml={args.noHtml}")
+ print(f"JSON5 from {filename} with noController={args.noController}, noHtml={args.noHtml} and noLang={args.noLang}") #Not yet activated
#print("Chameleon version:", chameleon.__version__)
# check syntax of JSON5
@@ -172,6 +184,15 @@ if __name__ == "__main__":
routes = get_all_routes();
lc_routes =lc_get_all_routes();
+ #File names
+ controller_file = 'Targets/'+hl('PackageName')+'.pm'
+ layout_file = 'Targets/'+hl('PackageName')+'.html.ep'
+ partial_files = list()
+ for panel in routes:
+ partial_files.append('Targets/_'+hl('prefix')+"_"+panel+'.html.ep')
+ print(partial_files)
+ lex_file = 'Targets/'+hl('PackageName').lower()+'_en.lex'
+
#Generate controller file
try:
controller_template = PageTemplateFile("Templates/controller.pm.tem")
@@ -181,9 +202,9 @@ if __name__ == "__main__":
#print(controller_perl)
# Map '$ 'to '$' to overcome problem with escaping $ signs
#controller_perl = controller_perl.replace("$ ", "$")
- with open('Targets/'+hl('PackageName')+'.pm', 'w') as file:
+ with open(controller_file, 'w') as file:
file.write(controller_perl)
- print("Targets/"+hl('PackageName')+'.pm controller generated ok')
+ print(f"{controller_file} controller generated ok")
except Exception as e:
print(f"An chameleon controller render error occurred: {e}")
except Exception as e:
@@ -196,9 +217,9 @@ if __name__ == "__main__":
layout_mojo = layout_template.render(**json5_dict,conditions=routes)
# Map '$ 'to '$' to overcome problem with escaping $ signs
#layout_mojo = layout_mojo.replace("$ ", "$")
- with open('Targets/'+hl('PackageName')+'.html.ep', 'w') as file:
+ with open(layout_file, 'w') as file:
file.write(layout_mojo)
- print("Targets/"+hl('PackageName')+'.html.ep mojo template generated ok')
+ print(f"{layout_file} mojo template generated ok")
except Exception as e:
print(f"An chameleon render on layout file error occurred: {e}")
#print()
@@ -211,6 +232,7 @@ if __name__ == "__main__":
#html_controls = json5_to_dict('Templates/html_controls.html.ep.tem')
html_controls = parse_xml_to_dict('Templates/html_controls.html.ep.xml')
#print(html_controls)
+ i = 0
for html in json5_html_list:
# Generate a mojo template file, and then add in the controls
# main file first
@@ -221,9 +243,9 @@ if __name__ == "__main__":
partial_mojo_template = partial_template.render(**partial_mojo_context)
# Map '$ 'to '$' to overcome problem with escaping $ signs
#partial_mojo_template = partial_mojo_template.replace("$ ", "$")
- with open('Targets/_'+hl('prefix')+"_"+html['route']+'.html.ep', 'w') as file:
+ with open( partial_files[i], 'w') as file:
file.write(partial_mojo_template)
- print('Targets/_'+hl('prefix')+"_"+html['route']+'.html.ep mojo template generated ok')
+ print(f"{partial_files[i]} mojo template generated ok")
except Exception as e:
print(f"An chameleon render on partial file {html['route']} occurred: {e}")
except Exception as e:
@@ -275,7 +297,7 @@ if __name__ == "__main__":
# Now insert it into the partial file in the correct place.
# Read in the text file and split at "%# Inputs etc in here."
- with open('Targets/_'+hl('prefix')+"_"+html['route']+'.html.ep', 'r') as file:
+ with open(partial_files[i], 'r') as file:
lines = file.readlines()
index = next((i for i, line in enumerate(lines) if "%# Inputs etc in here." in line), len(lines))
@@ -283,9 +305,59 @@ if __name__ == "__main__":
lines.insert(index+1, all_controls_html + '\n')
# Write the modified content back to the file
- with open('Targets/_'+hl('prefix')+"_"+html['route']+'.html.ep', 'w') as file:
+ with open(partial_files[i], 'w') as file:
file.writelines(lines)
- print('Content modified and saved to Targets/_'+hl('prefix')+"_"+html['route']+'.html.ep .')
+ print(f"Content modified and saved to {partial_files[i]}")
+ i += 1
+
+ # Now generate the .en file
+ # Look through the generated files for the /l[\s|(]['|"](.*)['|"]\)/ strings.
+
+ # create a combined list of all the files
+ all_files = [controller_file,layout_file]+partial_files
+ print(all_files)
+ all_strings = []
+ for filename in all_files:
+ with open(filename, 'r') as file:
+ file_content = file.read()
+ # Define the regular expression pattern to match the strings you want to extract
+ pattern = r"l[\s|(][\'|\"](.*)[\'|\"]\)"
+ # Use re.findall to extract all occurrences of the pattern from the file content
+ extracted_strings = re.findall(pattern, file_content)
+ print(len(extracted_strings))
+ all_strings = all_strings + extracted_strings
+ print(len(all_strings))
+ #Take out any duplicates
+ all_strings = deduplicate_array(all_strings)
+ print(len(all_strings))
+ # Now process them one by one into the lexical file
+ lex_all = "";
+ # '_english-message' => 'English Message',
+ for lex_message in all_strings:
+ # If has a prefix - leave it for left hand side but delete it for the right
+ # If has no prefix - add one for left hand side but and lkeave it for the right
+ if lex_message.startswith(hl('prefix')):
+ left_str = lex_message
+ right_str = lex_message[len(hl('prefix'))+1:]
+ else:
+ left_str = hl('prefix')+"_"+lex_message
+ right_str = lex_message
+ lex_all += f"'{left_str}' => '{right_str}'\n"
+ #And write it to lex file
+ with open( lex_file, 'w') as file:
+ file.write(lex_all)
+
+
+
+
+
+
+
+
+
+
+
+