Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #149 from vauxoo-dev/master-vx-merge-oca-moy
Browse files Browse the repository at this point in the history
Get transifex commits from oca/master
  • Loading branch information
moylop260 authored Nov 24, 2016
2 parents 0e5f8c0 + 0684bc0 commit d313bd5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
1 change: 1 addition & 0 deletions sample_files/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
41 changes: 41 additions & 0 deletions travis/odoo_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -122,4 +161,6 @@ def __enter__(self):
context_mapping = {
"7.0": Odoo7Context,
"8.0": Odoo8Context,
"9.0": Odoo8Context,
"10.0": Odoo10Context,
}
3 changes: 2 additions & 1 deletion travis/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mako
mock
passlib
pillow
polib
psutil
psycopg2 >= 2.2
pydot
Expand All @@ -29,7 +30,7 @@ reportlab
requests[security]
simplejson
slumber
transifex-client == 0.11b3
transifex-client
unittest2
vatnumber
vobject
Expand Down
8 changes: 7 additions & 1 deletion travis/travis_run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -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') == \
'[email protected]'

# 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 = []
Expand All @@ -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:
Expand Down
37 changes: 27 additions & 10 deletions travis/travis_transifex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))

Expand All @@ -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))
Expand Down Expand Up @@ -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()
Expand All @@ -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),
Expand Down

0 comments on commit d313bd5

Please sign in to comment.