Sort out parameters to sm2gen

This commit is contained in:
Brian Read 2024-09-19 10:00:50 +01:00
parent a551ee928c
commit 6e29aebd82
10 changed files with 103 additions and 92 deletions

View File

@ -24,7 +24,7 @@ else
fi fi
# Run the second program # Run the second program
python3 sm2gen.py -f json5/"$2.json5" python3 sm2gen.py -f json5/"$2.json5" --force --noLang
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error: sm2gen.py failed." echo "Error: sm2gen.py failed."
exit 1 exit 1

View File

@ -1,11 +1,10 @@
# #
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 08:37:59 # Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-19 08:43:41
# #
# #
# 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)
# #
##
use esmith::util; use esmith::util;
use esmith::HostsDB; use esmith::HostsDB;
use esmith::AccountsDB; use esmith::AccountsDB;

View File

@ -1,11 +1,11 @@
# #
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 15:44:18 # Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 09:02:36
# #
# #
# 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)
# # lcPackageName=json5_dict["PackageName"].lower(),
use esmith::util;
use esmith::HostsDB; use esmith::HostsDB;
use esmith::AccountsDB; use esmith::AccountsDB;
use esmith::NetworksDB; use esmith::NetworksDB;

View File

@ -1,6 +1,6 @@
package SrvMngr::Controller::CreateStarterWebsite; package SrvMngr::Controller::CreateStarterWebsite;
# #
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 08:38:32 # Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-19 08:43:41
# #
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# heading : Miscellaneous # heading : Miscellaneous

View File

@ -1,5 +1,5 @@
%# %#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 09:09:54 %# Generated by SM2Gen version:0.8 Chameleon version:3.8.1 On Python:3.12.3 at 2024-09-19 09:57:16
%# %#
<div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS"> <div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS">
<script> <script>
@ -13,8 +13,8 @@
% my $btn = l('csw_APPLY'); % my $btn = l('csw_APPLY');
%= form_for "CreateStarterWebsited" => (method => 'POST') => begin %= form_for "CreateStarterWebsited" => (method => 'POST') => begin
% param 'trt' => $csw_data->{trt} unless param 'trt'; % param 'trt' => ${prefix}_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $csw_data->{trt} %= hidden_field 'trt' => ${prefix}_data->{trt}
%# Inputs etc in here. %# Inputs etc in here.
<h1><%=l('csw_Create_a_starter_website')%></h1> <h1><%=l('csw_Create_a_starter_website')%></h1>
@ -40,7 +40,7 @@
<p><span class=label> <p><span class=label>
%=l('csw_') %=l('csw_')
</span><span class=data> </span><span class=data>
% param 'companyName' => $csw_data->{companyName} unless param 'companyName'; % param 'companyName' => ${prefix}_data->{companyName} unless param 'companyName';
%= text_field 'companyName', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'companyName' %= text_field 'companyName', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'companyName'
<br></span></p> <br></span></p>
@ -51,7 +51,7 @@
<p><span class=label> <p><span class=label>
%=l('csw_') %=l('csw_')
</span><span class=data> </span><span class=data>
% param 'header1' => $csw_data->{header1} unless param 'header1'; % param 'header1' => ${prefix}_data->{header1} unless param 'header1';
%= text_field 'header1', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'header1' %= text_field 'header1', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'header1'
<br></span></p> <br></span></p>
@ -62,7 +62,7 @@
<span class=label> <span class=label>
%=l('csw_') %=l('csw_')
</span><span class=data> </span><span class=data>
% param 'text1' => $csw_data->{text1} unless param 'text1'; % param 'text1' => ${prefix}_data->{text1} unless param 'text1';
%= text_area 'text1', cols=>40, rows=>10 %= text_area 'text1', cols=>40, rows=>10
</span><br> </span><br>
@ -73,7 +73,7 @@
<p><span class=label> <p><span class=label>
%=l('csw_') %=l('csw_')
</span><span class=data> </span><span class=data>
% param 'header2' => $csw_data->{header2} unless param 'header2'; % param 'header2' => ${prefix}_data->{header2} unless param 'header2';
%= text_field 'header2', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'header2' %= text_field 'header2', size => '50', class => 'input' , pattern=>'.*' , placeholder=>'header2'
<br></span></p> <br></span></p>
@ -84,7 +84,7 @@
<span class=label> <span class=label>
%=l('csw_') %=l('csw_')
</span><span class=data> </span><span class=data>
% param 'text2' => $csw_data->{text2} unless param 'text2'; % param 'text2' => ${prefix}_data->{text2} unless param 'text2';
%= text_area 'text2', cols=>40, rows=>10 %= text_area 'text2', cols=>40, rows=>10
</span><br> </span><br>

