2023-01-19 10:33:49 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
|
2021-05-16 13:09:32 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import argparse
|
|
|
|
import sys
|
2023-01-22 16:29:20 +01:00
|
|
|
import defines
|
2021-05-16 13:09:32 +02:00
|
|
|
from format_util import find_files
|
|
|
|
from format_util import check_git_exit
|
|
|
|
from format_util import execute_threaded
|
2022-11-02 12:15:34 +01:00
|
|
|
from sys import stdout
|
|
|
|
|
|
|
|
stdout.reconfigure(encoding='utf-8')
|
2021-05-16 13:09:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def format_file_function(file):
|
|
|
|
executable = "qmlformat"
|
|
|
|
if os.name == 'nt':
|
|
|
|
executable = "qmlformat.exe"
|
2023-01-22 16:29:20 +01:00
|
|
|
qt_bin_path = defines.QT_BIN_PATH
|
|
|
|
executable = qt_bin_path.joinpath(executable)
|
2021-05-16 13:09:32 +02:00
|
|
|
|
|
|
|
process = subprocess.run(
|
2021-05-16 19:35:05 +02:00
|
|
|
"%s -i %s" % (executable, file), capture_output=True, shell=True)
|
2021-05-16 13:09:32 +02:00
|
|
|
print("Format: %s \t return: %s" % (file, process.returncode))
|
|
|
|
|
|
|
|
|
|
|
|
def main(git_staged_only=False):
|
2021-05-16 19:35:05 +02:00
|
|
|
file_list = find_files(('.qml'), os.path.abspath(os.path.join(os.getcwd(), "../")), git_staged_only)
|
2021-05-16 13:09:32 +02:00
|
|
|
execute_threaded(file_list, format_file_function)
|
|
|
|
if not git_staged_only:
|
|
|
|
check_git_exit("QML Format")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-s', action="store_true", dest="stage_only",
|
|
|
|
default=False)
|
|
|
|
args = parser.parse_args()
|
|
|
|
main(args.stage_only)
|