Update list.py
*Updated list.py to sort the list before saving
This commit is contained in:
parent
7578202e18
commit
ec29f33835
@ -2,11 +2,12 @@ import os
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import locale
|
||||||
|
|
||||||
#
|
#
|
||||||
# [ TD2 SCENERIES JSON LIST GENERATOR ]
|
# [ TD2 SCENERIES JSON LIST GENERATOR ]
|
||||||
# by masuo
|
# by masuo
|
||||||
# v1.0
|
# v1.1
|
||||||
#
|
#
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
@ -30,51 +31,47 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def list_lite_sc_files(directory):
|
||||||
|
locale.setlocale(locale.LC_COLLATE, '')
|
||||||
|
try:
|
||||||
|
entries = [f for f in os.listdir(directory) if f.endswith('.lite.sc')]
|
||||||
|
except OSError as e:
|
||||||
|
print(f"Error reading directory: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
return sorted(entries, key=locale.strxfrm)
|
||||||
|
|
||||||
|
def write_output(path, data):
|
||||||
|
try:
|
||||||
|
with open(path, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||||
|
print(f"Successfully wrote {len(data['list'])} entries to '{path}'")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error writing to output file: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
# Prompt for version if not provided
|
|
||||||
version = args.save_version or input("Enter version: ")
|
version = args.save_version or input("Enter version: ")
|
||||||
version_date = args.save_version_date or input("Enter version date (YYYY-MM-DD): ")
|
version_date = args.save_version_date or input("Enter version date (YYYY-MM-DD): ")
|
||||||
|
|
||||||
directory = args.directory
|
directory = args.directory
|
||||||
if not os.path.isdir(directory):
|
if not os.path.isdir(directory):
|
||||||
print(f"Error: '{directory}' is not a valid directory.")
|
print(f"Error: '{directory}' is not a valid directory.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
collected = []
|
files = list_lite_sc_files(directory)
|
||||||
|
for fname in list_lite_sc_files(directory):
|
||||||
for fname in sorted(os.listdir(directory)):
|
|
||||||
full_path = os.path.join(directory, fname)
|
full_path = os.path.join(directory, fname)
|
||||||
if not os.path.isfile(full_path):
|
if not os.path.isfile(full_path):
|
||||||
print(f"Warning: Skipping '{fname}' (not a file)")
|
print(f"Warning: Skipping '{fname}' (not a file)")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not fname.endswith('.sc'):
|
|
||||||
print(f"Warning: Skipping '{fname}' (does not end with .sc)")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not fname.endswith('.lite.sc'):
|
|
||||||
print(f"Warning: '{fname}' ends with .sc but not .lite.sc, skipping")
|
|
||||||
continue
|
|
||||||
|
|
||||||
collected.append(fname)
|
|
||||||
|
|
||||||
output = {
|
output = {
|
||||||
"info": {
|
"info": {
|
||||||
"version": version,
|
"version": version,
|
||||||
"versionDate": version_date
|
"versionDate": version_date
|
||||||
},
|
},
|
||||||
"list": collected
|
"list": files
|
||||||
}
|
}
|
||||||
|
write_output(args.output_file, output)
|
||||||
try:
|
|
||||||
with open(args.output_file, 'w', encoding='utf-8') as f:
|
|
||||||
json.dump(output, f, ensure_ascii=False, indent=4)
|
|
||||||
print(f"Successfully wrote {len(collected)} entries to '{args.output_file}'")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error writing to output file: {e}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user