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