View File

@ -1,3 +1,3 @@
/* /*
Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 15:44:18 Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:3.8.1 On Python:3.12.3 at 2024-09-19 09:57:16
*/ */

View File

@ -1,7 +1,9 @@
%# %#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 08:38:32 %# Generated by SM2Gen version:0.8 Chameleon version:3.8.1 On Python:3.12.3 at 2024-09-19 09:57:16
%# %#
% layout 'default', title => "Sme server 2 - Create Starter Website", share_dir => './'; % layout 'default', title => "Sme server 2 - Create Starter Website", share_dir => './';
%# css specific to this panel:
%= stylesheet '/css/createstarterwebsite.css'
% content_for 'module' => begin % content_for 'module' => begin
<div id="module" class="module CreateStarterWebsite-panel"> <div id="module" class="module CreateStarterWebsite-panel">
@ -17,22 +19,22 @@
%= $c->render_to_string(inline => stash('modul') ); %= $c->render_to_string(inline => stash('modul') );
% } % }
%if ($csw_data->{first}) { %if (${prefix}_data->{first}) {
<br><p> <br><p>
%=$c->render_to_string(inline =>$c->l($csw_data->{first})) %=$c->render_to_string(inline =>$c->l(${prefix}_data->{first}))
</p> </p>
%} elsif ($csw_data->{success}) { %} elsif (${prefix}_data->{success}) {
<div class='sme-border'> <div class='sme-border'>
<h2> Operation Status Report</h2><p> <h2> Operation Status Report</h2><p>
%= $c->l($csw_data->{success}); %= $c->l(${prefix}_data->{success});
</p> </p>
</div> </div>
%} elsif ($csw_data->{error}) { %} elsif (${prefix}_data->{error}) {
<div class='sme-error'> <div class='sme-error'>
<h2> Operation Status Report - error</h2><p> <h2> Operation Status Report - error</h2><p>
%= $c->l($csw_data->{error}); %= $c->l(${prefix}_data->{error});
</p> </p>
</div> </div>
%} %}
@ -40,7 +42,7 @@
%#Routing to partials according to trt parameter. %#Routing to partials according to trt parameter.
%#This ought to be cascading if/then/elsif, but is easier to just stack the if/then's rather like a case statement' %#This ought to be cascading if/then/elsif, but is easier to just stack the if/then's rather like a case statement'
% if ($csw_data->{trt} eq "PARAMS") { % if (${prefix}_data->{trt} eq "PARAMS") {
%= include 'partials/_csw_PARAMS' %= include 'partials/_csw_PARAMS'
%} %}

View File

