Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge dc4c01a into c1b733b
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jun 13, 2018
2 parents c1b733b + dc4c01a commit 62356a2
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 622 deletions.
26 changes: 6 additions & 20 deletions sample_files/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ addons:

env:
global:
- VERSION="10.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- VERSION="10.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0"
# Set this variable to some version existing as linux-generic build on
# https://github.com/wkhtmltopdf/wkhtmltopdf/releases
# if you need to install wkhtmltopdf
Expand All @@ -46,28 +46,14 @@ env:
# Use the above line to install dependencies that are required for website repos:
# * SASS & Bootstrap-SASS
# * Compass
- TRANSIFEX_USER='transbot@odoo-community.org'
# This line contains the encrypted transifex password
# To encrypt transifex password, install travis ruby utils with:
# $ 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).
# The default organization is the owner of the repo.
# The default fill up resources (TM) is True.
# The default team is 23907. https://www.transifex.com/organization/oca/team/23907/
# - TRANSIFEX_PROJECT_SLUG=
# - TRANSIFEX_ORGANIZATION=
# - TRANSIFEX_FILL_UP_RESOURCES=
# - TRANSIFEX_TEAM=

matrix:
- LINT_CHECK="1"
- TRANSIFEX="1"
- TESTS="1" ODOO_REPO="odoo/odoo"
# use this to install a standalone database to export .pot files
# - MAKEPOT="1"
# add MAKEPOT="1" to a TEST line to export .pot files from
# the test database after test success
- TESTS="1" ODOO_REPO="odoo/odoo" MAKEPOT="1"
- TESTS="1" ODOO_REPO="OCA/OCB"
# either use the two lines above or the two below. Don't change the default if
# it's not necessary (it is only necessary if modules in your repository can't
Expand Down
4 changes: 0 additions & 4 deletions sample_files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ ${REPO_DESCRIPTION}
This part will be replaced when running the oca-gen-addons-table script from OCA/maintainer-tools.
[//]: # (end addons)

Translation Status
------------------
[![Transifex Status](https://www.transifex.com/projects/p/${ORG_NAME}-${REPO_NAME}-${BRANCH_NAME_WITH_DASH}/chart/image_png)](https://www.transifex.com/projects/p/${ORG_NAME}-${REPO_NAME}-${BRANCH_NAME_WITH_DASH})

----

OCA, or the [Odoo Community Association](http://odoo-community.org/), is a nonprofit organization whose
Expand Down
124 changes: 0 additions & 124 deletions travis/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import base64
import os
import re
import subprocess
import tempfile
import time
import json
from contextlib import contextmanager
import requests


Expand Down Expand Up @@ -44,125 +39,6 @@ def _request(self, url, payload=None, is_json=True, patch=False):
return response.json() if is_json else response


class WeblateApi(Request):

def __init__(self):
super(WeblateApi, self).__init__()
self.repo_slug = None
self.branch = None
self._token = os.environ.get("WEBLATE_TOKEN")
self.host = os.environ.get(
"WEBLATE_HOST", "https://weblate.odoo-community.org/api")
self.ssh = os.environ.get(
"WEBLATE_SSH", "ssh://user@webpage.com")
self.tempdir = os.path.join(tempfile.gettempdir(), 'weblate_api')
self._ssh_keyscan()

def _ssh_keyscan(self):
"""This method execute the command 'ssh-keysan' to avoid the
question when the command git clone is excecuted.
The question is like to:
'Are you sure you want to continue connecting (yes/no)?'"""
cmd = ['ssh-keyscan', '-p']
match = re.search(
r'(ssh\:\/\/\w+@(?P<host>[a-zA-Z0-9_.-]+))(:{0,1})'
r'(?P<port>(\d+))?', self.ssh)
if not match:
return False
data = match.groupdict()
cmd.append(data['port'] or '22')
cmd.append(data['host'])
with open(os.path.expanduser('~/.ssh/known_hosts'), 'a+') as hosts:
subprocess.Popen(cmd, stdout=hosts)

def get_project(self, repo_slug, branch):
self.branch = branch
projects = []
page = 1
while True:
data = self._request(self.host + '/projects/?page=%s' % page)
projects.extend(data['results'] or [])
if not data['next']:
break
page += 1
for project in projects:
if project['name'] == repo_slug:
self.repo_slug = project['slug']
return project
raise ApiException('No project found in "%s" for this path "%s"' %
(self.host, repo_slug))

def load_project(self, repo_slug, branch):
self.project = self.get_project(repo_slug, branch)
self.load_components()

def get_components(self):
components = []
values = []
page = 1
while True:
data = self._request(self.host +
'/projects/%s/components/?page=%s' %
(self.project['slug'], page))
values.extend(data['results'] or [])
if not data['next']:
break
page += 1
for value in values:
if value['branch'] and value['branch'] != self.branch:
continue
components.append(value)
return components

def load_components(self):
self.components = self.get_components()

def pull(self):
pull = self._request(
self.host + '/projects/%s/repository/' % self.project['slug'],
{'operation': 'pull'})
return pull['result']

def component_repository(self, component, operation):
result = self._request(self.host + '/components/%s/%s/repository/' %
(self.project['slug'], component['slug']),
{'operation': operation})
return result['result']

@contextmanager
def component_lock(self):
try:
for component in self.components:
self._component_lock(component)
self._component_commit(component)
yield
finally:
for component in self.components:
self._component_lock(component, lock=False)

def _component_lock(self, component, lock=True):
url = (self.host + '/components/%s/%s/lock/' %
(self.project['slug'], component['slug']))
for i in range(10):
new_lock = self._request(url, {'lock': lock})
if new_lock['locked'] == lock:
break
time.sleep(60)
return True

def _component_commit(self, component):
url = (self.host + '/components/%s/%s/repository/' %
(self.project['slug'], component['slug']))
needs_commit = self._request(url)
if not needs_commit['needs_commit']:
return
new_commit = self._request(url, {'operation': 'commit'})
if not new_commit['result']:
raise ApiException('The commit into the component "%s" cannot be '
'made' % component['slug'])
return True


class GitHubApi(Request):

def __init__(self):
Expand Down
16 changes: 16 additions & 0 deletions travis/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ def main(argv=None):
return 1
elif counted_errors != expected_errors:
return 1
# no test error, let's generate .pot and msgmerge all .po files
must_run_makepot = (
os.environ.get('MAKEPOT') == '1' and
os.environ.get('TRAVIS_PULL_REQUEST') == 'false' and
os.environ.get('GITHUB_USER') and
os.environ.get('GITHUB_TOKEN')
)
if must_run_makepot:
# run makepot using the database we just tested
makepot_cmd = ['unbuffer'] if unbuffer else []
makepot_cmd += [
'travis_makepot',
database,
]
if subprocess.call(makepot_cmd) != 0:
return 1
# if we get here, all is OK
return 0

Expand Down
88 changes: 88 additions & 0 deletions travis/travis_makepot
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env python

from __future__ import print_function
from contextlib import contextmanager
import os
import subprocess

from test_server import setup_server, get_addons_path, \
get_server_path, get_addons_to_check, create_server_conf, get_server_script


@contextmanager
def setenv(key, value):
old_value = os.environ.get(key)
os.environ[key] = value
try:
yield
finally:
if old_value:
os.environ[key] = old_value
else:
del os.environ[key]


def main(argv=None, database=None):
odoo_full = os.environ.get("ODOO_REPO", "odoo/odoo")
odoo_version = os.environ.get("VERSION")
odoo_exclude = os.environ.get("EXCLUDE")
odoo_include = os.environ.get("INCLUDE")
odoo_unittest = False
install_options = os.environ.get("INSTALL_OPTIONS", "").split()
travis_home = os.environ.get("HOME", "~/")
travis_dependencies_dir = os.path.join(travis_home, 'dependencies')
travis_build_dir = os.environ.get("TRAVIS_BUILD_DIR", "../..")
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 database:
database = 'openerp_i18n'
print("\nInitializing db %s to generate .pot for: %s" % (database, addons))
script_name = get_server_script(server_path)
setup_server(database, odoo_unittest, addons_list, server_path,
script_name, addons_path, install_options, addons_list)
else:
print("\nUsing db %s to generate .pot" % (database, ))

print("Installing click-odoo-contrib")
r = subprocess.call([
'pip', 'install', 'click-odoo-contrib',
])
if r:
return r

with setenv('PYTHONPATH', server_path):
print("Exporting .pot files")
r = subprocess.call([
'click-odoo-makepot',
'-d', database,
'--commit',
'--log-level=debug',
])
if r:
return r

print("Pushing .pot files changes to GitHub")
r = subprocess.call([
'git', 'push',
'https://{GITHUB_USER}:{GITHUB_TOKEN}@github.com/'
'{TRAVIS_REPO_SLUG}'.format(**os.environ),
'HEAD:{TRAVIS_BRANCH}'.format(**os.environ),
])
if r:
return r

return 0


if __name__ == "__main__":
exit(main(sys.argv[1]))
31 changes: 14 additions & 17 deletions travis/travis_run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ if __name__ == '__main__':
lint_check_enabled = os.environ.get('LINT_CHECK') == '1'
tests_enabled = os.environ.get('TESTS') == '1'
tests_unspecified = os.environ.get('TESTS') is None
transifex_enabled = os.environ.get('TRANSIFEX') == '1'
weblate_enabled = os.environ.get('WEBLATE') == '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 or not is_oca_transifex_user)
# run makepot using a fresh database
# where addons are going to be installed
# is MAKEPOT=1 and TESTS=1, test_server.py will run
# makepot using the test database, which will be faster
must_run_makepot = (
(os.environ.get('MAKEPOT') == '1' or
os.environ.get('TRANSIFEX') == '1') and
not tests_enabled and
not is_pull_request and
os.environ.get('GITHUB_USER') and
os.environ.get('GITHUB_TOKEN')
)

# Test list. Each test is a list with command + arguments.
tests = []
Expand All @@ -77,16 +82,8 @@ if __name__ == '__main__':
elif tests_enabled:
tests.append(['test_server.py'])

if transifex_enabled and is_valid_transifex:
tests.append(['travis_transifex.py'])

is_valid_weblate = (
not is_pull_request and os.environ.get('UNIT_TEST') != '1' and
['test_server.py'] in tests)

if weblate_enabled and is_valid_weblate:
# Re-use database of TESTS=1 except if UNIT_TEST is enabled.
tests.append(['travis_weblate.py'])
if must_run_makepot:
tests.append(['travis_makepot])

if tests:
exit(main(tests))

0 comments on commit 62356a2

Please sign in to comment.