Skip to content

Commit

Permalink
Merge branch 'release/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rizziepit committed Jul 22, 2015
2 parents 990d97f + 77b540a commit 08aec8b
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.1.0
-----
- enable i18n for new springboard apps
- add update_messages command to manage translations

3.0.5
-----
- add uwsgi to dependencies
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.5
3.1.0
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
entry_points={
'paste.app_factory': ['main = springboard.application:main'],
'console_scripts': ['springboard = springboard.tools.main:main'],
})
},
message_extractors={'.': [
('**.py', 'python', None),
('**.jinja2', 'jinja2', None),
]})
1 change: 1 addition & 0 deletions springboard/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def main(global_config, **settings):

config = Configurator(settings=defaults)
config.include('springboard.config')
config.add_translation_dirs('springboard:locale/')
config.configure_celery(global_config['__file__'])

return config.make_wsgi_app()
1 change: 1 addition & 0 deletions springboard/locale/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is here because i18n requires the locale directory to exist.
57 changes: 56 additions & 1 deletion springboard/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import yaml

from mock import patch, Mock

from springboard.tests import SpringboardTestCase
from springboard.utils import parse_repo_name
from springboard.tools.commands import (
CloneRepoTool, CreateIndexTool, CreateMappingTool, SyncDataTool,
BootstrapTool, ImportContentTool)
BootstrapTool, ImportContentTool, UpdateMessagesTool)
from springboard.tools.commands.base import YAMLFile


Expand Down Expand Up @@ -308,3 +310,56 @@ def test_import_remote(self):
self.assertEqual(data['repositories'], {
repo_name: self.workspace.working_dir
})


class TestUpdateMessagesTool(SpringboardToolTestCase):

@patch('springboard.tools.commands.update_messages.run_setup')
def test_update_messages(self, mocked_run_setup):
tool = UpdateMessagesTool()
tool.stdout = StringIO()
ini_config = self.mk_configfile({
'app:main': {
'available_languages': 'eng_GB\npor_PT',
}
})
mocked_run_setup.return_value = Mock(get_name=Mock(return_value='foo'))

tool.run(
ini_config=ini_config,
ini_section='app:main',
locales=[])

mocked_run_setup.assert_any_call(
'setup.py',
['extract_messages', '-o', 'foo/locale/messages.pot'])
mocked_run_setup.assert_any_call(
'setup.py',
['init_catalog', '-i', 'foo/locale/messages.pot',
'-d', 'foo/locale', '-l', 'por_PT'])
mocked_run_setup.assert_any_call(
'setup.py',
['init_catalog', '-i', 'foo/locale/messages.pot',
'-d', 'foo/locale', '-l', 'eng_GB'])
mocked_run_setup.assert_any_call(
'setup.py',
['update_catalog', '-i', 'foo/locale/messages.pot',
'-d', 'foo/locale'])
mocked_run_setup.assert_any_call(
'setup.py',
['compile_catalog', '-d', 'foo/locale'])

mocked_run_setup.reset_mock()
tool.run(
ini_config=ini_config,
ini_section='app:main',
locales=['swa_KE'])

mocked_run_setup.assert_any_call(
'setup.py',
['init_catalog', '-i', 'foo/locale/messages.pot',
'-d', 'foo/locale', '-l', 'swa_KE'])
init_calls = filter(
lambda call: len(call[0]) > 1 and call[0][1][0] == 'init_catalog',
mocked_run_setup.call_args_list)
self.assertEqual(len(init_calls), 1)
2 changes: 2 additions & 0 deletions springboard/tools/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from springboard.tools.commands.bootstrap import BootstrapTool
from springboard.tools.commands.startapp import StartAppTool
from springboard.tools.commands.import_content import ImportContentTool
from springboard.tools.commands.update_messages import UpdateMessagesTool

