aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-31 15:14:25 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-02 04:59:52 +0000
commit6377d14cfe491d497d6ad555fdd6aade1e08211c (patch)
treed2234277f4f507b251afc404a9476a6b676d2c29
parent18ab54ffb1a535c98b0293c04ab636927f1e6a60 (diff)
qtpy2cpp: Handle multiple file arguments
Task-number: PYSIDE-1945 Change-Id: If994c572ed5cdbac6536968160153c721b5f1473 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit dc06e881f72f2added3b7211a78e2ec15065a623) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tools/qtpy2cpp.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/tools/qtpy2cpp.py b/tools/qtpy2cpp.py
index a41226a04..92c03f301 100644
--- a/tools/qtpy2cpp.py
+++ b/tools/qtpy2cpp.py
@@ -56,7 +56,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
@@ -69,31 +69,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} ...")