aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-31 15:14:25 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-06-01 16:17:41 +0200
commitdc06e881f72f2added3b7211a78e2ec15065a623 (patch)
treece792f0a2c7d253e5c506232608c6605e488d4be /tools
parent808cf3a40c03e95a4ec84477656e739ab48dfc85 (diff)
qtpy2cpp: Handle multiple file arguments
Pick-to: 6.3 Task-number: PYSIDE-1945 Change-Id: If994c572ed5cdbac6536968160153c721b5f1473 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qtpy2cpp.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/tools/qtpy2cpp.py b/tools/qtpy2cpp.py
index 50ad88d12..04a34a97d 100644
--- a/tools/qtpy2cpp.py
+++ b/tools/qtpy2cpp.py
@@ -20,7 +20,7 @@ def create_arg_parser(desc):
help='Write to stdout')
parser.add_argument('--force', '-f', action='store_true',
help='Force overwrite of existing files')
- parser.add_argument('file', type=str, help='Python source file')
+ parser.add_argument('files', type=str, nargs="+", help='Python source file(s)')
return parser
@@ -33,31 +33,31 @@ if __name__ == '__main__':
args = arg_parser.parse_args()
ConvertVisitor.debug = args.debug
- input_file = args.file
- if not os.path.isfile(input_file):
- logger.error(f'{input_file} does not exist or is not a file.')
- sys.exit(-1)
- file_root, ext = os.path.splitext(input_file)
- if ext != '.py':
- logger.error(f'{input_file} does not appear to be a Python file.')
- sys.exit(-1)
-
- ast_tree = ConvertVisitor.create_ast(input_file)
- if args.stdout:
- sys.stdout.write(f'// Converted from {input_file}\n')
- ConvertVisitor(input_file, sys.stdout).visit(ast_tree)
- sys.exit(0)
-
- target_file = file_root + '.cpp'
- if os.path.exists(target_file):
- if not os.path.isfile(target_file):
- logger.error(f'{target_file} exists and is not a file.')
+ for input_file in args.files:
+ if not os.path.isfile(input_file):
+ logger.error(f'{input_file} does not exist or is not a file.')
sys.exit(-1)
- if not args.force:
- logger.error(f'{target_file} exists. Use -f to overwrite.')
+ file_root, ext = os.path.splitext(input_file)
+ if ext != '.py':
+ logger.error(f'{input_file} does not appear to be a Python file.')
sys.exit(-1)
- with open(target_file, "w") as file:
- file.write(f'// Converted from {input_file}\n')
- ConvertVisitor(input_file, file).visit(ast_tree)
- logger.info(f"Wrote {target_file} ...")
+ ast_tree = ConvertVisitor.create_ast(input_file)
+ if args.stdout:
+ sys.stdout.write(f'// Converted from {input_file}\n')
+ ConvertVisitor(input_file, sys.stdout).visit(ast_tree)
+ sys.exit(0)
+
+ target_file = file_root + '.cpp'
+ if os.path.exists(target_file):
+ if not os.path.isfile(target_file):
+ logger.error(f'{target_file} exists and is not a file.')
+ sys.exit(-1)
+ if not args.force:
+ logger.error(f'{target_file} exists. Use -f to overwrite.')
+ sys.exit(-1)
+
+ with open(target_file, "w") as file:
+ file.write(f'// Converted from {input_file}\n')
+ ConvertVisitor(input_file, file).visit(ast_tree)
+ logger.info(f"Wrote {target_file} ...")