def _register_pull_request(self, component, status): branch_name = 'conflict-%s-weblate' % self.branch self._git.run(["add", component['filemask']]) self._git.run([ "commit", "--no-verify", "--author='Weblate bot <weblate@bot>'", "-m", "[REF] i18n: Conflict on the daily cron", "-m", status ]) self._git.run(["branch", "-m", branch_name]) self._git.run(["push", "-f", "origin", branch_name]) pull = self.gh_api.create_pull_request({ 'title': '[REF] i18n: Conflict on the daily cron', 'head': '%s:%s' % (self.repo_name.split('/')[0].split(':')[1], branch_name), 'base': self.branch, 'body': status }) self._git.run( ["checkout", "-qb", self.branch, "origin/%s" % self.branch]) self._git.run(["branch", "-D", branch_name]) print yellow("The pull request register is: %s" % pull['html_url'])
def wl_push(project): res = weblate(project['repository_url']) if res['needs_push'] or res['needs_commit']: print(yellow("Weblate commit %s" % project['repository_url'])) weblate(project['repository_url'], {'operation': 'commit'}) print(yellow("Weblate push %s" % project['repository_url'])) weblate(project['repository_url'], {'operation': 'push'}) return True print(yellow("Don't needs weblate push %s" % project['repository_url'])) return False
def update(self): self._check() self.wl_api.load_project(self.repo_name, self.branch) with self.wl_api.component_lock(): self._git.run(["fetch", "origin"]) first_commit = False component = [ item for item in self.wl_api.components if item['git_export'] ] if len(component) > 1: print( yellow("To many repository for this project %s" % self.wl_api.project['name'])) return 1 remote = (self.wl_api.ssh + '/' + self.wl_api.project['slug'] + '/' + component[0]['slug']) name = '%s-wl' % self.wl_api.project['slug'] self._git.run(["remote", "add", name, remote]) for component in self.wl_api.components: print(yellow("Component %s" % component['slug'])) self._git.run([ "checkout", "-qb", self.branch, "origin/%s" % self.branch ]) self.wl_api.component_repository(component, 'pull') self._git.run(["fetch", name]) if self._generate_odoo_po_files(component['name']): first_commit = self._commit_weblate(first_commit) self._git.run([ "merge", "--squash", "-s", "recursive", "-X", "ours", "%s/%s" % (name, self.branch) ]) if self._check_conflict(component): break if (component['filemask'].replace('/*.po', '') in self._git.run(["status"])): self._git.run(["add", component['filemask']]) first_commit = self._commit_weblate(first_commit) if self._check_conflict(component): break first_commit = self._commit_weblate(first_commit) self._git.run(["remote", "remove", name]) modules_no_processed = [ module for module in self._installed_modules if module not in [comp['name'] for comp in self.wl_api.components] ] for component in modules_no_processed: if self._generate_odoo_po_files(component, only_installed=False): first_commit = self._commit_weblate(first_commit) if not self._push_git_repository(): return 1 return 0
def update(self): self._check() self.wl_api.load_project(self.repo_name, self.branch) with self.wl_api.component_lock(): self._git.run(["fetch", "origin"]) first_commit = False component = [item for item in self.wl_api.components if item['git_export']] if len(component) > 1: print yellow("To many repository for this project %s" % self.wl_api.project['name']) return 1 remote = (self.wl_api.ssh + '/' + self.wl_api.project['slug'] + '/' + component[0]['slug']) name = '%s-wl' % self.wl_api.project['slug'] self._git.run(["remote", "add", name, remote]) for component in self.wl_api.components: print yellow("Component %s" % component['slug']) self._git.run(["checkout", "-qb", self.branch, "origin/%s" % self.branch]) self.wl_api.component_repository(component, 'pull') self._git.run(["fetch", name]) if self._generate_odoo_po_files(component['name']): first_commit = self._commit_weblate(first_commit) self._git.run(["merge", "--squash", "-s", "recursive", "-X", "ours", "%s/%s" % (name, self.branch)]) if self._check_conflict(component): break if (component['filemask'].replace('/*.po', '') in self._git.run(["status"])): self._git.run(["add", component['filemask']]) first_commit = self._commit_weblate(first_commit) if self._check_conflict(component): break first_commit = self._commit_weblate(first_commit) self._git.run(["remote", "remove", name]) modules_no_processed = [module for module in self._installed_modules if module not in [comp['name'] for comp in self.wl_api.components]] for component in modules_no_processed: if self._generate_odoo_po_files(component, only_installed=False): first_commit = self._commit_weblate(first_commit) if not self._push_git_repository(): return 1 return 0
def lock(project, filter_modules=None): components = [component['lock_url'] for component in get_components(project, filter_modules)] try: for component in components: print(yellow("Lock %s" % component)) res = weblate(component, {'lock': True}) print("..%s" % res) if not res['locked']: raise ValueError("Project not locked %s token **%s. %s" % ( component, WEBLATE_TOKEN[-4:], res)) yield finally: for component in components: print(yellow("unlock %s" % component)) res = weblate(component, {'lock': False}) print("..%s" % res)
def lock(project, filter_modules=None): components = [ component['lock_url'] for component in get_components(project, filter_modules) ] try: for component in components: print(yellow("Lock %s" % component)) res = weblate(component, {'lock': True}) print("..%s" % res) if not res['locked']: raise ValueError("Project not locked %s token **%s. %s" % (component, WEBLATE_TOKEN[-4:], res)) yield finally: for component in components: print(yellow("unlock %s" % component)) res = weblate(component, {'lock': False}) print("..%s" % res)
def _register_pull_request(self, component, status): branch_name = 'conflict-%s-weblate' % self.branch self._git.run(["add", component['filemask']]) self._git.run(["commit", "--no-verify", "--author='Weblate bot <weblate@bot>'", "-m", "[REF] i18n: Conflict on the daily cron", "-m", status]) self._git.run(["branch", "-m", branch_name]) self._git.run(["push", "-f", "origin", branch_name]) pull = self.gh_api.create_pull_request({ 'title': '[REF] i18n: Conflict on the daily cron', 'head': '%s:%s' % (self.repo_name.split('/')[0].split(':')[1], branch_name), 'base': self.branch, 'body': status }) self._git.run(["checkout", "-qb", self.branch, "origin/%s" % self.branch]) self._git.run(["branch", "-D", branch_name]) print yellow("The pull request register is: %s" % pull['html_url'])
def update(self): self._check() self.wl_api.load_project(self.repo_name, self.branch) if not self.wl_api.components: print yellow("No component found for %s" % self.repo_name) return 1 with self.wl_api.component_lock(): self._git.run(["fetch", "origin"]) first_commit = False for component in self.wl_api.components: print yellow("Component %s" % component['slug']) name = '%s-wl' % component['slug'] remote = (self.wl_api.host.replace('api', 'git') + '/' + self.wl_api.project['slug'] + '/' + component['slug']) self._git.run([ "checkout", "-qb", self.branch, "origin/%s" % self.branch ]) self.wl_api.component_repository(component, 'pull') self._git.run(["remote", "add", name, remote]) self._git.run(["fetch", name]) if self._generate_odoo_po_files(component): first_commit = self._commit_weblate(first_commit) self._git.run([ "merge", "--squash", "-s", "recursive", "-X", "ours", "%s/%s" % (name, self.branch) ]) self._git.run(["remote", "remove", name]) if self._check_conflict(component): break if (component['filemask'].replace('/*.po', '') in self._git.run(["status"])): self._git.run(["add", component['filemask']]) first_commit = self._commit_weblate(first_commit) if self._check_conflict(component): break first_commit = self._commit_weblate(first_commit) if not self._push_git_repository(): return 1 return 0
def version_validate(version, dir): if not version and dir: repo_path = os.path.join(dir, '.git') branch_name = GitRun(repo_path).get_branch_name() version = (branch_name.replace('_', '-').split('-')[:1] if branch_name else False) version = version[0] if version else None if not version: print( travis_helpers.yellow('Undefined environment variable' ' `VERSION`.\nSet `VERSION` for ' 'compatibility with guidelines by version.')) return version
def version_validate(version, dir): if not version and dir: repo_path = os.path.join(dir, '.git') branch_name = GitRun(repo_path).get_branch_name() version = (branch_name.replace('_', '-').split('-')[:1] if branch_name else False) version = version[0] if version else None if not version: print(travis_helpers.yellow( 'Undefined environment variable' ' `VERSION`.\nSet `VERSION` for ' 'compatibility with guidelines by version.')) return version
def _generate_odoo_po_files(self, module, only_installed=True): generated = False with self._connection_context(self._server_path, self._addons_path, self._database) as odoo_context: if only_installed and module not in self._installed_modules: return generated print("\n", yellow("Obtaining POT file for %s" % module)) i18n_folder = os.path.join(self._travis_build_dir, module, 'i18n') if not os.path.isdir(i18n_folder): os.makedirs(i18n_folder) # Put git add for letting known git which translations to update po_files = glob.glob(os.path.join(i18n_folder, '*.po')) for lang in self._langs: if os.path.isfile(os.path.join(i18n_folder, lang + '.po')): continue po_content = odoo_context.get_pot_contents(module, lang) if not po_content: continue with open(os.path.join(i18n_folder, lang + '.po'), 'wb')\ as f_po: f_po.write(po_content) if self._git.run(["add", "-v", f_po.name]): generated = True for po_file_name in po_files: lang = os.path.basename(os.path.splitext(po_file_name)[0]) if self._langs and lang not in self._langs: # Limit just allowed languages if is defined continue po_file_path = os.path.join(i18n_folder, po_file_name) with open(po_file_path, 'r') as f_po: odoo_context.load_po(f_po, lang) new_content = odoo_context.get_pot_contents(module, lang) if not new_content: continue with open(po_file_path, 'wb') as f_po: f_po.write(new_content) diff = self._git.run(["diff", "HEAD", po_file_path]) if diff.count('msgstr') == 1: self._git.run(["checkout", po_file_path]) if self._git.run(["add", "-v"] + po_files): generated = True return generated
def wl_pull(project): print(yellow("Weblate pull %s" % project['repository_url'])) return weblate(project['repository_url'], {'operation': 'pull'})
def main(argv=None): """ Export translation files and push them to Transifex The transifex password should be encrypted in .travis.yml If not, export exits early. """ if argv is None: argv = sys.argv transifex_user = os.environ.get("TRANSIFEX_USER") transifex_password = os.environ.get("TRANSIFEX_PASSWORD") if not transifex_user: print( yellow_light("WARNING! Transifex user not defined- " "exiting early.")) return 1 if not transifex_password: print( yellow_light("WARNING! Transifex password not recognized- " "exiting early.")) return 1 travis_home = os.environ.get("HOME", "~/") travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") travis_repo_slug = os.environ.get("TRAVIS_REPO_SLUG") travis_repo_owner = travis_repo_slug.split("/")[0] travis_repo_shortname = travis_repo_slug.split("/")[1] odoo_unittest = False odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") install_options = os.environ.get("INSTALL_OPTIONS", "").split() odoo_version = os.environ.get("VERSION") if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = sys.argv[1] print( yellow_light("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version)) default_project_slug = "%s-%s" % (travis_repo_slug.replace( '/', '-'), odoo_version.replace('.', '-')) transifex_project_slug = os.environ.get("TRANSIFEX_PROJECT_SLUG", default_project_slug) transifex_project_name = "%s (%s)" % (travis_repo_shortname, odoo_version) transifex_organization = os.environ.get("TRANSIFEX_ORGANIZATION", travis_repo_owner) transifex_fill_up_resources = os.environ.get("TRANSIFEX_FILL_UP_RESOURCES", "True") transifex_team = os.environ.get("TRANSIFEX_TEAM", "23907") repository_url = "https://github.com/%s" % travis_repo_slug odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_version, travis_home) addons_path = get_addons_path(travis_home, travis_build_dir, server_path) addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) addons = ','.join(addons_list) print("\nWorking in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not addons: print(yellow_light("WARNING! Nothing to translate- exiting early.")) return 0 # Create Transifex project if it doesn't exist print() print(yellow("Creating Transifex project if it doesn't exist")) auth = (transifex_user, transifex_password) api_url = "https://www.transifex.com/api/2/" api = API(api_url, auth=auth) project_data = { "slug": transifex_project_slug, "name": transifex_project_name, "source_language_code": "en", "description": transifex_project_name, "repository_url": repository_url, "organization": transifex_organization, "license": "permissive_open_source", "fill_up_resources": transifex_fill_up_resources, "team": transifex_team, } try: api.project(transifex_project_slug).get() print('This Transifex project already exists.') except exceptions.HttpClientError: try: api.projects.post(project_data) print('Transifex project has been successfully created.') except exceptions.HttpClientError: print('Transifex organization: %s' % transifex_organization) print('Transifex username: %s' % transifex_user) print('Transifex project slug: %s' % transifex_project_slug) print( red('Error: Authentication failed. Please verify that ' 'Transifex organization, user and password are ' 'correct. You can change these variables in your ' '.travis.yml file.')) raise print("\nModules to translate: %s" % addons) # Install the modules on the database database = "openerp_i18n" setup_server(database, odoo_unittest, addons, server_path, addons_path, install_options, addons_list) # Initialize Transifex project print() print(yellow('Initializing Transifex project')) init_args = [ '--host=https://www.transifex.com', '--user=%s' % transifex_user, '--pass=%s' % transifex_password ] commands.cmd_init(init_args, path_to_tx=None) path_to_tx = utils.find_dot_tx() connection_context = context_mapping[odoo_version] with connection_context(server_path, addons_path, database) \ as odoo_context: for module in addons_list: print() print(yellow("Downloading PO file for %s" % module)) source_filename = os.path.join(travis_build_dir, module, 'i18n', module + ".pot") # Create i18n/ directory if doesn't exist if not os.path.exists(os.path.dirname(source_filename)): os.makedirs(os.path.dirname(source_filename)) with open(source_filename, 'w') as f: f.write(odoo_context.get_pot_contents(module)) print() print(yellow("Linking PO file and Transifex resource")) set_args = [ '-t', 'PO', '--auto-local', '-r', '%s.%s' % (transifex_project_slug, module), '%s/i18n/<lang>.po' % module, '--source-lang', 'en', '--source-file', source_filename, '--execute' ] commands.cmd_set(set_args, path_to_tx) print() print(yellow('Pushing translation files to Transifex')) push_args = ['-s', '-t', '--skip'] commands.cmd_push(push_args, path_to_tx) return 0
def main(argv=None): """ Export translation files and push them to Transifex The transifex password should be encrypted in .travis.yml If not, export exits early. """ if argv is None: argv = sys.argv transifex_user = os.environ.get("TRANSIFEX_USER") transifex_password = os.environ.get("TRANSIFEX_PASSWORD") if not transifex_user: print(yellow_light("WARNING! Transifex user not defined- " "exiting early.")) return 1 if not transifex_password: print(yellow_light("WARNING! Transifex password not recognized- " "exiting early.")) return 1 travis_home = os.environ.get("HOME", "~/") travis_dependencies_dir = os.path.join(travis_home, 'dependencies') travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") travis_repo_slug = os.environ.get("TRAVIS_REPO_SLUG") travis_repo_owner = travis_repo_slug.split("/")[0] travis_repo_shortname = travis_repo_slug.split("/")[1] odoo_unittest = False odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") install_options = os.environ.get("INSTALL_OPTIONS", "").split() odoo_version = os.environ.get("VERSION") if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print(yellow_light("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version)) default_project_slug = "%s-%s" % (travis_repo_slug.replace('/', '-'), odoo_version.replace('.', '-')) transifex_project_slug = os.environ.get("TRANSIFEX_PROJECT_SLUG", default_project_slug) transifex_project_name = "%s (%s)" % (travis_repo_shortname, odoo_version) transifex_organization = os.environ.get("TRANSIFEX_ORGANIZATION", travis_repo_owner) transifex_fill_up_resources = os.environ.get( "TRANSIFEX_FILL_UP_RESOURCES", "True" ) transifex_team = os.environ.get( "TRANSIFEX_TEAM", "23907" ) repository_url = "https://github.com/%s" % travis_repo_slug odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_version, travis_home) addons_path = get_addons_path(travis_dependencies_dir, travis_build_dir, server_path) addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) addons = ','.join(addons_list) create_server_conf({'addons_path': addons_path}, odoo_version) print("\nWorking in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not addons: print(yellow_light("WARNING! Nothing to translate- exiting early.")) return 0 # Create Transifex project if it doesn't exist print() print(yellow("Creating Transifex project if it doesn't exist")) auth = (transifex_user, transifex_password) api_url = "https://www.transifex.com/api/2/" api = API(api_url, auth=auth) project_data = {"slug": transifex_project_slug, "name": transifex_project_name, "source_language_code": "en", "description": transifex_project_name, "repository_url": repository_url, "organization": transifex_organization, "license": "permissive_open_source", "fill_up_resources": transifex_fill_up_resources, "team": transifex_team, } try: api.project(transifex_project_slug).get() print('This Transifex project already exists.') except exceptions.HttpClientError: try: api.projects.post(project_data) print('Transifex project has been successfully created.') except exceptions.HttpClientError: print('Transifex organization: %s' % transifex_organization) print('Transifex username: %s' % transifex_user) print('Transifex project slug: %s' % transifex_project_slug) print(red('Error: Authentication failed. Please verify that ' 'Transifex organization, user and password are ' 'correct. You can change these variables in your ' '.travis.yml file.')) raise print("\nModules to translate: %s" % addons) # Install the modules on the database database = "openerp_i18n" setup_server(database, odoo_unittest, addons, server_path, addons_path, install_options, addons_list) # Initialize Transifex project print() print(yellow('Initializing Transifex project')) init_args = ['--host=https://www.transifex.com', '--user=%s' % transifex_user, '--pass=%s' % transifex_password] commands.cmd_init(init_args, path_to_tx=None) path_to_tx = utils.find_dot_tx() connection_context = context_mapping[odoo_version] with connection_context(server_path, addons_path, database) \ as odoo_context: for module in addons_list: print() print(yellow("Downloading POT file for %s" % module)) source_filename = os.path.join(travis_build_dir, module, 'i18n', module + ".pot") # Create i18n/ directory if doesn't exist if not os.path.exists(os.path.dirname(source_filename)): os.makedirs(os.path.dirname(source_filename)) with open(source_filename, 'w') as f: f.write(odoo_context.get_pot_contents(module)) print() print(yellow("Linking POT file and Transifex resource")) set_args = ['-t', 'PO', '--auto-local', '-r', '%s.%s' % (transifex_project_slug, module), '%s/i18n/<lang>.po' % module, '--source-lang', 'en', '--source-file', source_filename, '--execute'] commands.cmd_set(set_args, path_to_tx) print() print(yellow('Pushing translation files to Transifex')) push_args = ['-s', '-t', '--skip'] commands.cmd_push(push_args, path_to_tx) return 0
def main(argv=None): try: TravisWeblateUpdate().update() except ApiException as exc: print yellow(str(exc)) raise exc
import check_tags import travis_helpers version = os.environ.get('VERSION', '') token = os.environ.get('GITHUB_TOKEN') travis_pull_request_number = os.environ.get('TRAVIS_PULL_REQUEST') travis_repo_slug = os.environ.get('TRAVIS_REPO_SLUG') travis_pr_slug = os.environ.get('TRAVIS_PULL_REQUEST_SLUG') travis_branch = os.environ.get('TRAVIS_BRANCH') travis_build_dir = os.environ.get('TRAVIS_BUILD_DIR') error_msg = "Check guidelines: https://gitlab.com/itpp/handbook/blob/master/documenting-updates.md If you are not IT-Projects' employee, you can ignore it and we'll handle it by our own" exit_status = 0 result = check_tags.get_errors_msgs_commits(travis_repo_slug, travis_pull_request_number, travis_branch, version, token, travis_build_dir, travis_pr_slug) count_errors = len(result.keys()) if count_errors > 0: for key, value in result.items(): print('Faulty discription of commit or update of files:') print(travis_helpers.yellow("{commit}".format(commit=key))) print(travis_helpers.red("{errors}".format(errors=value))) print(error_msg) print() print() print( travis_helpers.red("check tags errors: found {number_errors}!".format( number_errors=count_errors))) exit_status = 1 exit(exit_status)
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 main(argv=None): """ Export translation files and push them to Transifex The transifex password should be encrypted in .travis.yml If not, export exits early. """ if argv is None: argv = sys.argv transifex_user = os.environ.get("TRANSIFEX_USER", "*****@*****.**") transifex_password = os.environ.get("TRANSIFEX_PASSWORD") if not transifex_user: print( yellow_light("WARNING! Transifex user not defined- " "exiting early.")) return 1 if not transifex_password: print( yellow_light("WARNING! Transifex password not recognized- " "exiting early.")) return 1 travis_home = os.environ.get("HOME", "~/") travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..") travis_repo_slug = os.environ.get("TRAVIS_REPO_SLUG") travis_repo_owner = travis_repo_slug.split("/")[0] travis_repo_shortname = travis_repo_slug.split("/")[1] odoo_unittest = False odoo_exclude = os.environ.get("EXCLUDE") odoo_include = os.environ.get("INCLUDE") install_options = os.environ.get("INSTALL_OPTIONS", "").split() odoo_version = os.environ.get("VERSION") langs = parse_list(os.environ.get("LANG_ALLOWED", "")) if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set odoo_version = argv[1] print( yellow_light("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version)) default_project_slug = "%s-%s" % (travis_repo_slug.replace( '/', '-'), odoo_version.replace('.', '-')) transifex_project_slug = os.environ.get("TRANSIFEX_PROJECT_SLUG", default_project_slug) transifex_project_name = "%s (%s)" % (travis_repo_shortname, odoo_version) transifex_organization = os.environ.get("TRANSIFEX_ORGANIZATION", travis_repo_owner) transifex_fill_up_resources = os.environ.get("TRANSIFEX_FILL_UP_RESOURCES", "True") transifex_team = os.environ.get("TRANSIFEX_TEAM", "45447") repository_url = "https://github.com/%s" % travis_repo_slug odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo") server_path = get_server_path(odoo_full, odoo_version, travis_home) addons_path = get_addons_path(travis_home, travis_build_dir, server_path) addons_list = get_addons_to_check(travis_build_dir, odoo_include, odoo_exclude) addons_path_list = parse_list(addons_path) all_depends = get_depends(addons_path_list, addons_list) main_modules = set(os.listdir(travis_build_dir)) main_depends = main_modules & all_depends addons_list = list(main_depends) addons = ','.join(addons_list) create_server_conf({'addons_path': addons_path}, odoo_version) print("\nWorking in %s" % travis_build_dir) print("Using repo %s and addons path %s" % (odoo_full, addons_path)) if not addons: print(yellow_light("WARNING! Nothing to translate- exiting early.")) return 0 # Create Transifex project if it doesn't exist print() print(yellow("Creating Transifex project if it doesn't exist")) auth = (transifex_user, transifex_password) api_url = "https://www.transifex.com/api/2/" api = API(api_url, auth=auth) project_data = { "slug": transifex_project_slug, "name": transifex_project_name, "source_language_code": "en", "description": transifex_project_name, "repository_url": repository_url, "organization": transifex_organization, "license": "permissive_open_source", "fill_up_resources": transifex_fill_up_resources, "team": transifex_team, } try: api.project(transifex_project_slug).get() print('This Transifex project already exists.') except exceptions.HttpClientError: try: api.projects.post(project_data) print('Transifex project has been successfully created.') except exceptions.HttpClientError: print('Transifex organization: %s' % transifex_organization) print('Transifex username: %s' % transifex_user) print('Transifex project slug: %s' % transifex_project_slug) print( red('Error: Authentication failed. Please verify that ' 'Transifex organization, user and password are ' 'correct. You can change these variables in your ' '.travis.yml file.')) raise print("\nModules to translate: %s" % addons) # Install the modules on the database database = "openerp_test" script_name = get_server_script(odoo_version) setup_server(database, odoo_unittest, addons, server_path, script_name, addons_path, install_options, addons_list) # Initialize Transifex project print() print(yellow('Initializing Transifex project')) init_args = [ '--host=https://www.transifex.com', '--user=%s' % transifex_user, '--pass=%s' % transifex_password ] commands.cmd_init(init_args, path_to_tx=None) path_to_tx = utils.find_dot_tx() # Use by default version 10 connection context connection_context = context_mapping.get(odoo_version, Odoo10Context) with connection_context(server_path, addons_path, database) \ as odoo_context: for module in addons_list: print() print(yellow("Obtaining POT file for %s" % module)) i18n_folder = os.path.join(travis_build_dir, module, 'i18n') source_filename = os.path.join(i18n_folder, module + ".pot") # Create i18n/ directory if doesn't exist if not os.path.exists(os.path.dirname(source_filename)): os.makedirs(os.path.dirname(source_filename)) with open(source_filename, 'w') as f: f.write(odoo_context.get_pot_contents(module)) # Put the correct timestamp for letting known tx client which # translations to update for po_file_name in os.listdir(i18n_folder): if not po_file_name.endswith('.po'): continue if langs and os.path.splitext(po_file_name)[0] not in langs: # Limit just allowed languages if is defined os.remove(os.path.join(i18n_folder, po_file_name)) continue po_file_name = os.path.join(i18n_folder, po_file_name) command = [ 'git', 'log', '--pretty=format:%cd', '-n1', '--date=raw', po_file_name ] timestamp = float(subprocess.check_output(command).split()[0]) # This converts to UTC the timestamp timestamp = time.mktime(time.gmtime(timestamp)) os.utime(po_file_name, (timestamp, timestamp)) print() print(yellow("Linking POT file and Transifex resource")) set_args = [ '-t', 'PO', '--auto-local', '-r', '%s.%s' % (transifex_project_slug, module), '%s/i18n/<lang>.po' % module, '--source-lang', 'en', '--source-file', source_filename, '--execute' ] commands.cmd_set(set_args, path_to_tx) print() print(yellow('Pushing translation files to Transifex')) push_args = ['-s', '-t', '--skip'] commands.cmd_push(push_args, path_to_tx) return 0
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