def exe(self, command, exit_on_error=True): if isinstance(command, (str, unicode)): pass elif isinstance(command, list): command = ' '.join(command) else: raise Exception( "Command should be a str, unicode or a list, found %s (%s)" % ( type(command), command)) command = command.replace('${TRAVIS_BUILD_DIR}', self.mqt_path) if self.env: command = "%s %s" % (self.env, command) print(travis_helpers.green("Exec: %s" % command)) exit_code = subprocess.call(command, shell=True) if exit_code > 0: msg = 'ERROR while execulting: %s' % command print(travis_helpers.red(msg)) if exit_on_error: sys.exit(msg) return exit_code
def pylint_run(is_pr, version, dir): # Look for an environment variable # whose value is the name of a proper configuration file for pylint # (this file will then be expected to be found in the 'cfg/' folder). # If such an environment variable is not found, # it defaults to the standard configuration file. pylint_config_file = os.environ.get('PYLINT_CONFIG_FILE', 'travis_run_pylint.cfg') pylint_rcfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'cfg', pylint_config_file) pylint_rcfile_pr = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', "travis_run_pylint_pr.cfg") odoo_version = version_validate(version, dir) modules_cmd = get_modules_cmd(dir) beta_msgs = get_beta_msgs() branch_base = get_branch_base() extra_params_cmd = get_extra_params(odoo_version) extra_info = "extra_params_cmd %s " % extra_params_cmd print(extra_info) conf = ["--config-file=%s" % (pylint_rcfile)] cmd = conf + modules_cmd + extra_params_cmd real_errors = main(cmd, standalone_mode=False) res = dict((key, value) for key, value in (real_errors.get('by_msg') or {}).items() if key not in beta_msgs) count_errors = get_count_fails(real_errors, list(beta_msgs)) count_info = "count_errors %s" % count_errors print(count_info) if is_pr: print( travis_helpers.green( 'Starting lint check only for modules changed')) modules_changed = get_modules_changed(dir, branch_base) if not modules_changed: print( travis_helpers.green('There are not modules changed from ' '"git --git-dir=%s diff ..%s"' % (dir, branch_base))) return res modules_changed_cmd = [] for module_changed in modules_changed: modules_changed_cmd.extend(['--path', module_changed]) conf = ["--config-file=%s" % (pylint_rcfile_pr)] cmd = conf + modules_changed_cmd + extra_params_cmd pr_real_errors = main(cmd, standalone_mode=False) pr_stats = dict( (key, value) for key, value in (pr_real_errors.get('by_msg') or {}).items() if key not in beta_msgs) if pr_stats: pr_errors = get_count_fails(pr_real_errors, list(beta_msgs)) print( travis_helpers.yellow("Found %s errors in modules changed." % (pr_errors))) if pr_errors < 0: res = pr_stats else: new_dict = {} for val in res: new_dict[val] = (new_dict.get(val, 0) + res[val]) for val in pr_stats: new_dict[val] = (new_dict.get(val, 0) + pr_stats[val]) res = new_dict return res
def pylint_run(is_pr, version, dir): # Look for an environment variable # whose value is the name of a proper configuration file for pylint # (this file will then be expected to be found in the 'cfg/' folder). # If such an environment variable is not found, # it defaults to the standard configuration file. pylint_config_file = os.environ.get( 'PYLINT_CONFIG_FILE', 'travis_run_pylint.cfg') pylint_rcfile = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', pylint_config_file) pylint_rcfile_pr = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', "travis_run_pylint_pr.cfg") odoo_version = version_validate(version, dir) modules_cmd = get_modules_cmd(dir) beta_msgs = get_beta_msgs() branch_base = get_branch_base() extra_params_cmd = get_extra_params(odoo_version) extra_info = "extra_params_cmd %s " % extra_params_cmd print(extra_info) conf = ["--config-file=%s" % (pylint_rcfile)] cmd = conf + modules_cmd + extra_params_cmd real_errors = main(cmd, standalone_mode=False) res = dict( (key, value) for key, value in (real_errors.get( 'by_msg') or {}).items() if key not in beta_msgs) count_errors = get_count_fails(real_errors, list(beta_msgs)) count_info = "count_errors %s" % count_errors print(count_info) if is_pr: print(travis_helpers.green( 'Starting lint check only for modules changed')) modules_changed = get_modules_changed(dir, branch_base) if not modules_changed: print(travis_helpers.green( 'There are not modules changed from ' '"git --git-dir=%s diff ..%s"' % (dir, branch_base))) return res modules_changed_cmd = [] for module_changed in modules_changed: modules_changed_cmd.extend(['--path', module_changed]) conf = ["--config-file=%s" % (pylint_rcfile_pr)] cmd = conf + modules_changed_cmd + extra_params_cmd pr_real_errors = main(cmd, standalone_mode=False) pr_stats = dict( (key, value) for key, value in (pr_real_errors.get( 'by_msg') or {}).items() if key not in beta_msgs) if pr_stats: pr_errors = get_count_fails(pr_real_errors, list(beta_msgs)) print(travis_helpers.yellow( "Found %s errors in modules changed." % (pr_errors))) if pr_errors < 0: res = pr_stats else: new_dict = {} for val in res: new_dict[val] = (new_dict.get(val, 0) + res[val]) for val in pr_stats: new_dict[val] = (new_dict.get(val, 0) + pr_stats[val]) res = new_dict return res
if isinstance(res, string_types): res = res.strip('\n') res = res.splitlines() res = [path.dirname(i).split('/')[0] for i in res] res = list(set(res)) return res config_file = path.abspath(sys.argv[1]) repo_path = os.environ.get('TRAVIS_BUILD_DIR', False) expected_errors = int(os.environ.get('PYLINT_EXPECTED_ERRORS', 0)) modules = [] status = 0 for change in changer_files(path.abspath(repo_path)): if not change: continue modules.extend(['--path', change]) if modules: conf = ["--config-file=%s" % (config_file)] cmd = conf + modules + extra_params res = run_pylint.main(cmd, standalone_mode=False) count_errors = run_pylint.get_count_fails(res, []) if count_errors and count_errors != expected_errors: status = 1 print( travis_helpers.red( "pylint expected errors found {0}!".format(count_errors))) else: print(travis_helpers.green("Good...!!")) exit(status)