From bac698c8be7d2ae86ecf344403dcd42ff6a63449 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 24 Nov 2015 14:31:22 +0100 Subject: [PATCH 01/10] [IMP] .travis.yml: Include Transifex secure list link --- sample_files/.travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/sample_files/.travis.yml b/sample_files/.travis.yml index dd435f7fb..5023064a6 100644 --- a/sample_files/.travis.yml +++ b/sample_files/.travis.yml @@ -39,6 +39,7 @@ env: # $ gem install travis --user-install # and use: # $ travis encrypt TRANSIFEX_PASSWORD=your-password -r owner/project + # Secure list for current OCA projects is in https://github.com/OCA/maintainer-quality-tools/issues/194 - secure: PjP88tPSwimBv4tsgn3UcQAD1heK/wcuSaSfhi2xUt/jSrOaTmWzjaW2gH/eKM1ilxPXwlPGyAIShJ2JJdBiA97hQufOeiqxdkWDctnNVVEDx2Tk0BiG3PPYyhXPgUZ+FNOnjZFF3pNWvzXTQaB0Nvz8plqp93Ov/DEyhrCxHDs= # Use the following lines if you need to manually change the transifex project slug or/and the transifex organization. # The default project slug is owner-repo_name-version (with dash in the version string). From 2b5c17f9782166fcac867f8ff05137c2d65fa804 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 9 Dec 2015 18:56:04 +0100 Subject: [PATCH 02/10] [FIX] transifex: try to use Odoo8Context for export translations --- travis/odoo_connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/travis/odoo_connection.py b/travis/odoo_connection.py index 7cff92a77..7c3a8ab7d 100644 --- a/travis/odoo_connection.py +++ b/travis/odoo_connection.py @@ -122,4 +122,5 @@ def __enter__(self): context_mapping = { "7.0": Odoo7Context, "8.0": Odoo8Context, + "9.0": Odoo8Context, } From 294ce20e4d73a23d7fd6152f8adfc6cde76c7fb3 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 24 Feb 2016 18:26:33 +0100 Subject: [PATCH 03/10] [FIX] travis_transifex: include addons_path for installing correctly addons --- travis/travis_transifex.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index aec75ff4d..d1a2108df 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -49,7 +49,7 @@ def main(argv=None): if not odoo_version: # For backward compatibility, take version from parameter # if it's not globally set - odoo_version = sys.argv[1] + odoo_version = argv[1] print(yellow_light("WARNING: no env variable set for VERSION. " "Using '%s'" % odoo_version)) @@ -74,6 +74,7 @@ def main(argv=None): 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)) @@ -136,7 +137,7 @@ def main(argv=None): as odoo_context: for module in addons_list: print() - print(yellow("Downloading PO file for %s" % module)) + 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 @@ -146,7 +147,7 @@ def main(argv=None): f.write(odoo_context.get_pot_contents(module)) print() - print(yellow("Linking PO file and Transifex resource")) + print(yellow("Linking POT file and Transifex resource")) set_args = ['-t', 'PO', '--auto-local', '-r', '%s.%s' % (transifex_project_slug, module), From d8c48c01a6afab7cd2f9c522f9b29b2d8d04184f Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 24 Feb 2016 18:38:17 +0100 Subject: [PATCH 04/10] [FIX] travis_transifex: Missing import --- travis/travis_transifex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index d1a2108df..bda12d5aa 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -8,7 +8,7 @@ from slumber import API, exceptions from odoo_connection import context_mapping from test_server import setup_server, get_addons_path, \ - get_server_path, get_addons_to_check + get_server_path, get_addons_to_check, create_server_conf from travis_helpers import yellow, yellow_light, red from txclib import utils, commands From a55ffe5ee8fdd64a997d3505ef72e2d7f9408bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez?= Date: Fri, 8 Jul 2016 14:46:56 -0500 Subject: [PATCH 05/10] [REF] travis_run_tests: Avoid false red from forks for transifex builds --- travis/travis_run_tests | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/travis/travis_run_tests b/travis/travis_run_tests index e6639864e..d3fac444b 100755 --- a/travis/travis_run_tests +++ b/travis/travis_run_tests @@ -55,9 +55,15 @@ if __name__ == '__main__': tests_enabled = os.environ.get('TESTS') == '1' tests_unspecified = os.environ.get('TESTS') is None transifex_enabled = os.environ.get('TRANSIFEX') == '1' + is_oca_project = os.environ.get('TRAVIS_REPO_SLUG', '').startswith('OCA/') + is_oca_transifex_user = os.environ.get('TRANSIFEX_USER') == \ + 'transbot@odoo-community.org' # TRAVIS_PULL_REQUEST contains the pull request number or 'false' is_pull_request = os.environ.get('TRAVIS_PULL_REQUEST') != 'false' + # Avoid false red from forks using OCA transifex user + is_valid_transifex = not is_pull_request and \ + is_oca_project == is_oca_transifex_user # Test list. Each test is a list with command + arguments. tests = [] @@ -75,7 +81,7 @@ if __name__ == '__main__': elif tests_enabled: tests.append(['test_server.py']) - if transifex_enabled and not is_pull_request: + if transifex_enabled and is_valid_transifex: tests.append(['travis_transifex.py']) if tests: From d82a49060a1d835a7d90ef10ef3930d47772da47 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 10 Oct 2016 18:23:14 +0200 Subject: [PATCH 06/10] [FIX] travis_transifex: Include script_name --- travis/travis_transifex.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index bda12d5aa..d2a05f8d7 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -8,7 +8,7 @@ from slumber import API, exceptions from odoo_connection import context_mapping from test_server import setup_server, get_addons_path, \ - get_server_path, get_addons_to_check, create_server_conf + get_server_path, get_addons_to_check, create_server_conf, get_server_script from travis_helpers import yellow, yellow_light, red from txclib import utils, commands @@ -120,8 +120,9 @@ def main(argv=None): # Install the modules on the database database = "openerp_i18n" - setup_server(database, odoo_unittest, addons, server_path, addons_path, - install_options, addons_list) + 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() From 9bfcf4ac736b23d1ab1fa0acbb46fc8f3a8c31e8 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 11 Oct 2016 13:57:56 +0200 Subject: [PATCH 07/10] [FIX] travis_transifex: Connection environment for v10 --- travis/odoo_connection.py | 40 ++++++++++++++++++++++++++++++++++++++ travis/travis_transifex.py | 5 +++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/travis/odoo_connection.py b/travis/odoo_connection.py index 7c3a8ab7d..a3e7664a9 100644 --- a/travis/odoo_connection.py +++ b/travis/odoo_connection.py @@ -52,6 +52,45 @@ def get_pot_contents(self, addon): return buf.getvalue() +class Odoo10Context(_OdooBaseContext): + """A context for connecting to a odoo 10 server with function to export + .pot files. + """ + + def __enter__(self): + """ + Context enter function. + Temporarily add odoo 10 server path to system path and pop afterwards. + Import odoo 10 server from path as library. + Init logger, registry and environment. + Add addons path to config. + :returns Odoo10Context: This instance + """ + sys.path.append(self.server_path) + from odoo import netsvc, api + from odoo.modules.registry import RegistryManager + from odoo.tools import trans_export, config + self.trans_export = trans_export + sys.path.pop() + netsvc.init_logger() + config['addons_path'] = ( + config.get('addons_path') + ',' + self.addons_path + ) + registry = RegistryManager.new(self.dbname) + self.environment_manage = api.Environment.manage() + self.environment_manage.__enter__() + self.cr = registry.cursor() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + """ + Context exit function. + Cleanly close environment manage and cursor. + """ + self.environment_manage.__exit__(exc_type, exc_val, exc_tb) + super(Odoo10Context, self).__exit__(exc_type, exc_val, exc_tb) + + class Odoo8Context(_OdooBaseContext): """ A context for connecting to a odoo 8 server with function to export .pot @@ -123,4 +162,5 @@ def __enter__(self): "7.0": Odoo7Context, "8.0": Odoo8Context, "9.0": Odoo8Context, + "10.0": Odoo10Context, } diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index d2a05f8d7..16f4b9cfb 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -6,7 +6,7 @@ import os import sys from slumber import API, exceptions -from odoo_connection import context_mapping +from odoo_connection import context_mapping, Odoo10Context from test_server import setup_server, get_addons_path, \ get_server_path, get_addons_to_check, create_server_conf, get_server_script from travis_helpers import yellow, yellow_light, red @@ -133,7 +133,8 @@ def main(argv=None): commands.cmd_init(init_args, path_to_tx=None) path_to_tx = utils.find_dot_tx() - connection_context = context_mapping[odoo_version] + # 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: From edba68f4d1face328c5ba4cb9989da746ebdd421 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 12 Oct 2016 13:08:06 +0200 Subject: [PATCH 08/10] [FIX] requirements: Don't freeze Transifex client --- travis/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/requirements.txt b/travis/requirements.txt index 6295c1682..fe6182ff1 100644 --- a/travis/requirements.txt +++ b/travis/requirements.txt @@ -29,7 +29,7 @@ reportlab requests[security] simplejson slumber -transifex-client == 0.11b3 +transifex-client unittest2 vatnumber vobject From 8ff6f8cefeb419001bbed146913691797517be81 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 12 Oct 2016 13:52:20 +0200 Subject: [PATCH 09/10] [IMP] travis_transifex: Don't push to Transifex empty strings --- travis/requirements.txt | 1 + travis/travis_transifex.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/travis/requirements.txt b/travis/requirements.txt index fe6182ff1..720b23fa4 100644 --- a/travis/requirements.txt +++ b/travis/requirements.txt @@ -12,6 +12,7 @@ mako mock passlib pillow +polib psutil psycopg2 >= 2.2 pydot diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index 16f4b9cfb..a82979d42 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import os import sys +import polib from slumber import API, exceptions from odoo_connection import context_mapping, Odoo10Context from test_server import setup_server, get_addons_path, \ @@ -140,13 +141,26 @@ def main(argv=None): 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") + 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)) + # Strip out empty strings on PO files to avoid overwriting already + # translated strings in TX, but not pushed back to GH yet + for po_file_name in os.listdir(i18n_folder): + if not po_file_name.endswith('.po'): + continue + po_file_name = os.path.join(i18n_folder, po_file_name) + st = os.stat(po_file_name) # Remember modification time + po_file = polib.pofile(po_file_name) + for entry in po_file.untranslated_entries(): + po_file.remove(entry) + po_file.save(po_file_name) + # Overwrite modification time with the old one + os.utime(po_file_name, (st.st_atime, st.st_mtime)) print() print(yellow("Linking POT file and Transifex resource")) From 0684bc0888974232e8fa183b093ee9fc206b8d60 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 12 Oct 2016 21:41:11 +0200 Subject: [PATCH 10/10] [FIX] travis_transifex: Files timestamp --- travis/travis_transifex.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index a82979d42..fba5de858 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -5,7 +5,8 @@ from __future__ import unicode_literals import os import sys -import polib +import time +import subprocess from slumber import API, exceptions from odoo_connection import context_mapping, Odoo10Context from test_server import setup_server, get_addons_path, \ @@ -140,7 +141,7 @@ def main(argv=None): as odoo_context: for module in addons_list: print() - print(yellow("Downloading POT file for %s" % module)) + 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 @@ -148,19 +149,18 @@ def main(argv=None): os.makedirs(os.path.dirname(source_filename)) with open(source_filename, 'w') as f: f.write(odoo_context.get_pot_contents(module)) - # Strip out empty strings on PO files to avoid overwriting already - # translated strings in TX, but not pushed back to GH yet + # 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 po_file_name = os.path.join(i18n_folder, po_file_name) - st = os.stat(po_file_name) # Remember modification time - po_file = polib.pofile(po_file_name) - for entry in po_file.untranslated_entries(): - po_file.remove(entry) - po_file.save(po_file_name) - # Overwrite modification time with the old one - os.utime(po_file_name, (st.st_atime, st.st_mtime)) + 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"))