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). diff --git a/travis/odoo_connection.py b/travis/odoo_connection.py index 7cff92a77..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 @@ -122,4 +161,6 @@ def __enter__(self): context_mapping = { "7.0": Odoo7Context, "8.0": Odoo8Context, + "9.0": Odoo8Context, + "10.0": Odoo10Context, } diff --git a/travis/requirements.txt b/travis/requirements.txt index 6295c1682..720b23fa4 100644 --- a/travis/requirements.txt +++ b/travis/requirements.txt @@ -12,6 +12,7 @@ mako mock passlib pillow +polib psutil psycopg2 >= 2.2 pydot @@ -29,7 +30,7 @@ reportlab requests[security] simplejson slumber -transifex-client == 0.11b3 +transifex-client unittest2 vatnumber vobject 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: diff --git a/travis/travis_transifex.py b/travis/travis_transifex.py index aec75ff4d..fba5de858 100755 --- a/travis/travis_transifex.py +++ b/travis/travis_transifex.py @@ -5,10 +5,12 @@ from __future__ import unicode_literals import os import sys +import time +import subprocess 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 + 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 @@ -49,7 +51,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 +76,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)) @@ -119,8 +122,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() @@ -131,22 +135,35 @@ 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: print() - print(yellow("Downloading PO file for %s" % module)) - source_filename = os.path.join(travis_build_dir, module, 'i18n', - module + ".pot") + 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 + 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 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),