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