From 7901995bc7da3492809ea8d443e50f2830f6864c Mon Sep 17 00:00:00 2001 From: gregorni Date: Thu, 15 Jun 2023 18:51:41 +0200 Subject: [PATCH] Added ability to add directories as input --- blueprintcompiler/main.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/blueprintcompiler/main.py b/blueprintcompiler/main.py index 78121d9..9087b67 100644 --- a/blueprintcompiler/main.py +++ b/blueprintcompiler/main.py @@ -75,8 +75,6 @@ class BlueprintApp: "inputs", nargs="+", metavar="filenames", - default=sys.stdin, - type=argparse.FileType("r+"), ) port = self.add_subcommand("port", "Interactive porting tool", self.cmd_port) @@ -164,8 +162,25 @@ class BlueprintApp: sys.exit(1) def cmd_format(self, opts): + input_files = [] + + for path in opts.inputs: + if os.path.isfile(path): + input_files.append(open(path, "r+")) + elif os.path.isdir(path): + for root, subfolders, files in os.walk(path): + for file in files: + if file.endswith(".blp"): + input_files.append(open(os.path.join(root, file), "r+")) + else: + print( + f"{Colors.RED}{Colors.BOLD}Could not find file: {path}{Colors.CLEAR}" + ) + sys.exit(1) + formatted_files = 0 - for file in opts.inputs: + + for file in input_files: data = file.read() try: xml, warnings = self._compile(data)