diff options
-rwxr-xr-x[-rw-r--r--] | tools/infrastructure/api_compare.py | 62 | ||||
-rw-r--r-- | tools/infrastructure/format_src.py | 37 | ||||
-rw-r--r-- | tools/infrastructure/install_hooks.py | 8 |
3 files changed, 33 insertions, 74 deletions
diff --git a/tools/infrastructure/api_compare.py b/tools/infrastructure/api_compare.py index 0129119673..ca1279ab61 100644..100755 --- a/tools/infrastructure/api_compare.py +++ b/tools/infrastructure/api_compare.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- import json import sys @@ -7,11 +8,6 @@ import argparse import xml.etree.ElementTree as ElementTree from collections import namedtuple -reload(sys) -# Enable Utf-8 support. Needed if script will be run under Windows -sys.setdefaultencoding('utf-8') - - class colors: """Class defining colorful output. Works under UNIX ONLY as Windows does not support ANSI escape sequences @@ -206,53 +202,53 @@ def print_parameters(common_params, hmi_params, mob_params): """Function which prints parameters in mobile, hmi api and common parameters """ - print "Parameters to check: ", common_params, "\n" + print("Parameters to check: ", common_params, "\n") for param in common_params: mob_items = sorted(mob_params[param].items()) hmi_items = sorted(hmi_params[param].items()) - print colors.UNDERLINE + colors.BOLD + param + colors.ENDC, ":" - print "In Mobile API :\t", dict(mob_items) - print "In HMI API :\t", dict(hmi_items) + print(colors.UNDERLINE + colors.BOLD + param + colors.ENDC, ":") + print("In Mobile API :\t", dict(mob_items)) + print("In HMI API :\t", dict(hmi_items)) def print_full_info(hmi_absent_params, hmi_params, mob_absent_params, mob_params, rpc_name): """Function prints full detailed info about every rpc""" - print "\n" + "---" * 60 + "\n" + print("\n" + "---" * 60 + "\n") rpc_color = colors.BOLD + colors.HEADER - print rpc_color + rpc_name + colors.ENDC - print colors.BOLD + "\nMobile API: " + colors.ENDC - print "Parameters quantity: ", len(mob_params) - print "Parameters list: ", sorted(mob_params.keys()) - print colors.BOLD + "HMI API: " + colors.ENDC - print "Parameters quantity: ", len(hmi_params) - print "Parameters list: ", sorted(hmi_params.keys()) - print "\n" + print(rpc_color + rpc_name + colors.ENDC) + print(colors.BOLD + "\nMobile API: " + colors.ENDC) + print("Parameters quantity: ", len(mob_params)) + print("Parameters list: ", sorted(mob_params.keys())) + print(colors.BOLD + "HMI API: " + colors.ENDC) + print("Parameters quantity: ", len(hmi_params)) + print("Parameters list: ", sorted(hmi_params.keys())) + print("\n") print("{}Parameters absent in Mobile APIs: {}{}". format(colors.WARN, mob_absent_params, colors.ENDC)) print("{}Parameters absent in HMI APIs: {}{}". format(colors.WARN, hmi_absent_params, colors.ENDC)) - print "\n" + print("\n") def console_print(summary_result): """Function which prints summary result to console""" for rpc_name in sorted(summary_result.keys()): - print "\n" + "---" * 60 - print colors.HEADER + rpc_name + colors.ENDC + print("\n" + "---" * 60) + print(colors.HEADER + rpc_name + colors.ENDC) for problematic_item in summary_result[rpc_name]: item = summary_result[rpc_name][problematic_item] if len(item) > 0: - print colors.UNDERLINE + problematic_item + colors.ENDC + print(colors.UNDERLINE + problematic_item + colors.ENDC) if type(item) is not dict: print("{}{}{}".format(colors.WARN, item, colors.ENDC)) elif type(item) is dict: for param in item.keys(): item_print = colors.UNDERLINE + param + colors.ENDC - print "{} {}".format("Parameter name: ", item_print) + print("{} {}".format("Parameter name: ", item_print)) res_val = item[param] for key in res_val: - print key, ":", colors.FAIL, res_val[key], colors.ENDC + print(key, ":", colors.FAIL, res_val[key], colors.ENDC) def print_summary_info(summary_result, args): @@ -260,21 +256,21 @@ def print_summary_info(summary_result, args): Output type depends on command line args """ summary_color = colors.UNDERLINE + colors.BOLD + colors.BLUE - print "\n" - print summary_color, "SUMMARY COMPARISON RESULT:\n", colors.ENDC + print("\n") + print(summary_color, "SUMMARY COMPARISON RESULT:\n", colors.ENDC) if len(summary_result) == 0: - print colors.BOLD + " === NO PROBLEMS FOUND ===" + colors.ENDC + print(colors.BOLD + " === NO PROBLEMS FOUND ===" + colors.ENDC) return if args.output == "console": console_print(summary_result) if args.output == "json": json_summary_result = dict_to_json(summary_result) - print json_summary_result + print(json_summary_result) if args.output == "xml": json_summary_result = dict_to_json(summary_result) temp = json.loads(json_summary_result) xml_summary_result = json_to_xml(temp) - print xml_summary_result + print(xml_summary_result) def handle_absent_params(area, absent_params, rpc_name, summary_result): @@ -365,7 +361,7 @@ def all_compare_rule(mob_param_attributes, hmi_param_attributes): """Function used for all common arrtibutes comparison""" mobile_result = {} hmi_result = {} - attr_names = mob_param_attributes.keys() + hmi_param_attributes.keys() + attr_names = [*mob_param_attributes] + [*hmi_param_attributes] attr_names = set(attr_names) for attr_name in attr_names: mobile_attribute_value = None @@ -393,8 +389,8 @@ global_compare_rules = [ mob_param_attributes["type"] == "String", string_compare_rule), # Comparison rule when attribute "array" = "true" (lambda mob_param_attributes, hmi_param_attributes: - 'array' in mob_param_attributes.keys() + - hmi_param_attributes.keys(), array_compare_rule), + 'array' in [*mob_param_attributes] + + [*hmi_param_attributes], array_compare_rule), # Common comparison function for all attributes (lambda mob_param_attributes, hmi_param_attributes: True, all_compare_rule) diff --git a/tools/infrastructure/format_src.py b/tools/infrastructure/format_src.py deleted file mode 100644 index b7927b2708..0000000000 --- a/tools/infrastructure/format_src.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -""" -Format all sources with clang-format. All *.cc and *h in the src dir -are affected. Excluded from formatting sources in the "3rd_party" and -in the "3rd_party-static" dirs. For the formatting used ".clang-format" -in the project root. -""" - -import os -from utils import setup_working_dir, walk_dir, run_cmd -import re - - -INCLUDE_PATTERNS = ['^.*\.cc$', '^.*\.h$', '^.*\.cpp$', '^.*\.hpp$'] -EXCLUDE_PATTERNS = ['^.*3rd_party.*$'] -FORMAT_CMD = 'clang-format -i -style=file {}' - - -def main(): - ''' Main logic ''' - setup_working_dir() - print 'Current working dir is {}'.format(os.getcwd()) - - def action(file_path): - if re.match('|'.join(INCLUDE_PATTERNS), file_path, re.M | re.I): - if not re.match('|'.join(EXCLUDE_PATTERNS), - file_path, - re.M | re.I): - print 'Formatting file {}'.format(file_path) - run_cmd(FORMAT_CMD.format(file_path)) - walk_dir('src', action) - - -if __name__ == '__main__': - main() diff --git a/tools/infrastructure/install_hooks.py b/tools/infrastructure/install_hooks.py index 6f93e02c41..1e1f63de43 100644 --- a/tools/infrastructure/install_hooks.py +++ b/tools/infrastructure/install_hooks.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @@ -12,14 +12,14 @@ from utils import setup_working_dir def uninstall_hooks(hooks_dir): - print 'Deleting existing pre-commit hooks from {}'.format(hooks_dir) + print('Deleting existing pre-commit hooks from {}'.format(hooks_dir)) files = glob.glob(os.path.join(hooks_dir, 'pre-commit*')) for item in files: os.remove(item) def install_hooks(src_dir, dst_dir): - print 'Installing pre-commit hooks' + print('Installing pre-commit hooks') src_files = glob.glob(os.path.join(src_dir, 'pre-commit*')) for item in src_files: shutil.copy(item, dst_dir) @@ -28,7 +28,7 @@ def install_hooks(src_dir, dst_dir): def main(): ''' Main logic ''' setup_working_dir() - print 'Current working dir is {}'.format(os.getcwd()) + print('Current working dir is {}'.format(os.getcwd())) hooks_src_dir = os.path.join( os.getcwd(), 'tools', 'infrastructure', 'git-hooks') hooks_dst_dir = os.path.join(os.getcwd(), '.git', 'hooks') |