rivet/main.py

71 lines
2.5 KiB
Python
Raw Normal View History

2024-03-24 13:14:39 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2024-04-12 21:33:09 +00:00
from __future__ import annotations
2024-01-28 12:52:45 +00:00
import argparse
import os
2024-01-28 12:52:45 +00:00
2023-11-24 13:34:44 +00:00
from schema import InstructionSetSchema
2024-01-28 12:52:45 +00:00
description = """Examples:
- Default theme (black on white):
python main.py schema.xml -o out.jpg
- Dark theme (white on black):
python main.py schema.xml -o out.jpg -c dark.json
- Blueprint theme (white on blue):
python main.py schema.xml -o out.jpg -c blueprint.json
- Transparent background:
python main.py schema.xml -o out.png -c transparent.json
2024-03-24 13:07:53 +00:00
- Directory mode:
python main.py -d -o images/ schemas/
2024-01-28 12:52:45 +00:00
"""
2024-03-24 10:33:34 +00:00
2024-04-12 21:33:09 +00:00
def processFile(inPath: str, outPath: str, confPath: str, display: bool) -> None:
2024-03-24 13:07:53 +00:00
schema = InstructionSetSchema(inPath, confPath, display)
schema.save(outPath)
2023-11-24 13:34:44 +00:00
if __name__ == "__main__":
2024-01-28 12:52:45 +00:00
parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("schema", help="Path to the schema description. Accepted formats are: YAML, JSON and XML")
parser.add_argument("-o", "--output", help="Output path. By default, the output file will have the same name as the schema description with the extension .png")
2024-01-28 12:52:45 +00:00
parser.add_argument("-c", "--config", help="Path to the config file", default="config.json")
parser.add_argument("-D", "--display", help="Enable pygame display of the result", action="store_true")
2024-03-24 13:07:53 +00:00
parser.add_argument("-d", "--directory", help="Enable directory mode. If set, the input and output paths are directories and all files inside the input directory are processed", action="store_true")
2024-01-28 12:52:45 +00:00
args = parser.parse_args()
2024-03-24 13:07:53 +00:00
if args.directory:
if not os.path.isdir(args.schema):
print(f"{args.schema} is not a directory")
exit(-1)
output = args.output
if output is None:
output = args.schema
if not os.path.isdir(output):
print(f"{output} is not a directory")
exit(-1)
paths = os.listdir(args.schema)
for path in paths:
inPath = os.path.join(args.schema, path)
outPath = os.path.join(output, path)
outPath = os.path.splitext(outPath)[0] + ".png"
processFile(inPath, outPath, args.config, args.display)
2024-03-24 13:07:53 +00:00
else:
output = args.output
if output is None:
output = os.path.splitext(args.schema)[0] + ".png"
2024-04-12 21:33:09 +00:00
processFile(args.schema, output, args.config, args.display)