__all__ = [
'CloneRepoTool',
Expand All @@ -14,4 +15,5 @@
'BootstrapTool',
'StartAppTool',
'ImportContentTool',
'UpdateMessagesTool',
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@

[app:main]
use = egg:{{cookiecutter.app_name}}

# A repo URL can be a local path, either relative to repos_dir, or absolute.
# Alternatively, a URL can point to a unicore.distribute repo endpoint.
# The index on Elasticsearch corresponds to the basename (minus .git or .json suffix).
# For that reason, the basename must be alphanumeric and lowercase. It may also not
# start with _.
# https://github.com/elastic/elasticsearch/issues/6736

; unicore.content_repo_urls =
; thumbor.security_key = '{{cookiecutter.thumbor_security_key}}'

; featured_languages =
; available_languages =

[celery]
CELERY_TASK_SERIALIZER = json
CELERY_ALWAYS_EAGER = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
'paste.app_factory': [
'main = {{cookiecutter.app_name}}.application:main',
],
})
},
message_extractors={'.': [
('**.py', 'python', None),
('**.jinja2', 'jinja2', None),
]})
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ def main(global_config, **settings):
override_with='{{cookiecutter.app_name}}:templates/')
config.add_static_view(
'static', '{{cookiecutter.app_name}}:static', cache_max_age=3600)
config.add_translation_dirs('{{cookiecutter.app_name}}:locale/')
config.configure_celery(global_config['__file__'])

return config.make_wsgi_app()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is here because i18n requires the locale directory to exist.
65 changes: 65 additions & 0 deletions springboard/tools/commands/update_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import glob
from distutils.core import run_setup
from ConfigParser import ConfigParser

from springboard.utils import config_list
from springboard.tools.commands.base import ToolCommand, CommandArgument


class UpdateMessagesTool(ToolCommand):

command_name = 'update-messages'
command_help_text = 'Update or create .po and .mo message files'
command_arguments = (
CommandArgument(
'-i', '--ini',
dest='ini_config',
default='development.ini',
help='The paste ini file to get the locales from.'),
CommandArgument(
'-s', '--ini-section',
dest='ini_section',
default='app:main',
help='The paste ini section to get the locales from.'),
CommandArgument(
'-l', '--locale',
dest='locales',
nargs='*',
help='The locales to update or create.'),
)

def run(self, ini_config, ini_section, locales):
if not locales:
cp = ConfigParser()
cp.read(ini_config)
locales = config_list(cp.get(ini_section, 'available_languages'))

package_name = run_setup('setup.py', stop_after='init').get_name()
locale_dir = os.path.join(package_name, 'locale')
pot_filename = os.path.join(locale_dir, 'messages.pot')

# delete existing .mo files
for filename in glob.glob(
os.path.join(locale_dir, '*/LC_MESSAGES/*.mo')):
os.remove(filename)

# generate new .pot file
run_setup('setup.py', [
'extract_messages', '-o', pot_filename])

# initialize new locales' .po files
for locale in locales:
po_filename = os.path.join(
locale_dir, '%s/LC_MESSAGES/messages.po' % locale)
if os.path.exists(po_filename):
continue
run_setup('setup.py', [
'init_catalog', '-i', pot_filename, '-d', locale_dir,
'-l', locale])

# update and compile .po files
run_setup('setup.py', [
'update_catalog', '-i', pot_filename, '-d', locale_dir])
run_setup('setup.py', [
'compile_catalog', '-d', locale_dir])
2 changes: 2 additions & 0 deletions springboard/tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from springboard.tools.commands import BootstrapTool
from springboard.tools.commands import StartAppTool
from springboard.tools.commands import ImportContentTool
from springboard.tools.commands import UpdateMessagesTool


def get_parser(): # pragma: no cover
Expand All @@ -23,6 +24,7 @@ def get_parser(): # pragma: no cover
add_command(subparsers, SyncDataTool)
add_command(subparsers, StartAppTool)
add_command(subparsers, ImportContentTool)
add_command(subparsers, UpdateMessagesTool)
return parser


Expand Down

0 comments on commit 08aec8b

Please sign in to comment.