@ -1,21 +1,21 @@
# #
# Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-18 09:28:01 # Generated by SM2Gen version: SM2Gen version:0.8 Chameleon version:3.8.1 On Python:3.12.3 at 2024-09-19 09:57:16
# #
'csw_Create_a_starter_website' => 'Create a starter website',
'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_Second_header,_typically_used_for' => 'Second header, Typically used for short phrases such as For more information or To order our products:',
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
'csw_' => '',
'csw_Text_following_second_header,_typically' => 'Text following second header, Typically used for contact or ordering information:',
'csw_To_create_a_simple_web' => 'To create a simple web page for your company, Fill in the fields below and click onCreate. ',
'csw_Do_you_wish_to_proceed?' => 'Do you wish to proceed?',
'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_When_you_create_this_web' => 'When you create this web page, The file index. Htm will be overwritten in your web site directory. ', '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_Create' => 'Create', '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_APPLY' => 'Apply',
'csw_First_header,_typically_used_for' => 'First header, Typically used for short phrases such as Leader in the field of textile manufacturing',
'csw_Create_a_starter_website' => 'Create a starter website',
'csw_' => '',
'csw_You_can_leave_any_field' => 'You can leave any field blank if you do not need it. ',
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
'csw_Second_header,_typically_used_for' => 'Second header, Typically used for short phrases such as For more information or To order our products:',
'csw_Create_Starter_Website' => 'Create Starter Website', 'csw_Create_Starter_Website' => 'Create Starter Website',
'csw_Hello_PARAMS' => 'Hello PARAMS', 'csw_Hello_PARAMS' => 'Hello PARAMS',
'csw_APPLY' => 'Apply', 'csw_Create' => 'Create',
'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_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_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_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful', 'csw_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'csw_To_create_a_simple_web' => 'To create a simple web page for your company, Fill in the fields below and click onCreate. ',

View File

@ -2,8 +2,8 @@
%# Generated by ${version} %# Generated by ${version}
%# %#
% layout 'default', title => "Sme server 2 - ${MenuDescription}", share_dir => './'; % layout 'default', title => "Sme server 2 - ${MenuDescription}", share_dir => './';
% css specific to this panel: %# css specific to this panel:
%= stylesheet '/css/{lcPackageName}.css' %= stylesheet '/css/${lcPackageName}.css'
% content_for 'module' => begin % content_for 'module' => begin
<div id="module" class="module ${PackageName}-panel"> <div id="module" class="module ${PackageName}-panel">

108
sm2gen.py
View File

