Skip to content

Commit

Permalink
[ADD] runbot_push_pot
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Jan 30, 2020
1 parent 8845595 commit 157a240
Show file tree
Hide file tree
Showing 20 changed files with 817 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -27,7 +27,7 @@ env:
matrix:
- LINT_CHECK="1"
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="runbot_buildout"
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="runbot_travis2docker"
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="runbot_travis2docker,runbot_push_pot"

before_install:
# Fix https://github.com/travis-ci/travis-ci/issues/8982#issuecomment-354357640
Expand Down
102 changes: 102 additions & 0 deletions runbot_push_pot/README.rst
@@ -0,0 +1,102 @@
===========================
Export translatable strings
===========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frunbot--addons-lightgray.png?logo=github
:target: https://github.com/OCA/runbot-addons/tree/11.0/runbot_push_pot
:alt: OCA/runbot-addons
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/runbot-addons-11-0/runbot-addons-11-0-runbot_push_pot
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/146/11.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module exports translations for your builds and pushes them back to your repository.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

#. give the user running your runbot write access to the repositories in question
#. go to one of your stable branches and check the box ``Push Pot``

Usage
=====

This module presupposes a directory structure like::

addon_name/i18n/addon_name.pot

in the root of your repository.

So if you don't have that, it won't work for you.

Known issues / Roadmap
======================

* investigate if we can do the commit via the API using the exsiting git{hub,lab} token

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/runbot-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/runbot-addons/issues/new?body=module:%20runbot_push_pot%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Therp BV

Contributors
~~~~~~~~~~~~

* Holger Brunn <hbrunn@therp.nl>

Other credits
~~~~~~~~~~~~~

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/runbot-addons <https://github.com/OCA/runbot-addons/tree/11.0/runbot_push_pot>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions runbot_push_pot/__init__.py
@@ -0,0 +1,3 @@
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
16 changes: 16 additions & 0 deletions runbot_push_pot/__manifest__.py
@@ -0,0 +1,16 @@
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Export translatable strings",
"version": "11.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Runbot",
"summary": "Export & push .pot files to your repo",
"depends": [
'runbot',
],
"data": [
"views/runbot_branch.xml",
],
}
4 changes: 4 additions & 0 deletions runbot_push_pot/models/__init__.py
@@ -0,0 +1,4 @@
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import runbot_build
from . import runbot_branch
13 changes: 13 additions & 0 deletions runbot_push_pot/models/runbot_branch.py
@@ -0,0 +1,13 @@
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


class RunbotBranch(models.Model):
_inherit = 'runbot.branch'

push_pot = fields.Boolean(
default=False, help='Enable this on your stable branch to have runbot '
'push new translatable strings to your repo. Note this will overwrite '
'your existing pot file',
)
86 changes: 86 additions & 0 deletions runbot_push_pot/models/runbot_build.py
@@ -0,0 +1,86 @@
# Copyright 2019 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import multiprocessing
import subprocess
import tarfile
import tempfile
from odoo import models
from odoo.addons.runbot.common import lock


class RunbotBuild(models.Model):
_inherit = 'runbot.build'

def _job_29_export_translations(self, build, lock_path, log_path):
if not build.branch_id.push_pot:
return -2
command, modules = build._cmd()
process = multiprocessing.Process(
target=self._export_translations.__func__,
args=(
None,
command, modules, build.repo_id.path, build.repo_id.name,
build.branch_id.branch_name, '%s-all' % build.dest, lock_path,
log_path, self.env['ir.config_parameter'].get_param(
'runbot_push_pot.commit_message',
'[UPD] updated translations from runbot',
),
),
name='translation export for %s' % build,
)
process.start()
return process.pid

def _export_translations(
self, command, modules, repo_path, repo_url, branch_name, db_name,
lock_path, log_path, commit_message,
):
"""Do the actual translation export. Note you can't override this
because we don't use it as a class member"""
lock(lock_path)
with open(log_path, 'w') as log_file, tempfile.NamedTemporaryFile(
suffix='.tgz', delete=False,
) as translation_file:
command.extend([
'-d', db_name,
'--i18n-export', translation_file.name,
'--modules', modules,
'--stop-after-init',
])
subprocess.check_call(
command, stdout=log_file, stderr=log_file,
)
translations = tarfile.open(translation_file.name)
with tempfile.TemporaryDirectory() as checkout:
subprocess.run(
['git', 'clone', repo_path, checkout],
stdout=log_file, stderr=log_file,
)

def git(*cmd, **kwargs):
cmd = ('git', '-C', checkout) + cmd
return subprocess.run(
cmd, stdout=log_file, stderr=log_file, **kwargs
)

git('checkout', branch_name)
translations.extractall(checkout)
git('add', '.')
diff_lines = [
line for line in
subprocess.run(
['git', '-C', checkout, 'diff', 'HEAD', '-U0'],
capture_output=True
).stdout.decode('utf8').split('\n')
if
# we want only lines from the diff where we actually have
# changes, and we want to ignore the date fields because
# they change for every export
(line.startswith('+') or line.startswith('-')) and not
(line.startswith('+++') or line.startswith('---')) and
'POT-Creation-Date' not in line and
'PO-Revision-Date' not in line
]
if diff_lines:
git('commit', '-m', commit_message)
git('push', repo_url, branch_name)
4 changes: 4 additions & 0 deletions runbot_push_pot/readme/CONFIGURE.rst
@@ -0,0 +1,4 @@
To configure this module, you need to:

#. give the user running your runbot write access to the repositories in question
#. go to one of your stable branches and check the box ``Push Pot``
1 change: 1 addition & 0 deletions runbot_push_pot/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Holger Brunn <hbrunn@therp.nl>
1 change: 1 addition & 0 deletions runbot_push_pot/readme/CREDITS.rst
@@ -0,0 +1 @@
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
1 change: 1 addition & 0 deletions runbot_push_pot/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
This module exports translations for your builds and pushes them back to your repository.
1 change: 1 addition & 0 deletions runbot_push_pot/readme/ROADMAP.rst
@@ -0,0 +1 @@
* investigate if we can do the commit via the API using the exsiting git{hub,lab} token
7 changes: 7 additions & 0 deletions runbot_push_pot/readme/USAGE.rst
@@ -0,0 +1,7 @@
This module presupposes a directory structure like::

addon_name/i18n/addon_name.pot

in the root of your repository.

So if you don't have that, it won't work for you.
Binary file added runbot_push_pot/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 157a240

Please sign in to comment.