Add in entries for other mojo input tags
This commit is contained in:
parent
3b6e1930a0
commit
4d7cc1f076
@ -2,7 +2,7 @@
|
||||
# Routines to be edited by the developer to provide validation for parameters
|
||||
# and provison of the control data for table(s)
|
||||
#
|
||||
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
|
||||
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
|
||||
#
|
||||
|
||||
use esmith::util;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package SrvMngr::Controller::CreateStarterWebsite;
|
||||
#
|
||||
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
|
||||
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
# heading : Miscellaneous
|
||||
|
@ -1,5 +1,5 @@
|
||||
%#
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-13 19:20
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
|
||||
%#
|
||||
<div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS">
|
||||
<script>
|
||||
@ -20,48 +20,39 @@
|
||||
<h2><%=l('csw_Manage_CreateStarterWebsite_settings:')%></h2>
|
||||
|
||||
<p>
|
||||
%= l('To create a simple web page for your company, fill
|
||||
in the fields below and click onCreate.')
|
||||
%=l('csw_To_create_a_simple_web')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%= l('csw_You_can_leave_any_field')
|
||||
%=l('csw_You_can_leave_any_field')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%= l('The text that you enter below will be line wrapped
|
||||
for a nicer appearance in your web page. Leave a blank line
|
||||
whenever you want to start a new paragraph. If you need
|
||||
to force a line break without starting a new paragraph (for
|
||||
example after each line of a mailing address), then type
|
||||
the four-character sequence')
|
||||
%=l('csw_The_text_that_you_enter')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%= l('Do not use this option if you have already customized your web site, since it will
|
||||
overwrite the 'index.htm' file in your web site directory.')
|
||||
%=l('csw_Do_not_use_this_optionif')
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
%=
|
||||
% text_field
|
||||
</span></p>
|
||||
|
||||
<p>
|
||||
%= l('First header, typically used for short phrases such
|
||||
as 'Leader in the field of textile manufacturing'')
|
||||
%=l('csw_First_header,_typically_used_for')
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
%=
|
||||
% text_field
|
||||
</span></p>
|
||||
|
||||
<p>
|
||||
%= l('Text following first header, typically used for a
|
||||
paragraph of marketing information.')
|
||||
%=l('csw_Text_following_first_header,_typically')
|
||||
</p>
|
||||
|
||||
<span class=label>
|
||||
@ -72,19 +63,17 @@
|
||||
</span><br>
|
||||
|
||||
<p>
|
||||
%= l('Second header, typically used for short phrases such
|
||||
as 'For more information' or 'To order our products':')
|
||||
%=l('csw_Second_header,_typically_used_for')
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
%=
|
||||
% text_field
|
||||
</span></p>
|
||||
|
||||
<p>
|
||||
%= l('Text following second header, typically used for contact
|
||||
or ordering information:')
|
||||
%=l('csw_Text_following_second_header,_typically')
|
||||
</p>
|
||||
|
||||
<span class=label>
|
||||
@ -95,15 +84,17 @@
|
||||
</span><br>
|
||||
|
||||
<p>
|
||||
%= l('When you create this web page, the file
|
||||
'index.htm' will be overwritten
|
||||
in your web site directory.')
|
||||
%=l('csw_When_you_create_this_web')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%= l('csw_Do_you_wish_to_proceed?')
|
||||
%=l('csw_Do_you_wish_to_proceed?')
|
||||
</p>
|
||||
|
||||
<span class='data'>
|
||||
%= submit_button l('csw_Create'), class => 'action'
|
||||
</span>
|
||||
|
||||
%# Probably finally by a submit.
|
||||
%end
|
||||
</div>
|
||||
|
@ -1,6 +1,6 @@
|
||||
% layout 'default', title => "Sme server 2 - Create Starter Website", share_dir => './';
|
||||
%#
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
|
||||
%#
|
||||
% content_for 'module' => begin
|
||||
<div id="module" class="module CreateStarterWebsite-panel">
|
||||
|
@ -1,16 +1,17 @@
|
||||
'csw_Do_not_use_this_optionif' => 'Do not use this optionif you have already customized your web site, Since it will overwrite the \'index. Htm\' file in your web site directory. ',
|
||||
'csw_Second_header,_typically_used_for' => 'Second header, Typically used for short phrases such as \'For more information\' or \'To order our products\':',
|
||||
'csw_Text_following_second_header,_typically' => 'Text following second header, Typically used for contact or ordering information:',
|
||||
'csw_Hello_PARAMS' => 'Hello PARAMS',
|
||||
'csw_To_create_a_simple_web' => 'To create a simple web page for your company, Fill in the fields below and click onCreate. ',
|
||||
'csw_The_text_that_you_enter' => 'The text that you enter below will be line wrapped for a nicer appearance in your web page. Leave a blank line whenever you want to start a new paragraph. If you need to force a line break without starting a new paragraph (for example after each line of a mailing address), Then type the four-character sequence',
|
||||
'csw_You_can_leave_any_field' => 'You can leave any field blank if you do not need it. ',
|
||||
'csw_Text_following_first_header,_typically' => 'Text following first header, Typically used for a paragraph of marketing information. ',
|
||||
'csw_Do_you_wish_to_proceed?' => 'Do you wish to proceed?',
|
||||
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
|
||||
'csw_When_you_create_this_web' => 'When you create this web page, The file \'index. Htm\' will be overwritten in your web site directory. ',
|
||||
'csw_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
|
||||
'csw_Create_Starter_Website' => 'Create Starter Website',
|
||||
'csw_First_header,_typically_used_for' => 'First header, Typically used for short phrases such as \'Leader in the field of textile manufacturing\'',
|
||||
'csw_Do_you_wish_to_proceed?' => 'Do you wish to proceed?',
|
||||
'csw_Create' => 'Create',
|
||||
'csw_When_you_create_this_web' => 'When you create this web page, The file 'index. Htm' will be overwritten in your web site directory. ',
|
||||
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
|
||||
'csw_' => '',
|
||||
'csw_The_text_that_you_enter' => 'The text that you enter below will be line wrapped for a nicer appearance in your web page. Leave a blank line whenever you want to start a new paragraph. If you need to force a line break without starting a new paragraph (for example after each line of a mailing address), Then type the four-character sequence',
|
||||
'csw_You_can_leave_any_field' => 'You can leave any field blank if you do not need it. ',
|
||||
'csw_First_header,_typically_used_for' => 'First header, Typically used for short phrases such as 'Leader in the field of textile manufacturing'',
|
||||
'csw_Text_following_first_header,_typically' => 'Text following first header, Typically used for a paragraph of marketing information. ',
|
||||
'csw_Do_not_use_this_optionif' => 'Do not use this optionif you have already customized your web site, Since it will overwrite the 'index. Htm' file in your web site directory. ',
|
||||
'csw_Create_Starter_Website' => 'Create Starter Website',
|
||||
'csw_To_create_a_simple_web' => 'To create a simple web page for your company, Fill in the fields below and click onCreate. ',
|
||||
'csw_APPLY' => 'Apply',
|
||||
'csw_Text_following_second_header,_typically' => 'Text following second header, Typically used for contact or ordering information:',
|
||||
'csw_Second_header,_typically_used_for' => 'Second header, Typically used for short phrases such as 'For more information' or 'To order our products':',
|
||||
|
@ -1,96 +0,0 @@
|
||||
%#
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
|
||||
%#
|
||||
<div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS">
|
||||
<script>
|
||||
window.onload = function() {
|
||||
SelectInput();
|
||||
};
|
||||
</script>
|
||||
<h2>
|
||||
%= l('csw_Hello_PARAMS');
|
||||
</h2>
|
||||
% my $btn = l('csw_APPLY');
|
||||
%= form_for "CreateStarterWebsited" => (method => 'POST') => begin
|
||||
|
||||
% param 'trt' => $csw_data->{trt} unless param 'trt';
|
||||
%= hidden_field 'trt' => $csw_data->{trt}
|
||||
%# Inputs etc in here.
|
||||
|
||||
<h2><%=l('csw_Manage_CreateStarterWebsite_settings:')%></h2>
|
||||
|
||||
<p>
|
||||
%=l('csw_To_create_a_simple_web')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%=l('csw_You_can_leave_any_field')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%=l('csw_The_text_that_you_enter')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%=l('csw_Do_not_use_this_optionif')
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
%=
|
||||
</span></p>
|
||||
|
||||
<p>
|
||||
%=l('csw_First_header,_typically_used_for')
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
%=
|
||||
</span></p>
|
||||
|
||||
<p>
|
||||
%=l('csw_Text_following_first_header,_typically')
|
||||
</p>
|
||||
|
||||
<span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
% param 'text1' => $csw_data->{text1} unless param 'text1';
|
||||
%= text_area 'text1', cols=>40, rows=>10
|
||||
</span><br>
|
||||
|
||||
<p>
|
||||
%=l('csw_Second_header,_typically_used_for')
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
%=
|
||||
</span></p>
|
||||
|
||||
<p>
|
||||
%=l('csw_Text_following_second_header,_typically')
|
||||
</p>
|
||||
|
||||
<span class=label>
|
||||
%=l('csw_')
|
||||
</span><span class=data>
|
||||
% param 'text2' => $csw_data->{text2} unless param 'text2';
|
||||
%= text_area 'text2', cols=>40, rows=>10
|
||||
</span><br>
|
||||
|
||||
<p>
|
||||
%=l('csw_When_you_create_this_web')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%=l('csw_Do_you_wish_to_proceed?')
|
||||
</p>
|
||||
|
||||
%# Probably finally by a submit.
|
||||
%end
|
||||
</div>
|
@ -2,7 +2,7 @@
|
||||
# Routines to be edited by the developer to provide validation for parameters
|
||||
# and provison of the control data for table(s)
|
||||
#
|
||||
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
|
||||
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 10:49
|
||||
#
|
||||
|
||||
use esmith::util;
|
||||
@ -36,7 +36,11 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
# Return an array of hashes of the contents for each row and column for Table1
|
||||
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
|
||||
my $c = shift;
|
||||
my @ret = {};
|
||||
my $control_data = $self->stash('Table1');
|
||||
my @ret = {}
|
||||
# foreach my $colHead (@$control_data) {
|
||||
# my ret{$colHead} = "$colhead-1"
|
||||
# };
|
||||
return \@ret
|
||||
}
|
||||
|
||||
@ -44,7 +48,11 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
# Return an array of hashes of the contents for each row and column for Table2
|
||||
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
|
||||
my $c = shift;
|
||||
my @ret = {};
|
||||
my $control_data = $self->stash('Table2');
|
||||
my @ret = {}
|
||||
# foreach my $colHead (@$control_data) {
|
||||
# my ret{$colHead} = "$colhead-1"
|
||||
# };
|
||||
return \@ret
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Routines to be edited by the developer to provide validation for parameters
|
||||
# and provison of the control data for table(s)
|
||||
#
|
||||
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 11:53
|
||||
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
|
||||
#
|
||||
|
||||
use esmith::util;
|
||||
@ -33,14 +33,26 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
# Get control data for tables(s)
|
||||
|
||||
sub get_Table1 {
|
||||
# Return an array of hashes of the contents for each row and column for Table1
|
||||
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
|
||||
my $c = shift;
|
||||
my @ret = {};
|
||||
my $control_data = $self->stash('Table1');
|
||||
my @ret = {}
|
||||
# foreach my $colHead (@$control_data) {
|
||||
# my ret{$colHead} = "$colhead-1"
|
||||
# };
|
||||
return \@ret
|
||||
}
|
||||
|
||||
sub get_Table2 {
|
||||
# Return an array of hashes of the contents for each row and column for Table2
|
||||
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
|
||||
my $c = shift;
|
||||
my @ret = {};
|
||||
my $control_data = $self->stash('Table2');
|
||||
my @ret = {}
|
||||
# foreach my $colHead (@$control_data) {
|
||||
# my ret{$colHead} = "$colhead-1"
|
||||
# };
|
||||
return \@ret
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
package SrvMngr::Controller::Diskusage;
|
||||
package SrvMngr::Controller::DiskUsage;
|
||||
#
|
||||
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
|
||||
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
# heading : Miscellaneous
|
||||
# description : Disk Usage
|
||||
# navigation : 2000 400
|
||||
#
|
||||
# name : diskusage, method : get, url : /diskusage, ctlact : Diskusage#main
|
||||
# name : diskusageu, method : post, url : /diskusageu, ctlact : Diskusage#do_update
|
||||
# name : diskusaged, method : get, url : /diskusaged, ctlact : Diskusage#do_display
|
||||
# name : diskusage, method : get, url : /diskusage, ctlact : DiskUsage#main
|
||||
# name : diskusageu, method : post, url : /diskusageu, ctlact : DiskUsage#do_update
|
||||
# name : diskusaged, method : get, url : /diskusaged, ctlact : DiskUsage#do_display
|
||||
#
|
||||
# routes : end
|
||||
#
|
||||
# Documentation: https://wiki.contribs.org/Diskusage
|
||||
# Documentation: https://wiki.contribs.org/DiskUsage
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#
|
||||
@ -49,7 +49,7 @@ our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
|
||||
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
|
||||
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
|
||||
require '/usr/share/smanager/lib/SrvMngr/Controller/Diskusage-Custom.pm'; #The code that is to be added by the developer
|
||||
require '/usr/share/smanager/lib/SrvMngr/Controller/DiskUsage-Custom.pm'; #The code that is to be added by the developer
|
||||
|
||||
sub main {
|
||||
#
|
@ -1,7 +1,7 @@
|
||||
%#
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
|
||||
%#
|
||||
<div id="Diskusage-PARAMS" class="partial Diskusage-PARAMS">
|
||||
<div id="DiskUsage-PARAMS" class="partial DiskUsage-PARAMS">
|
||||
<script>
|
||||
window.onload = function() {
|
||||
SelectInput();
|
||||
@ -11,7 +11,7 @@
|
||||
%= l('du_Hello_PARAMS');
|
||||
</h2>
|
||||
% my $btn = l('du_APPLY');
|
||||
%= form_for "Diskusaged" => (method => 'POST') => begin
|
||||
%= form_for "DiskUsaged" => (method => 'POST') => begin
|
||||
|
||||
% param 'trt' => $du_data->{trt} unless param 'trt';
|
||||
%= hidden_field 'trt' => $du_data->{trt}
|
||||
@ -20,11 +20,11 @@
|
||||
<h2><%=l('du_Manage_DiskUsage_settings:')%></h2>
|
||||
|
||||
<p>
|
||||
%= l('du_&nbsp')
|
||||
%=l('du_')
|
||||
</p>
|
||||
|
||||
<p>
|
||||
%= l('du_Wed_Sep_11_19:01:00_BST')
|
||||
%=l('du_Wed_Sep_11_19:01:00_BST')
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
@ -60,7 +60,7 @@ tmpfs 2.0G 648K 2.0G 1% /run
|
||||
|
||||
|
||||
<p>
|
||||
%= l('du_&nbsp')
|
||||
%=l('du_')
|
||||
</p>
|
||||
|
||||
<br /><table class="sme-border TableSort sme-table">
|
@ -1,9 +1,9 @@
|
||||
% layout 'default', title => "Sme server 2 - Disk Usage", share_dir => './';
|
||||
%#
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
|
||||
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
|
||||
%#
|
||||
% content_for 'module' => begin
|
||||
<div id="module" class="module Diskusage-panel">
|
||||
<div id="module" class="module DiskUsage-panel">
|
||||
|
||||
% if ($config->{debug} == 1) {
|
||||
<p>
|
@ -1,11 +1,11 @@
|
||||
'du_&nbsp' => '&nbsp',
|
||||
'du_I-bays' => 'I-bays',
|
||||
'du_Usage' => 'Usage',
|
||||
'du_Disk_Usage' => 'Disk Usage',
|
||||
'du_Path' => 'Path',
|
||||
'du_Wed_Sep_11_19:01:00_BST' => 'Wed Sep 11 19:01:00 BST 2024',
|
||||
'du_Users' => 'Users',
|
||||
'du_APPLY' => 'Apply',
|
||||
'du_Hello_PARAMS' => 'Hello PARAMS',
|
||||
'du_' => '',
|
||||
'du_Manage_DiskUsage_settings:' => 'Manage DiskUsage settings:',
|
||||
'du_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
|
||||
'du_Wed_Sep_11_19:01:00_BST' => 'Wed Sep 11 19:01:00 BST 2024',
|
||||
'du_Path' => 'Path',
|
||||
'du_I-bays' => 'I-bays',
|
||||
'du_Hello_PARAMS' => 'Hello PARAMS',
|
||||
'du_Usage' => 'Usage',
|
||||
'du_Users' => 'Users',
|
||||
'du_Disk_Usage' => 'Disk Usage',
|
||||
'du_APPLY' => 'Apply',
|
@ -36,7 +36,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
# Return an array of hashes of the contents for each row and column for ${tablecontrol}
|
||||
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
|
||||
my $c = shift;
|
||||
my $control_data = $self->stash('${TableControl}');
|
||||
my $control_data = $self->stash('${tablecontrol}');
|
||||
my @ret = {}
|
||||
# foreach my $colHead (@$control_data) {
|
||||
# my ret{$colHead} = "$colhead-1"
|
||||
|
@ -3,7 +3,7 @@
|
||||
<p><span class=label>
|
||||
%=l('${prefix}_${Label}')
|
||||
</span><span class=data>
|
||||
%= ${Value}
|
||||
% text_field ${Value}
|
||||
</span></p>
|
||||
]]></Text>
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
%= select_field '${Name}' => @${Name}_options, class => 'input'
|
||||
<br></span> </p>
|
||||
]]></Selection>
|
||||
|
||||
|
||||
|
||||
<Textarea><![CDATA[
|
||||
<span class=label>
|
||||
@ -34,6 +36,15 @@
|
||||
</span><br>
|
||||
]]></Date>
|
||||
|
||||
<Time><![CDATA[
|
||||
<span class=label>
|
||||
%=l('${prefix}_${Label}')
|
||||
</span><span class=data>
|
||||
%=time_field '${Name}' =>$$${Name}, pattern=>${regexp | .*}
|
||||
</span><br>
|
||||
]]></Time>
|
||||
|
||||
|
||||
<Textinput><![CDATA[
|
||||
<p><span class=label>
|
||||
%=l('${prefix}_${Label}')
|
||||
@ -55,7 +66,7 @@
|
||||
|
||||
<Submit><![CDATA[
|
||||
<span class='data'>
|
||||
%= submit_button l('${value}'), class => 'action'
|
||||
%= submit_button l('${Value}'), class => 'action'
|
||||
</span>]]>
|
||||
</Submit>
|
||||
|
||||
@ -63,6 +74,8 @@
|
||||
<p><span class=label>
|
||||
%=l('${prefix}_${Label}')
|
||||
</span><span class=data>
|
||||
%=Search field
|
||||
%=search field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</search>
|
||||
@ -71,6 +84,7 @@
|
||||
<p><span class=label>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=URL field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</url>
|
||||
@ -79,6 +93,7 @@
|
||||
<p><span class=label>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=tel field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</tel>
|
||||
@ -87,6 +102,7 @@
|
||||
<p><span class=label>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=email field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</email>
|
||||
@ -95,9 +111,91 @@
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=password field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</password>
|
||||
|
||||
<timedate><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=timedate field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</timedate>
|
||||
|
||||
<week><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=week field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</week>
|
||||
|
||||
<month><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=month field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</month>
|
||||
|
||||
<range><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=range field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</range>
|
||||
|
||||
<radio><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=radio field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</radio>
|
||||
|
||||
<number><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=number field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</number>
|
||||
|
||||
<file><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=file field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</file>
|
||||
|
||||
<color><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=color field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</color>
|
||||
|
||||
<checkbox><![CDATA[
|
||||
<p><span class='label'>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=checkbox field
|
||||
</span>span></p>
|
||||
]]>
|
||||
</checkbox>
|
||||
|
||||
<Table><![CDATA[
|
||||
<br /><table class="sme-border TableSort sme-table">
|
||||
@ -125,11 +223,5 @@
|
||||
]]>
|
||||
</Preformatted>
|
||||
|
||||
<submit><![CDATA[
|
||||
<p> <br>
|
||||
%= submit_button "${Value}", class => 'action'
|
||||
</p>
|
||||
]]>
|
||||
</submit>
|
||||
|
||||
</root>
|
||||
|
@ -6,57 +6,58 @@
|
||||
'MenuNavigation': '2000 400',
|
||||
'firstPanel': 'PARAMS',
|
||||
'signalEvent': 'smeserver-createstarterwebsite-update',
|
||||
'html':[ {
|
||||
'Name': 'params',
|
||||
'route': 'PARAMS',
|
||||
'Header': 'Create a starter website',
|
||||
'SubHeader': 'Manage CreateStarterWebsite settings:',
|
||||
'Paragraph1': 'To create a simple web page for your company, fill in the fields below and click onCreate.',
|
||||
'Paragraph2': 'You can leave any field blank if you do not need it.',
|
||||
'Paragraph3': 'The text that you enter below will be line wrapped for a nicer appearance in your web page. Leave a blank line whenever you want to start a new paragraph. If you need to force a line break without starting a new paragraph (for example after each line of a mailing address), then type the four-character sequence',
|
||||
'Paragraph4': 'Do not use this optionif you have already customized your web site, since it will overwrite the index.htm file in your web site directory.',
|
||||
'Input1': {
|
||||
'Type': 'Text',
|
||||
'Value': '',
|
||||
'Name': 'companyName',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph5': 'First header, typically used for short phrases such as Leader in the field of textile manufacturing',
|
||||
'Input2': {
|
||||
'Type': 'Text',
|
||||
'Value': '',
|
||||
'Name': 'header1',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph6': 'Text following first header, typically used for a paragraph of marketing information.',
|
||||
'Input3': {
|
||||
'Type': 'Textarea',
|
||||
'Value': '',
|
||||
'Name': 'text1',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph7': 'Second header, typically used for short phrases such as For more information or To order our products:',
|
||||
'Input4': {
|
||||
'Type': 'Text',
|
||||
'Value': '',
|
||||
'Name': 'header2',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph8': 'Text following second header, typically used for contact or ordering information:',
|
||||
'Input5': {
|
||||
'Type': 'Textarea',
|
||||
'Value': '',
|
||||
'Name': 'text2',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph9': 'When you create this web page, the file index.htm will be overwritten in your web site directory.',
|
||||
'Paragraph10': 'Do you wish to proceed?',
|
||||
'Input6': {
|
||||
'Type': 'Submit',
|
||||
'Value': 'Create',
|
||||
'Name': 'Next',
|
||||
'Label': null
|
||||
'html': [
|
||||
{
|
||||
'Name': 'params',
|
||||
'route': 'PARAMS',
|
||||
'Header': 'Create a starter website',
|
||||
'SubHeader': 'Manage CreateStarterWebsite settings:',
|
||||
'Paragraph1': 'To create a simple web page for your company, fill in the fields below and click onCreate.',
|
||||
'Paragraph2': 'You can leave any field blank if you do not need it.',
|
||||
'Paragraph3': 'The text that you enter below will be line wrapped for a nicer appearance in your web page. Leave a blank line whenever you want to start a new paragraph. If you need to force a line break without starting a new paragraph (for example after each line of a mailing address), then type the four-character sequence',
|
||||
'Paragraph4': 'Do not use this optionif you have already customized your web site, since it will overwrite the \'index.htm\' file in your web site directory.',
|
||||
'Input1': {
|
||||
'Type': 'Text',
|
||||
'Value': '',
|
||||
'Name': 'companyName',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph5': 'First header, typically used for short phrases such as \'Leader in the field of textile manufacturing\'',
|
||||
'Input2': {
|
||||
'Type': 'Text',
|
||||
'Value': '',
|
||||
'Name': 'header1',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph6': 'Text following first header, typically used for a paragraph of marketing information.',
|
||||
'Input3': {
|
||||
'Type': 'Textarea',
|
||||
'Value': '',
|
||||
'Name': 'text1',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph7': 'Second header, typically used for short phrases such as \'For more information\' or \'To order our products\':',
|
||||
'Input4': {
|
||||
'Type': 'Text',
|
||||
'Value': '',
|
||||
'Name': 'header2',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph8': 'Text following second header, typically used for contact or ordering information:',
|
||||
'Input5': {
|
||||
'Type': 'Textarea',
|
||||
'Value': '',
|
||||
'Name': 'text2',
|
||||
'Label': null
|
||||
},
|
||||
'Paragraph9': 'When you create this web page, the file \'index.htm\' will be overwritten in your web site directory.',
|
||||
'Paragraph10': 'Do you wish to proceed?',
|
||||
'Input6': {
|
||||
'Type': 'Submit',
|
||||
'Value': 'Create',
|
||||
'Name': 'Next',
|
||||
'Label': null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,47 +1,49 @@
|
||||
{
|
||||
PackageName: 'Diskusage',
|
||||
prefix: 'du',
|
||||
MenuHeading: 'Miscellaneous',
|
||||
MenuDescription: 'Disk Usage',
|
||||
MenuNavigation: '2000 400',
|
||||
firstPanel: 'PARAMS',
|
||||
signalEvent: 'smeserver-diskusage-update',
|
||||
html: [{
|
||||
Name: 'params',
|
||||
route: 'PARAMS',
|
||||
Header: 'Disk usage',
|
||||
SubHeader: 'Manage DiskUsage settings:',
|
||||
Paragraph1: ' ',
|
||||
Paragraph2: 'Wed Sep 11 19:01:00 BST 2024',
|
||||
Preformatted1: 'Filesystem Size Used Avail Use% Mounted on\n/dev/mapper/main-root 29G 4.8G 24G 17% /\ndevtmpfs 2.0G 0 2.0G 0% /dev\ntmpfs 2.0G 12K 2.0G 1% /dev/shm\ntmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup\ntmpfs 2.0G 648K 2.0G 1% /run\n/dev/sda1 497M 111M 386M 23% /boot',
|
||||
Table1: {
|
||||
Type: 'Table',
|
||||
TableControl: 'Table1',
|
||||
TopHeadings: [
|
||||
'I-bays',
|
||||
'Usage',
|
||||
'Path'
|
||||
],
|
||||
Columns: [
|
||||
'Table1-I-bays',
|
||||
'Table1-Usage',
|
||||
'Table1-Path'
|
||||
]
|
||||
},
|
||||
Paragraph3: ' ',
|
||||
Table2: {
|
||||
Type: 'Table',
|
||||
TableControl: 'Table2',
|
||||
TopHeadings: [
|
||||
'Users',
|
||||
'Usage',
|
||||
'Path'
|
||||
],
|
||||
Columns: [
|
||||
'Table2-Users',
|
||||
'Table2-Usage',
|
||||
'Table2-Path'
|
||||
]
|
||||
'PackageName': 'DiskUsage',
|
||||
'prefix': 'du',
|
||||
'MenuHeading': 'Miscellaneous',
|
||||
'MenuDescription': 'Disk Usage',
|
||||
'MenuNavigation': '2000 400',
|
||||
'firstPanel': 'PARAMS',
|
||||
'signalEvent': 'smeserver-diskusage-update',
|
||||
'html': [
|
||||
{
|
||||
'Name': 'params',
|
||||
'route': 'PARAMS',
|
||||
'Header': 'Disk usage',
|
||||
'SubHeader': 'Manage DiskUsage settings:',
|
||||
'Paragraph1': '',
|
||||
'Paragraph2': 'Wed Sep 11 19:01:00 BST 2024',
|
||||
'Preformatted1': 'Filesystem Size Used Avail Use% Mounted on\n/dev/mapper/main-root 29G 4.8G 24G 17% /\ndevtmpfs 2.0G 0 2.0G 0% /dev\ntmpfs 2.0G 12K 2.0G 1% /dev/shm\ntmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup\ntmpfs 2.0G 648K 2.0G 1% /run\n/dev/sda1 497M 111M 386M 23% /boot',
|
||||
'Table1': {
|
||||
'Type': 'Table',
|
||||
'TableControl': 'Table1',
|
||||
'TopHeadings': [
|
||||
'I-bays',
|
||||
'Usage',
|
||||
'Path'
|
||||
],
|
||||
'Columns': [
|
||||
'Table1-I-bays',
|
||||
'Table1-Usage',
|
||||
'Table1-Path'
|
||||
]
|
||||
},
|
||||
'Paragraph3': '',
|
||||
'Table2': {
|
||||
'Type': 'Table',
|
||||
'TableControl': 'Table2',
|
||||
'TopHeadings': [
|
||||
'Users',
|
||||
'Usage',
|
||||
'Path'
|
||||
],
|
||||
'Columns': [
|
||||
'Table2-Users',
|
||||
'Table2-Usage',
|
||||
'Table2-Path'
|
||||
]
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
@ -3,12 +3,16 @@ import os
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from lxml import etree # Import lxml for HTML validation
|
||||
import html
|
||||
import argparse
|
||||
|
||||
|
||||
def read_html_file(filename):
|
||||
"""Read HTML content from a file."""
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
with open(filename, "r", encoding="utf-8") as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def validate_html(html):
|
||||
"""Validate the HTML content."""
|
||||
try:
|
||||
@ -16,14 +20,20 @@ def validate_html(html):
|
||||
etree.fromstring(html, parser) # Attempt to parse the HTML
|
||||
except Exception as e:
|
||||
raise ValueError("Invalid HTML document") from e
|
||||
|
||||
|
||||
|
||||
def sanitize_text(text):
|
||||
# Replace newlines with spaces
|
||||
sanitized_text = text.replace('\n', ' ').replace('\r', ' ') # Handle both Unix and Windows line endings
|
||||
decoded_text = html.unescape(text)
|
||||
sanitized_text = decoded_text.replace("\n", "").replace(
|
||||
"\r", " "
|
||||
) # Handle both Unix and Windows line endings
|
||||
# Replace tabs with spaces
|
||||
sanitized_text = sanitized_text.replace('\t', ' ')
|
||||
# Escape quote characters
|
||||
sanitized_text = sanitized_text.replace('"', '\\"').replace("'", "\\'")
|
||||
sanitized_text = sanitized_text.replace("\t", "")
|
||||
# map single quotes to double
|
||||
sanitized_text = sanitized_text.replace("'", '"')
|
||||
#Take out any multiple spaces - reduce to one.
|
||||
sanitized_text = ' '.join(sanitized_text.split())
|
||||
# Strip leading and trailing whitespace
|
||||
sanitized_text = sanitized_text.strip()
|
||||
return sanitized_text
|
||||
@ -31,15 +41,10 @@ def sanitize_text(text):
|
||||
|
||||
def extract_data(html):
|
||||
"""Extract paragraphs, inputs, tables, and pre blocks from HTML and organize them in order."""
|
||||
soup = BeautifulSoup(html, 'lxml')
|
||||
soup = BeautifulSoup(html, "lxml")
|
||||
records = []
|
||||
|
||||
hidden_input_names = [
|
||||
'page',
|
||||
'page_stack',
|
||||
'.id',
|
||||
'csrf_token'
|
||||
]
|
||||
hidden_input_names = ["page", "page_stack", ".id", "csrf_token"]
|
||||
|
||||
header_text = None
|
||||
sub_header_text = None
|
||||
@ -48,81 +53,81 @@ def extract_data(html):
|
||||
table_counter = 0
|
||||
|
||||
# Extract elements while preserving order
|
||||
for element in soup.find_all(['h1', 'h2', 'p', 'pre', 'input', 'select', 'textarea', 'button', 'table']):
|
||||
if element.name == 'h1':
|
||||
for element in soup.find_all(
|
||||
["h1", "h2", "p", "pre", "input", "select", "textarea", "button", "table"]
|
||||
):
|
||||
if element.name == "h1":
|
||||
header_text = element.get_text(strip=True)
|
||||
records.append({
|
||||
'Type': 'Header',
|
||||
'Text': header_text
|
||||
})
|
||||
records.append({"Type": "Header", "Text": header_text})
|
||||
|
||||
elif element.name == 'h2':
|
||||
elif element.name == "h2":
|
||||
sub_header_text = element.get_text(strip=True)
|
||||
records.append({
|
||||
'Type': 'SubHeader',
|
||||
'Text': sub_header_text
|
||||
})
|
||||
records.append({"Type": "SubHeader", "Text": sub_header_text})
|
||||
|
||||
elif element.name == 'p':
|
||||
elif element.name == "p":
|
||||
text = element.get_text(strip=True)
|
||||
if text: # Ignore empty paragraphs
|
||||
#Sanitise text freom newlines,tabs and escape quotes.
|
||||
records.append({
|
||||
'Type': 'Paragraph',
|
||||
'Text': sanitize_text(text)
|
||||
})
|
||||
# Sanitise text freom newlines,tabs and escape quotes.
|
||||
records.append({"Type": "Paragraph", "Text": sanitize_text(text)})
|
||||
|
||||
elif element.name == 'pre':
|
||||
elif element.name == "pre":
|
||||
text = element.get_text(strip=True)
|
||||
if text: # Ensure non-empty before adding
|
||||
records.append({
|
||||
'Type': 'Preformatted',
|
||||
'Text': text
|
||||
})
|
||||
records.append({"Type": "Preformatted", "Text": text})
|
||||
|
||||
elif element.name == 'input':
|
||||
if element.get('type') == 'hidden' or element.get('name') in hidden_input_names:
|
||||
elif element.name == "input":
|
||||
if (
|
||||
element.get("type") == "hidden"
|
||||
or element.get("name") in hidden_input_names
|
||||
):
|
||||
continue
|
||||
|
||||
|
||||
input_info = {
|
||||
'Type': element.get('type', 'text').capitalize(),
|
||||
'Name': element.get('name'),
|
||||
'Value': element.get('value', ''),
|
||||
"Type": element.get("type", "text").capitalize(),
|
||||
"Name": element.get("name"),
|
||||
"Value": element.get("value", ""),
|
||||
}
|
||||
label = element.find_next('label')
|
||||
input_info['Label'] = label.get_text(strip=True) if label else None
|
||||
label = element.find_next("label")
|
||||
input_info["Label"] = label.get_text(strip=True) if label else None
|
||||
records.append(input_info)
|
||||
|
||||
elif element.name == 'select':
|
||||
options = [{'Value': option.get('value'), 'Text': option.get_text(strip=True)} for option in element.find_all('option')]
|
||||
elif element.name == "select":
|
||||
options = [
|
||||
{"Value": option.get("value"), "Text": option.get_text(strip=True)}
|
||||
for option in element.find_all("option")
|
||||
]
|
||||
select_info = {
|
||||
'Type': 'Select',
|
||||
'Name': element.get('name'),
|
||||
'Options': options,
|
||||
'Label': element.find_previous('label').get_text(strip=True) if element.find_previous('label') else None,
|
||||
"Type": "Select",
|
||||
"Name": element.get("name"),
|
||||
"Options": options,
|
||||
"Label": element.find_previous("label").get_text(strip=True)
|
||||
if element.find_previous("label")
|
||||
else None,
|
||||
}
|
||||
records.append(select_info)
|
||||
|
||||
elif element.name == 'textarea':
|
||||
elif element.name == "textarea":
|
||||
textarea_info = {
|
||||
'Type': 'Textarea',
|
||||
'Name': element.get('name'),
|
||||
'Value': element.get_text(strip=True),
|
||||
"Type": "Textarea",
|
||||
"Name": element.get("name"),
|
||||
"Value": element.get_text(strip=True),
|
||||
}
|
||||
label = element.find_previous('label')
|
||||
textarea_info['Label'] = label.get_text(strip=True) if label else None
|
||||
label = element.find_previous("label")
|
||||
textarea_info["Label"] = label.get_text(strip=True) if label else None
|
||||
records.append(textarea_info)
|
||||
|
||||
elif element.name == 'button':
|
||||
elif element.name == "button":
|
||||
button_info = {
|
||||
'Type': 'Button',
|
||||
'Name': element.get('name'),
|
||||
'Value': element.get_text(strip=True),
|
||||
'Label': element.find_previous('label').get_text(strip=True) if label else None,
|
||||
"Type": "Button",
|
||||
"Name": element.get("name"),
|
||||
"Value": element.get_text(strip=True),
|
||||
"Label": element.find_previous("label").get_text(strip=True)
|
||||
if label
|
||||
else None,
|
||||
}
|
||||
records.append(button_info)
|
||||
|
||||
elif element.name == 'table' and 'sme-border' in element.get('class', []):
|
||||
elif element.name == "table" and "sme-border" in element.get("class", []):
|
||||
# Increment the table counter
|
||||
table_counter += 1
|
||||
|
||||
@ -132,37 +137,47 @@ def extract_data(html):
|
||||
columns = []
|
||||
|
||||
# Extract headings from the first row
|
||||
first_row = element.find('tr')
|
||||
first_row = element.find("tr")
|
||||
if first_row:
|
||||
for th in first_row.find_all('th'):
|
||||
for th in first_row.find_all("th"):
|
||||
top_headings.append(th.get_text(strip=True))
|
||||
|
||||
# Extract only the first data row's cell values for Columns
|
||||
data_rows = element.find_all('tr')[1:] # Skip the heading row
|
||||
data_rows = element.find_all("tr")[1:] # Skip the heading row
|
||||
if data_rows:
|
||||
first_data_row = data_rows[0] # Take the first row of data
|
||||
for idx, th in enumerate(first_row.find_all('th')):
|
||||
td = first_data_row.find_all('td')[idx] if idx < len(first_data_row.find_all('td')) else None
|
||||
for idx, th in enumerate(first_row.find_all("th")):
|
||||
td = (
|
||||
first_data_row.find_all("td")[idx]
|
||||
if idx < len(first_data_row.find_all("td"))
|
||||
else None
|
||||
)
|
||||
if td:
|
||||
columns.append(f"{table_control}-{th.get_text(strip=True)}") # Format as desired
|
||||
columns.append(
|
||||
f"{table_control}-{th.get_text(strip=True)}"
|
||||
) # Format as desired
|
||||
|
||||
records.append({
|
||||
'Type': 'Table',
|
||||
'TableControl': table_control,
|
||||
'TopHeadings': top_headings,
|
||||
'Columns': columns,
|
||||
})
|
||||
records.append(
|
||||
{
|
||||
"Type": "Table",
|
||||
"TableControl": table_control,
|
||||
"TopHeadings": top_headings,
|
||||
"Columns": columns,
|
||||
}
|
||||
)
|
||||
|
||||
return records, header_text, sub_header_text
|
||||
|
||||
|
||||
def insert_spaces_before_caps(text):
|
||||
"""Insert spaces before each capital letter in a given string."""
|
||||
return re.sub(r'(?<!^)(?=[A-Z])', ' ', text)
|
||||
return re.sub(r"(?<!^)(?=[A-Z])", " ", text)
|
||||
|
||||
|
||||
def save_to_json5(data, output_filename, package_name, header, sub_header):
|
||||
"""Save extracted data to a JSON5 file with a specific structure."""
|
||||
# Generate prefix from uppercase letters in PackageName made into lowercase
|
||||
prefix = ''.join(re.findall(r'[A-Z]', package_name)).lower()
|
||||
prefix = "".join(re.findall(r"[A-Z]", package_name)).lower()
|
||||
|
||||
# Prepare structured html list
|
||||
structured_html = []
|
||||
@ -172,103 +187,131 @@ def save_to_json5(data, output_filename, package_name, header, sub_header):
|
||||
table_count = 1
|
||||
|
||||
for record in data:
|
||||
if record['Type'] == 'Paragraph':
|
||||
structured_html.append({
|
||||
f'Paragraph{paragraph_count}': record['Text']
|
||||
})
|
||||
if record["Type"] == "Paragraph":
|
||||
structured_html.append({f"Paragraph{paragraph_count}": record["Text"]})
|
||||
paragraph_count += 1
|
||||
elif record['Type'] == 'Preformatted':
|
||||
structured_html.append({
|
||||
f'Preformatted{preformatted_count}': record['Text']
|
||||
})
|
||||
elif record["Type"] == "Preformatted":
|
||||
structured_html.append(
|
||||
{f"Preformatted{preformatted_count}": record["Text"]}
|
||||
)
|
||||
preformatted_count += 1
|
||||
elif record['Type'] == 'Header' or record['Type'] == 'SubHeader':
|
||||
elif record["Type"] == "Header" or record["Type"] == "SubHeader":
|
||||
continue # Skip headers for input count
|
||||
elif record['Type'] == 'Table':
|
||||
elif record["Type"] == "Table":
|
||||
# Construct the table entry
|
||||
table_structure = {
|
||||
'Type': record['Type'],
|
||||
'TableControl': record['TableControl'],
|
||||
'TopHeadings': record['TopHeadings'],
|
||||
'Columns': record['Columns']
|
||||
"Type": record["Type"],
|
||||
"TableControl": record["TableControl"],
|
||||
"TopHeadings": record["TopHeadings"],
|
||||
"Columns": record["Columns"],
|
||||
}
|
||||
structured_html.append({
|
||||
f'Table{table_count}': table_structure
|
||||
})
|
||||
structured_html.append({f"Table{table_count}": table_structure})
|
||||
table_count += 1
|
||||
else: # For inputs, selects, textareas, and buttons
|
||||
input_structure = {
|
||||
'Type': record['Type'],
|
||||
'Value': record.get('Value', ''), # Safely access Value
|
||||
"Type": record["Type"],
|
||||
"Value": record.get("Value", ""), # Safely access Value
|
||||
}
|
||||
|
||||
# Use .get() for the Name key to avoid KeyError
|
||||
input_structure['Name'] = record.get('Name', None) # Set to None if not present
|
||||
input_structure['Label'] = record.get('Label', None) # Set to None if not present
|
||||
input_structure["Name"] = record.get(
|
||||
"Name", None
|
||||
) # Set to None if not present
|
||||
input_structure["Label"] = record.get(
|
||||
"Label", None
|
||||
) # Set to None if not present
|
||||
|
||||
# Handle specific case for Select options
|
||||
if 'Options' in record:
|
||||
input_structure['Options'] = record['Options']
|
||||
if "Options" in record:
|
||||
input_structure["Options"] = record["Options"]
|
||||
|
||||
structured_html.append({
|
||||
f'Input{input_count}': input_structure
|
||||
})
|
||||
structured_html.append({f"Input{input_count}": input_structure})
|
||||
input_count += 1
|
||||
|
||||
# Wrap the records with the required fields
|
||||
json5_data = {
|
||||
'PackageName': package_name,
|
||||
'prefix': prefix,
|
||||
'MenuHeading': 'Miscellaneous',
|
||||
'MenuDescription': insert_spaces_before_caps(package_name),
|
||||
'MenuNavigation': '2000 400',
|
||||
'firstPanel': 'PARAMS',
|
||||
'signalEvent': f'smeserver-{package_name.lower()}-update',
|
||||
'html': {
|
||||
'Name': 'params',
|
||||
'route': 'PARAMS',
|
||||
'Header': header if header else f'{package_name} Contrib',
|
||||
'SubHeader': sub_header if sub_header else f'Manage {package_name} settings:',
|
||||
**{k: v for item in structured_html for k, v in item.items()} # Flatten the structured_html into the dict
|
||||
}
|
||||
"PackageName": package_name,
|
||||
"prefix": prefix,
|
||||
"MenuHeading": "Miscellaneous",
|
||||
"MenuDescription": insert_spaces_before_caps(package_name),
|
||||
"MenuNavigation": "2000 400",
|
||||
"firstPanel": "PARAMS",
|
||||
"signalEvent": f"smeserver-{package_name.lower()}-update",
|
||||
"html": [{
|
||||
"Name": "params",
|
||||
"route": "PARAMS",
|
||||
"Header": header if header else f"{package_name} Contrib",
|
||||
"SubHeader": sub_header
|
||||
if sub_header
|
||||
else f"Manage {package_name} settings:",
|
||||
**{
|
||||
k: v for item in structured_html for k, v in item.items()
|
||||
}, # Flatten the structured_html into the dict
|
||||
}],
|
||||
}
|
||||
|
||||
# Save in JSON5 format (JSON with comments and unquoted keys)
|
||||
with open(output_filename, 'w', encoding='utf-8') as json_file:
|
||||
with open(output_filename, "w", encoding="utf-8") as json_file:
|
||||
json.dump(json5_data, json_file, ensure_ascii=False, indent=4)
|
||||
|
||||
|
||||
# Manually format as JSON5 by adding single quotes (for simplicity)
|
||||
with open(output_filename, 'r+', encoding='utf-8') as json_file:
|
||||
with open(output_filename, "r+", encoding="utf-8") as json_file:
|
||||
content = json_file.read()
|
||||
content = content.replace('"', "'") # Replace double quotes with single quotes for JSON5
|
||||
content = content.replace(
|
||||
'"', "'"
|
||||
) # Replace double quotes with single quotes for JSON5
|
||||
json_file.seek(0)
|
||||
json_file.write(content)
|
||||
json_file.truncate() # Remove any old content beyond the new content length
|
||||
|
||||
|
||||
def main():
|
||||
input_file = '/home/brianr/clients/SM2/SM2Gen/venv/html/CreateStarterWebsite.html' # Specify the input HTML file path
|
||||
# command line parameters
|
||||
parser = argparse.ArgumentParser(description="sm1--html-2-jsopn5")
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--filename",
|
||||
help="Specify a filename for the html file",
|
||||
default="CreateStarterWebsite.html",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
input_file = "/home/brianr/clients/SM2/SM2Gen/venv/html/" + args.filename
|
||||
if not input_file.lower().endswith(".html"):
|
||||
# Add .html extension
|
||||
input_file += ".html"
|
||||
print(input_file)
|
||||
|
||||
# Read HTML content
|
||||
html_content = read_html_file(input_file)
|
||||
# Read HTML content
|
||||
html_content = read_html_file(input_file)
|
||||
|
||||
# Validate the HTML before extracting data
|
||||
validate_html(html_content)
|
||||
# Validate the HTML before extracting data
|
||||
validate_html(html_content)
|
||||
|
||||
# Extract data from HTML
|
||||
data, header, sub_header = extract_data(html_content)
|
||||
# Extract data from HTML
|
||||
data, header, sub_header = extract_data(html_content)
|
||||
#
|
||||
# Generate output JSON5 filename based on input file name
|
||||
#
|
||||
# Split the original path into directory and file name
|
||||
directory, filename = os.path.split(input_file)
|
||||
|
||||
# Generate output JSON5 filename based on input file name
|
||||
base_name = os.path.basename(input_file) # Get the file name (with extension)
|
||||
package_name = os.path.splitext(base_name)[0] # Use the filename without extension
|
||||
json_filename = package_name + '.json5' # Change extension to .json5
|
||||
# Replace 'html' with 'json5' in the directory path
|
||||
new_directory = directory.replace('/html', '/json5')
|
||||
#print(new_directory)
|
||||
|
||||
# Create the output file path in the same directory
|
||||
output_directory = os.path.dirname(input_file)
|
||||
output_file = os.path.join(output_directory, json_filename)
|
||||
# Construct the new path
|
||||
output_file = os.path.join(new_directory, filename.replace('.html', '.json5'))
|
||||
print(output_file)
|
||||
#quit(1)
|
||||
|
||||
# Generate output JSON5 filename based on input file name
|
||||
base_name = os.path.basename(input_file) # Get the file name (with extension)
|
||||
package_name = os.path.splitext(base_name)[0] # Use the filename without extension
|
||||
|
||||
# Save extracted data to JSON5
|
||||
save_to_json5(data, output_file, package_name, header, sub_header)
|
||||
print(f"Extracted data saved to '{output_file}'.")
|
||||
# Save extracted data to JSON5
|
||||
save_to_json5(data, output_file, package_name, header, sub_header)
|
||||
print(f"Extracted data saved to '{output_file}'.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
699
sm2gen.py
699
sm2gen.py
@ -306,371 +306,384 @@ def convert_lex_to_dict(pairs_string):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
chameleon_version = pkg_resources.get_distribution("Chameleon").version
|
||||
except pkg_resources.DistributionNotFound:
|
||||
chameleon_version = "Version information not available"
|
||||
python_version = sys.version
|
||||
version_pattern = r'(\d{1,3}\.\d{1,3}\.\d{1,3})'
|
||||
version_match = re.search(version_pattern, python_version)
|
||||
python_version = version_match.group(0) if version_match else 'Unknown'
|
||||
current_datetime = datetime.now()
|
||||
formatted_datetime = current_datetime.strftime("%Y-%m-%d %H:%M")
|
||||
strVersion = (
|
||||
"SM2Gen version:"
|
||||
+ SME2Gen_version
|
||||
+ " Chameleon version:"
|
||||
+ chameleon_version
|
||||
+ " On Python:"
|
||||
+ python_version
|
||||
+ " at "
|
||||
+ formatted_datetime
|
||||
)
|
||||
try:
|
||||
chameleon_version = pkg_resources.get_distribution("Chameleon").version
|
||||
except pkg_resources.DistributionNotFound:
|
||||
chameleon_version = "Version information not available"
|
||||
python_version = sys.version
|
||||
version_pattern = r"(\d{1,3}\.\d{1,3}\.\d{1,3})"
|
||||
version_match = re.search(version_pattern, python_version)
|
||||
python_version = version_match.group(0) if version_match else "Unknown"
|
||||
current_datetime = datetime.now()
|
||||
formatted_datetime = current_datetime.strftime("%Y-%m-%d %H:%M")
|
||||
strVersion = (
|
||||
"SM2Gen version:"
|
||||
+ SME2Gen_version
|
||||
+ " Chameleon version:"
|
||||
+ chameleon_version
|
||||
+ " On Python:"
|
||||
+ python_version
|
||||
+ " at "
|
||||
+ formatted_datetime
|
||||
)
|
||||
|
||||
json5_dict: dict = {}
|
||||
json5_html_list: list = []
|
||||
json5_dict: dict = {}
|
||||
json5_html_list: list = []
|
||||
|
||||
print(f"SM2 code from JSON5 - {strVersion}")
|
||||
print(f"SM2 code from JSON5 - {strVersion}")
|
||||
|
||||
home_dir = "/home/brianr/clients/SM2/SM2Gen/"
|
||||
json_filename = f"{home_dir}/json5/nfsshare.json5" #CreateStarterWebsite.json5"
|
||||
home_dir = "/home/brianr/clients/SM2/SM2Gen/"
|
||||
json_filename = f"{home_dir}/json5/nfsshare.json5" # CreateStarterWebsite.json5"
|
||||
|
||||
# read open ai key from ini file
|
||||
# Check if the file exists
|
||||
if os.path.exists(ini_file_path):
|
||||
# Create a configparser object and read the file
|
||||
config = configparser.ConfigParser()
|
||||
config.read(ini_file_path)
|
||||
# read open ai key from ini file
|
||||
# Check if the file exists
|
||||
if os.path.exists(ini_file_path):
|
||||
# Create a configparser object and read the file
|
||||
config = configparser.ConfigParser()
|
||||
config.read(ini_file_path)
|
||||
|
||||
# Read the value of "OPENAI_API_KEY"
|
||||
if "OPENAI_API_KEY" in config["smegit"]:
|
||||
OPENAI_API_KEY = config["smegit"]["OPENAI_API_KEY"]
|
||||
# print("API Key:", OPENAI_API_KEY)
|
||||
client = OpenAI(api_key=OPENAI_API_KEY)
|
||||
else:
|
||||
print("OPENAI_API_KEY not found in the configuration file.")
|
||||
else:
|
||||
print("Configuration file not found at:", file_path)
|
||||
# Read the value of "OPENAI_API_KEY"
|
||||
if "OPENAI_API_KEY" in config["smegit"]:
|
||||
OPENAI_API_KEY = config["smegit"]["OPENAI_API_KEY"]
|
||||
# print("API Key:", OPENAI_API_KEY)
|
||||
client = OpenAI(api_key=OPENAI_API_KEY)
|
||||
else:
|
||||
print("OPENAI_API_KEY not found in the configuration file.")
|
||||
else:
|
||||
print("Configuration file not found at:", file_path)
|
||||
|
||||
# Command line parameters - not in use
|
||||
parser = argparse.ArgumentParser(description="SM2Gen")
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--filename",
|
||||
help="Specify a filename for the JSON5 file",
|
||||
default=json_filename,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-nco",
|
||||
"--noController",
|
||||
help="Stop it creating a controller file",
|
||||
default="yes",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-nh", "--noHtml", help="Stop it creating html files(s)", default="yes"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-nl",
|
||||
"--noLang",
|
||||
help="Stop it creating language localise files(s)",
|
||||
default="yes",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-ncu", "--noCust", help="Stop it creating Custom controller file", default="yes"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
json_filename = args.filename
|
||||
print(
|
||||
f"JSON5 from {json_filename} with noController={args.noController}, noHtml={args.noHtml} and noLang={args.noLang}"
|
||||
) # Not yet activated
|
||||
|
||||
#check if json5 file exists
|
||||
json_file_path = Path(json_filename)
|
||||
if not json_file_path.exists():
|
||||
print(f"json5 file: {json_filename} not found")
|
||||
quit(1)
|
||||
# Command line parameters - not in use
|
||||
parser = argparse.ArgumentParser(description="SM2Gen")
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--filename",
|
||||
help="Specify a filename for the JSON5 file",
|
||||
default=json_filename,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-nco",
|
||||
"--noController",
|
||||
help="Stop it creating a controller file",
|
||||
default="yes",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-nh", "--noHtml", help="Stop it creating html files(s)", default="yes"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-nl",
|
||||
"--noLang",
|
||||
help="Stop it creating language localise files(s)",
|
||||
default="yes",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-ncu",
|
||||
"--noCust",
|
||||
help="Stop it creating Custom controller file",
|
||||
default="yes",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
json_filename = args.filename
|
||||
print(
|
||||
f"JSON5 from {json_filename} with noController={args.noController}, noHtml={args.noHtml} and noLang={args.noLang}"
|
||||
) # Not yet activated
|
||||
|
||||
# check syntax of JSON5
|
||||
lint_json5(json_filename)
|
||||
# check if json5 file exists
|
||||
json_file_path = Path(json_filename)
|
||||
if not json_file_path.exists():
|
||||
print(f"json5 file: {json_filename} not found")
|
||||
quit(1)
|
||||
|
||||
# Get dict of it all
|
||||
json5_dict = json5_to_dict(json_filename)
|
||||
# check syntax of JSON5
|
||||
lint_json5(json_filename)
|
||||
|
||||
# Get dict of just the html bit
|
||||
json5_html_list = json5_dict["html"]
|
||||
# Get dict of it all
|
||||
json5_dict = json5_to_dict(json_filename)
|
||||
|
||||
# Identify message
|
||||
print(f"\nGenerating mojo panels for {hl('PackageName')}")
|
||||
print("-----------------------------------")
|
||||
# Get dict of just the html bit
|
||||
json5_html_list = json5_dict["html"]
|
||||
|
||||
# Routes for each panel
|
||||
routes = get_all_routes()
|
||||
lc_routes = lc_get_all_routes()
|
||||
# Identify message
|
||||
print(f"\nGenerating mojo panels for {hl('PackageName')}")
|
||||
print("-----------------------------------")
|
||||
|
||||
# File names
|
||||
# Define the path for the generated files
|
||||
directory_path = Path("Targets/" + hl("PackageName"))
|
||||
# Create the directory if it doesn't exist
|
||||
directory_path.mkdir(parents=True, exist_ok=True)
|
||||
target_directory_path = "Targets/" + hl("PackageName")+"/"
|
||||
# Routes for each panel
|
||||
routes = get_all_routes()
|
||||
lc_routes = lc_get_all_routes()
|
||||
|
||||
controller_file = target_directory_path + hl("PackageName") + ".pm"
|
||||
custom_controller_file = target_directory_path + hl("PackageName") + "-Custom.pm"
|
||||
# Call it .new if one is already there (and may have been editted by the developer)
|
||||
if os.path.exists(custom_controller_file):
|
||||
custom_controller_file = custom_controller_file + ".new"
|
||||
layout_file = target_directory_path + hl("PackageName").lower() + ".html.ep"
|
||||
partial_files = list()
|
||||
for panel in routes:
|
||||
partial_files.append(target_directory_path + hl("prefix") + "_" + panel + ".html.ep")
|
||||
print(f"Partial files to be created:{partial_files}")
|
||||
lex_file = target_directory_path + hl("PackageName").lower() + "_en.lex"
|
||||
tablecontrols = (
|
||||
get_table_control_data()
|
||||
) # arrays of hashes used to drive rows in tables
|
||||
# File names
|
||||
# Define the path for the generated files
|
||||
directory_path = Path("Targets/" + hl("PackageName"))
|
||||
# Create the directory if it doesn't exist
|
||||
directory_path.mkdir(parents=True, exist_ok=True)
|
||||
target_directory_path = "Targets/" + hl("PackageName") + "/"
|
||||
|
||||
# print(strVersion,tablecontrols,routes)
|
||||
controller_file = target_directory_path + hl("PackageName") + ".pm"
|
||||
custom_controller_file = target_directory_path + hl("PackageName") + "-Custom.pm"
|
||||
# Call it .new if one is already there (and may have been editted by the developer)
|
||||
if os.path.exists(custom_controller_file):
|
||||
custom_controller_file = custom_controller_file + ".new"
|
||||
layout_file = target_directory_path + hl("PackageName").lower() + ".html.ep"
|
||||
partial_files = list()
|
||||
for panel in routes:
|
||||
partial_files.append(
|
||||
target_directory_path + '_' + hl("prefix") + "_" + panel + ".html.ep"
|
||||
)
|
||||
print(f"Partial files to be created:{partial_files}")
|
||||
lex_file = target_directory_path + hl("PackageName").lower() + "_en.lex"
|
||||
tablecontrols = (
|
||||
get_table_control_data()
|
||||
) # arrays of hashes used to drive rows in tables
|
||||
|
||||
# Generate controller file
|
||||
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,
|
||||
**json5_dict,
|
||||
panels=routes,
|
||||
lcPackageName=json5_dict["PackageName"].lower(),
|
||||
)
|
||||
with open(controller_file, "w") as file:
|
||||
file.write(controller_perl)
|
||||
print(f"{controller_file} controller generated ok")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon controller render error occurred: {e}")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon controller template error occurred: {e}")
|
||||
# print(strVersion,tablecontrols,routes)
|
||||
|
||||
# Generate Custom controller file
|
||||
try:
|
||||
custom_controller_template = PageTemplateFile("Templates/custom.pm.tem")
|
||||
try:
|
||||
custom_controller_perl = custom_controller_template.render(
|
||||
version=strVersion, panels=routes, tablecontrols=tablecontrols
|
||||
)
|
||||
# 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:
|
||||
file.write(custom_controller_perl)
|
||||
print(f"{custom_controller_file} custom controller generated ok")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon custom controller render error occurred: {e}")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon custom controller template error occurred: {e}")
|
||||
# Generate controller file
|
||||
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,
|
||||
**json5_dict,
|
||||
panels=routes,
|
||||
lcPackageName=json5_dict["PackageName"].lower(),
|
||||
)
|
||||
with open(controller_file, "w") as file:
|
||||
file.write(controller_perl)
|
||||
print(f"{controller_file} controller generated ok")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon controller render error occurred: {e}")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon controller template error occurred: {e}")
|
||||
|
||||
# generate Layout file
|
||||
layout_template = PageTemplateFile("Templates/layout.html.ep.tem")
|
||||
try:
|
||||
try:
|
||||
layout_mojo = layout_template.render(
|
||||
version=strVersion, **json5_dict, conditions=routes
|
||||
)
|
||||
with open(layout_file, "w") as file:
|
||||
file.write(layout_mojo)
|
||||
print(f"{layout_file} mojo template layout file generated ok")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon render on layout file error occurred: {e}")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon template layout file error occurred: {e}")
|
||||
# Generate Custom controller file
|
||||
try:
|
||||
custom_controller_template = PageTemplateFile("Templates/custom.pm.tem")
|
||||
try:
|
||||
custom_controller_perl = custom_controller_template.render(
|
||||
version=strVersion, panels=routes, tablecontrols=tablecontrols
|
||||
)
|
||||
# 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:
|
||||
file.write(custom_controller_perl)
|
||||
print(f"{custom_controller_file} custom controller generated ok")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon custom controller render error occurred: {e}")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon custom controller template error occurred: {e}")
|
||||
|
||||
# Generate a partial file for each of the entries in the html list
|
||||
# Pull in the template code for each of the input types
|
||||
# html_controls = json5_to_dict('Templates/html_controls.html.ep.tem')
|
||||
html_controls = parse_xml_to_dict("Templates/html_controls.html.ep.xml")
|
||||
i = 0
|
||||
for html in json5_html_list:
|
||||
# Generate a mojo template file, and then add in the controls
|
||||
# main file first
|
||||
try:
|
||||
partial_template = PageTemplateFile("Templates/partial.html.ep.tem")
|
||||
partial_mojo_context = {**json5_dict, **html}
|
||||
try:
|
||||
partial_mojo_template = partial_template.render(
|
||||
version=strVersion, **partial_mojo_context
|
||||
)
|
||||
with open(partial_files[i], "w") as file:
|
||||
file.write(partial_mojo_template)
|
||||
print(f"{partial_files[i]} mojo template generated ok - phase 1")
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render error on partial file {html['route']} occurred: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"A Chameleon html {html['route']} error occurred: {e}")
|
||||
# generate Layout file
|
||||
layout_template = PageTemplateFile("Templates/layout.html.ep.tem")
|
||||
try:
|
||||
try:
|
||||
layout_mojo = layout_template.render(
|
||||
version=strVersion, **json5_dict, conditions=routes
|
||||
)
|
||||
with open(layout_file, "w") as file:
|
||||
file.write(layout_mojo)
|
||||
print(f"{layout_file} mojo template layout file generated ok")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon render on layout file error occurred: {e}")
|
||||
except Exception as e:
|
||||
print(f"A Chameleon template layout file error occurred: {e}")
|
||||
|
||||
# Now generate the controls from the rest of the entries in the dict.
|
||||
all_controls_html = ""
|
||||
prefix_is = hl("prefix")
|
||||
for html_control in html:
|
||||
inner_html = html[html_control]
|
||||
if isinstance(inner_html, dict):
|
||||
try:
|
||||
control_template = PageTemplate(html_controls[inner_html["Type"]])
|
||||
try:
|
||||
control_html = control_template.render(
|
||||
version=strVersion, **inner_html, prefix=prefix_is
|
||||
)
|
||||
all_controls_html = all_controls_html + control_html
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render on partial file control {inner_html['Name']} error occurred: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render on partial file control {inner_html['Name']} error occurred: {e}"
|
||||
)
|
||||
else:
|
||||
# just a simple entry - name less numerics is type
|
||||
html_Type = "".join(char for char in html_control if not char.isdigit())
|
||||
try:
|
||||
simple_control_template = PageTemplate(html_controls[html_Type])
|
||||
try:
|
||||
simple_control_html = simple_control_template.render(
|
||||
version=strVersion, value=inner_html, prefix=prefix_is
|
||||
)
|
||||
all_controls_html = all_controls_html + simple_control_html
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render on partial file control {html_control} error occurred: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon template partial file control {html_control} error occurred: {e}"
|
||||
)
|
||||
# Generate a partial file for each of the entries in the html list
|
||||
# Pull in the template code for each of the input types
|
||||
# html_controls = json5_to_dict('Templates/html_controls.html.ep.tem')
|
||||
html_controls = parse_xml_to_dict("Templates/html_controls.html.ep.xml")
|
||||
i = 0
|
||||
for html in json5_html_list:
|
||||
# Generate a mojo template file, and then add in the controls
|
||||
# main file first
|
||||
try:
|
||||
partial_template = PageTemplateFile("Templates/partial.html.ep.tem")
|
||||
partial_mojo_context = {**json5_dict, **html}
|
||||
try:
|
||||
partial_mojo_template = partial_template.render(
|
||||
version=strVersion, **partial_mojo_context
|
||||
)
|
||||
with open(partial_files[i], "w") as file:
|
||||
file.write(partial_mojo_template)
|
||||
print(f"{partial_files[i]} mojo template generated ok - phase 1")
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render error on partial file {html['route']} occurred: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"A Chameleon html {html['route']} error occurred: {e}")
|
||||
|
||||
# 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(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),
|
||||
)
|
||||
# Now generate the controls from the rest of the entries in the dict.
|
||||
all_controls_html = ""
|
||||
prefix_is = hl("prefix")
|
||||
for html_control in html:
|
||||
inner_html = html[html_control]
|
||||
if isinstance(inner_html, dict):
|
||||
try:
|
||||
control_template = PageTemplate(html_controls[inner_html["Type"]])
|
||||
try:
|
||||
control_html = control_template.render(
|
||||
version=strVersion, **inner_html, prefix=prefix_is
|
||||
)
|
||||
all_controls_html = all_controls_html + control_html
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render on partial file control {inner_html['Name']} error occurred: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render on partial file control {inner_html['Name']} error occurred: {e}"
|
||||
)
|
||||
else:
|
||||
# just a simple entry - name less numerics is type
|
||||
html_Type = "".join(char for char in html_control if not char.isdigit())
|
||||
try:
|
||||
simple_control_template = PageTemplate(html_controls[html_Type])
|
||||
try:
|
||||
simple_control_html = simple_control_template.render(
|
||||
version=strVersion, value=inner_html, prefix=prefix_is
|
||||
)
|
||||
all_controls_html = all_controls_html + simple_control_html
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon render on partial file control {html_control} error occurred: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(
|
||||
f"A Chameleon template partial file control {html_control} error occurred: {e}"
|
||||
)
|
||||
|
||||
# Insert the string at the specified index
|
||||
lines.insert(index + 1, all_controls_html + "\n")
|
||||
# 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(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),
|
||||
)
|
||||
|
||||
# Write the modified content back to the file
|
||||
with open(partial_files[i], "w") as file:
|
||||
file.writelines(lines)
|
||||
print(f"Content modified and saved to {partial_files[i]}")
|
||||
i += 1
|
||||
# Insert the string at the specified index
|
||||
lines.insert(index + 1, all_controls_html + "\n")
|
||||
|
||||
# Now generate the <name>.en file
|
||||
# Look through the generated files for the /l[\s|(]['|"](.*)['|"]\)/ strings.
|
||||
# Write the modified content back to the file
|
||||
with open(partial_files[i], "w") as file:
|
||||
file.writelines(lines)
|
||||
print(f"Content modified and saved to {partial_files[i]}")
|
||||
i += 1
|
||||
|
||||
# create a combined list of all the files
|
||||
all_files = [controller_file, layout_file] + partial_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)
|
||||
all_strings = all_strings + extracted_strings
|
||||
# Take out any duplicates
|
||||
all_strings = deduplicate_array(all_strings)
|
||||
# '<prefix>_english-message' => 'English Message',
|
||||
string_lib = [] # Array of dicts
|
||||
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 leave it for the right
|
||||
# Map all spaces to "_" on left hand side
|
||||
# amd truncate it to max five words
|
||||
original_str = lex_message
|
||||
# Checkif it starts with the prefix (any case|)
|
||||
if lex_message.lower().startswith(hl("prefix").lower()):
|
||||
left_str = lex_message
|
||||
right_str = lex_message[len(hl("prefix")) + 1 :]
|
||||
# And take out any "_", map to " "
|
||||
else:
|
||||
left_str = hl("prefix") + "_" + lex_message
|
||||
right_str = lex_message
|
||||
right_str = right_str.replace("_", " ")
|
||||
# print(f"Right:{right_str}")
|
||||
right_str = format_text(right_str)
|
||||
left_str = left_str.replace(" ", "_")
|
||||
words = left_str.split("_")[:6]
|
||||
left_str = "_".join(words)
|
||||
next_lex_str = {"orig": original_str, "left": left_str, "right": right_str}
|
||||
string_lib.append(next_lex_str)
|
||||
# And write it to lex file
|
||||
# Now process them one by one into the lexical file
|
||||
lex_all = ""
|
||||
for lex_str in string_lib:
|
||||
lex_all += f"'{lex_str['left']}' => '{lex_str['right']}',\n"
|
||||
print(f"Writing {lex_file}")
|
||||
with open(lex_file, "w") as file:
|
||||
file.write(lex_all)
|
||||
# and then play the strings back into the partials and the layout file
|
||||
print("..and feed the lex string names back into other files")
|
||||
for filename in all_files:
|
||||
with open(filename, "r") as file:
|
||||
file_content = file.read()
|
||||
# Scan through
|
||||
for item in string_lib:
|
||||
original_str = item["orig"]
|
||||
left_str = item["left"]
|
||||
right_str = item["right"]
|
||||
# Replace all occurrences of original string with left string in 'contents'
|
||||
file_content = file_content.replace(
|
||||
"l('" + original_str + "')", "l('" + left_str + "')"
|
||||
)
|
||||
# and write it back
|
||||
with open(filename, "w") as file:
|
||||
file.write(file_content)
|
||||
print(f"Write out modified:{filename}")
|
||||
# Now generate the <name>.en file
|
||||
# Look through the generated files for the /l[\s|(]['|"](.*)['|"]\)/ strings.
|
||||
|
||||
# Now generate all the translated lex files from a list of the languages and codes
|
||||
# if specifically requested
|
||||
if not args.noLang:
|
||||
languages_path = "Templates/languages.json"
|
||||
with open(languages_path, "r") as file:
|
||||
languages_str = file.read()
|
||||
lang_dict = json.loads(languages_str)
|
||||
with open(lex_file, "r") as file:
|
||||
lex_str = file.read()
|
||||
eng_lex_dict = convert_lex_to_dict(lex_str)
|
||||
for lang_item in lang_dict:
|
||||
print(f"Translating from english lex file to {lang_item['language']}")
|
||||
code = lang_item["code"]
|
||||
translated_lex_file = f"{target_directory_path}{hl('PackageName').lower()}_{code}.lex"
|
||||
# Only do it if the lex file is missing
|
||||
if not os.path.exists(translated_lex_file):
|
||||
translated_dict = []
|
||||
for lex_item in eng_lex_dict:
|
||||
# Get it from ChatGPT
|
||||
translated_text = get_translation(
|
||||
lex_item["text"], lang_item["language"]
|
||||
)
|
||||
translated_dict.append({"id": lex_item["id"], "text": translated_text})
|
||||
print(f"Writing out lex file for {lang_item['code']}")
|
||||
with open(translated_lex_file, "w") as file:
|
||||
for item in translated_dict:
|
||||
# escape any nasties
|
||||
translated_text = (
|
||||
item["text"]
|
||||
.replace("\\", r"\\")
|
||||
.replace('"', r"\"")
|
||||
.replace("'", r"\'")
|
||||
)
|
||||
line = "'" + item["id"] + "' => " + '"' + translated_text + '",\n'
|
||||
file.write(line)
|
||||
# print(f"{item['id']} => {item['text']}\n")
|
||||
else:
|
||||
print(
|
||||
f"Skipping the creation of {translated_lex_file} as it exists already"
|
||||
)
|
||||
quit() # end of the program
|
||||
# create a combined list of all the files
|
||||
all_files = [controller_file, layout_file] + partial_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)
|
||||
all_strings = all_strings + extracted_strings
|
||||
# Take out any duplicates
|
||||
all_strings = deduplicate_array(all_strings)
|
||||
# '<prefix>_english-message' => 'English Message',
|
||||
string_lib = [] # Array of dicts
|
||||
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 leave it for the right
|
||||
# Map all spaces to "_" on left hand side
|
||||
# amd truncate it to max five words
|
||||
original_str = lex_message
|
||||
# Checkif it starts with the prefix (any case|)
|
||||
if lex_message.lower().startswith(hl("prefix").lower()):
|
||||
left_str = lex_message
|
||||
right_str = lex_message[len(hl("prefix")) + 1 :]
|
||||
# And take out any "_", map to " "
|
||||
else:
|
||||
left_str = hl("prefix") + "_" + lex_message
|
||||
right_str = lex_message
|
||||
right_str = right_str.replace("_", " ")
|
||||
# print(f"Right:{right_str}")
|
||||
right_str = format_text(right_str)
|
||||
left_str = left_str.replace(" ", "_")
|
||||
words = left_str.split("_")[:6]
|
||||
left_str = "_".join(words)
|
||||
next_lex_str = {"orig": original_str, "left": left_str, "right": right_str}
|
||||
string_lib.append(next_lex_str)
|
||||
# And write it to lex file
|
||||
# Now process them one by one into the lexical file
|
||||
lex_all = ""
|
||||
for lex_str in string_lib:
|
||||
lex_all += f"'{lex_str['left']}' => '{lex_str['right']}',\n"
|
||||
print(f"Writing {lex_file}")
|
||||
with open(lex_file, "w") as file:
|
||||
file.write(lex_all)
|
||||
# and then play the strings back into the partials and the layout file
|
||||
print("..and feed the lex string names back into other files")
|
||||
for filename in all_files:
|
||||
with open(filename, "r") as file:
|
||||
file_content = file.read()
|
||||
# Scan through
|
||||
for item in string_lib:
|
||||
original_str = item["orig"]
|
||||
left_str = item["left"]
|
||||
right_str = item["right"]
|
||||
# Replace all occurrences of original string with left string in 'contents'
|
||||
file_content = file_content.replace(
|
||||
"l('" + original_str + "')", "l('" + left_str + "')"
|
||||
)
|
||||
# and write it back
|
||||
with open(filename, "w") as file:
|
||||
file.write(file_content)
|
||||
print(f"Write out modified:{filename}")
|
||||
|
||||
# Now generate all the translated lex files from a list of the languages and codes
|
||||
# if specifically requested
|
||||
if not args.noLang:
|
||||
languages_path = "Templates/languages.json"
|
||||
with open(languages_path, "r") as file:
|
||||
languages_str = file.read()
|
||||
lang_dict = json.loads(languages_str)
|
||||
with open(lex_file, "r") as file:
|
||||
lex_str = file.read()
|
||||
eng_lex_dict = convert_lex_to_dict(lex_str)
|
||||
for lang_item in lang_dict:
|
||||
print(f"Translating from english lex file to {lang_item['language']}")
|
||||
code = lang_item["code"]
|
||||
translated_lex_file = (
|
||||
f"{target_directory_path}{hl('PackageName').lower()}_{code}.lex"
|
||||
)
|
||||
# Only do it if the lex file is missing
|
||||
if not os.path.exists(translated_lex_file):
|
||||
translated_dict = []
|
||||
for lex_item in eng_lex_dict:
|
||||
# Get it from ChatGPT
|
||||
translated_text = get_translation(
|
||||
lex_item["text"], lang_item["language"]
|
||||
)
|
||||
translated_dict.append(
|
||||
{"id": lex_item["id"], "text": translated_text}
|
||||
)
|
||||
print(f"Writing out lex file for {lang_item['code']}")
|
||||
with open(translated_lex_file, "w") as file:
|
||||
for item in translated_dict:
|
||||
# escape any nasties
|
||||
translated_text = (
|
||||
item["text"]
|
||||
.replace("\\", r"\\")
|
||||
.replace('"', r"\"")
|
||||
.replace("'", r"\'")
|
||||
)
|
||||
line = (
|
||||
"'" + item["id"] + "' => " + '"' + translated_text + '",\n'
|
||||
)
|
||||
file.write(line)
|
||||
# print(f"{item['id']} => {item['text']}\n")
|
||||
else:
|
||||
print(
|
||||
f"Skipping the creation of {translated_lex_file} as it exists already"
|
||||
)
|
||||
quit() # end of the program
|
||||
|
Loading…
Reference in New Issue
Block a user