@ -321,51 +321,54 @@ def get_translation(message="Hello", language="french"):
import os import os
from datetime import datetime, timedelta from datetime import datetime, timedelta
def check_file_version(filename, ThresholdSecs=3): def check_file_version(filename,force_Files=False):
# #
# Check modified versus creation date of the file and return +".new" if modified since creation + ThresholdSecs # Check modified versus creation date of the file and return +".new" if modified since creation + ThresholdSecs
# #
try: if force_Files:
with open(filename, 'r') as file: return filename
# Read the first three lines ThresholdSecs = 3 #allow secs since creation date before treat as changed.
header_lines = [file.readline().strip() for _ in range(5)] try:
with open(filename, 'r') as file:
# Read the first three lines
header_lines = [file.readline().strip() for _ in range(5)]
# Extract the timestamp # Extract the timestamp
timestamp_str = None timestamp_str = None
for line in header_lines: for line in header_lines:
if ' at ' in line: if ' at ' in line:
# Split at 'at', expect the timestamp to be in the third part # Split at 'at', expect the timestamp to be in the third part
print(line) #print(line)
timestamp_str = line.split('at')[2].strip() timestamp_str = line.split('at')[2].strip()
break break
if timestamp_str is None: if timestamp_str is None:
print("Warning: No timestamp found. Returning original filename.") print("Warning: No timestamp found. Returning original filename.")
return filename # Return the original filename if no timestamp is found return filename # Return the original filename if no timestamp is found
# Convert the string timestamp to a datetime object # Convert the string timestamp to a datetime object
file_timestamp = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S') file_timestamp = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S')
# Add the threshold seconds to the creation date # Add the threshold seconds to the creation date
file_timestamp += timedelta(seconds=ThresholdSecs) file_timestamp += timedelta(seconds=ThresholdSecs)
# Get the last modified time of the file, ignoring milliseconds # Get the last modified time of the file, ignoring milliseconds
file_modified_time = datetime.fromtimestamp(os.path.getmtime(filename)).replace(microsecond=0) file_modified_time = datetime.fromtimestamp(os.path.getmtime(filename)).replace(microsecond=0)
print(file_modified_time,file_timestamp) #print(file_modified_time,file_timestamp)
# Compare the timestamps # Compare the timestamps
if file_modified_time > file_timestamp: if file_modified_time > file_timestamp:
return f"{filename}.new" return f"{filename}.new"
else: else:
return filename return filename
except FileNotFoundError: except FileNotFoundError:
print(f"Error: The file '{filename}' does not exist.") #print(f"Error: The file '{filename}' does not exist.")
return filename return filename
except Exception as e: except Exception as e:
print(f"An error occurred: {traceback.format_exc()}") print(f"An error occurred: {traceback.format_exc()}")
return filename return filename
def convert_lex_to_dict(pairs_string): def convert_lex_to_dict(pairs_string):
@ -416,25 +419,30 @@ if __name__ == "__main__":
default=json_filename, default=json_filename,
) )
parser.add_argument( parser.add_argument(
"-nco", "--force",
action = 'store_true',
help="Force an overwrite of all files",
)
parser.add_argument(
"--noController", "--noController",
help="Stop it creating a controller file", action = 'store_false',
default="yes", help="Stop it creating a controller file (not currently implemented)",
) )
parser.add_argument( parser.add_argument(
"-nh", "--noHtml", help="Stop it creating html files(s)", default="yes" "--noHtml",
action = 'store_false',
help="Stop it creating html files(s) (not currently implemented)", default=False
) )
parser.add_argument( parser.add_argument(
"-nl",
"--noLang", "--noLang",
action = 'store_false',
help="Stop it creating language localise files(s)", help="Stop it creating language localise files(s)",
default="yes",
) )
parser.add_argument( parser.add_argument(
"-ncu",
"--noCust", "--noCust",
help="Stop it creating Custom controller file", action = 'store_false',
default="yes", help="Stop it creating Custom controller file (not currently implemented)",
) )
args = parser.parse_args() args = parser.parse_args()
json_filename = args.filename json_filename = args.filename
@ -473,23 +481,25 @@ if __name__ == "__main__":
# File names # File names
# #
# Define the path for the generated files # Define the path for the generated files
# force them to be overwritten
force_Files = args.force
directory_path = Path("Targets/" + hl("PackageName")) directory_path = Path("Targets/" + hl("PackageName"))
# Create the directory if it doesn't exist # Create the directory if it doesn't exist
directory_path.mkdir(parents=True, exist_ok=True) directory_path.mkdir(parents=True, exist_ok=True)
target_directory_path = "Targets/" + hl("PackageName") + "/" target_directory_path = "Targets/" + hl("PackageName") + "/"
controller_file = check_file_version(target_directory_path + hl("PackageName") + ".pm") controller_file = check_file_version(target_directory_path + hl("PackageName") + ".pm",force_Files)
custom_controller_file = check_file_version(target_directory_path + hl("PackageName") + "-Custom.pm",3) custom_controller_file = check_file_version(target_directory_path + hl("PackageName") + "-Custom.pm",force_Files)
#print(custom_controller_file) #print(custom_controller_file)
layout_file = check_file_version(target_directory_path + hl("PackageName").lower() + ".html.ep") layout_file = check_file_version(target_directory_path + hl("PackageName").lower() + ".html.ep",force_Files)
css_file = check_file_version(target_directory_path + hl("PackageName").lower() + ".css") css_file = check_file_version(target_directory_path + hl("PackageName").lower() + ".css",force_Files)
partial_files = list() partial_files = list()
for panel in routes: for panel in routes:
partial_files.append(check_file_version( partial_files.append(check_file_version(
target_directory_path + '_' + hl("prefix") + "_" + panel + ".html.ep") target_directory_path + '_' + hl("prefix") + "_" + panel + ".html.ep",force_Files)
) )
print(f"Partial files to be created:{partial_files}") print(f"Partial files to be created:{partial_files}")
lex_file = check_file_version(target_directory_path + hl("PackageName").lower() + "_en.lex") lex_file = check_file_version(target_directory_path + hl("PackageName").lower() + "_en.lex",force_Files)
print(lex_file) print(lex_file)
tablecontrols = ( tablecontrols = (
get_table_control_data() get_table_control_data()