diff options
author | Ronan Amicel <ronan.amicel@gmail.com> | 2012-10-26 00:54:18 +0200 |
---|---|---|
committer | Ronan Amicel <ronan.amicel@gmail.com> | 2012-10-26 04:05:01 +0200 |
commit | 8a1c97b5ea3dd9339c2e20277f300058c8730ead (patch) | |
tree | 79a69e12bdcc4187f6dd1ffb8284de5ea1291463 | |
parent | Add extra options to create_user (thanks to Gaƫl Pasgrimaud) [#40] (diff) | |
download | fabtools-8a1c97b5ea3dd9339c2e20277f300058c8730ead.tar.xz |
Fix locales support on Debian [#42]
-rw-r--r-- | fabtools/require/postgres.py | 37 | ||||
-rw-r--r-- | fabtools/require/system.py | 12 | ||||
-rw-r--r-- | fabtools/tests/fabfiles/system.py | 13 | ||||
-rw-r--r-- | fabtools/tests/test_postgres.py | 16 |
4 files changed, 57 insertions, 21 deletions
diff --git a/fabtools/require/postgres.py b/fabtools/require/postgres.py index 6a0be8e..77cfec9 100644 --- a/fabtools/require/postgres.py +++ b/fabtools/require/postgres.py @@ -4,12 +4,24 @@ PostgreSQL users and databases """ from __future__ import with_statement -import os.path - -from fabtools.files import is_file +from fabtools.files import is_file, watch from fabtools.postgres import * from fabtools.require.deb import package -from fabtools.require.service import started +from fabtools.require.service import started, restarted +from fabtools.require.system import locale as require_locale + + +def _service_name(version=None): + + if is_file('/etc/init.d/postgresql'): + return 'postgresql' + + if version and is_file('/etc/init.d/postgresql-%s' % version): + return 'postgresql-%s' % version + + with cd('/etc/init.d'): + with settings(hide('running', 'stdout')): + return run('ls postgresql-*').splitlines()[0] def server(version=None): @@ -29,16 +41,7 @@ def server(version=None): pkg_name = 'postgresql' package(pkg_name) - if is_file('/etc/init.d/postgresql'): - service_name = 'postgresql' - else: - if version and is_file('/etc/init.d/postgresql-%s' % version): - service_name = 'postgresql-%s' % version - else: - with cd('/etc/init.d'): - with settings(hide('running', 'stdout')): - service_name = run('ls postgresql-*').splitlines()[0] - started(service_name) + started(_service_name(version)) def user(name, password): @@ -69,5 +72,11 @@ def database(name, owner, template='template0', encoding='UTF8', """ if not database_exists(name): + + with watch('/etc/locale.gen') as locales: + require_locale(locale) + if locales.changed: + restarted(_service_name()) + create_database(name, owner, template=template, encoding=encoding, locale=locale) diff --git a/fabtools/require/system.py b/fabtools/require/system.py index bb1a651..f7ff1ed 100644 --- a/fabtools/require/system.py +++ b/fabtools/require/system.py @@ -4,10 +4,12 @@ System settings """ from __future__ import with_statement +from re import escape + from fabric.api import sudo, warn -from fabric.contrib.files import append +from fabric.contrib.files import append, uncomment -from fabtools.files import watch +from fabtools.files import is_file, watch from fabtools.system import ( get_hostname, set_hostname, get_sysctl, set_sysctl, @@ -48,6 +50,9 @@ def locales(names): config_file = '/var/lib/locales/supported.d/local' + if not is_file(config_file): + config_file = '/etc/locale.gen' + # Regenerate locales if config file changes with watch(config_file, use_sudo=True) as config: @@ -57,12 +62,13 @@ def locales(names): if name in supported: charset = supported[name] locale = "%s %s" % (name, charset) + uncomment(config_file, escape(locale), use_sudo=True) append(config_file, locale, use_sudo=True) else: warn('Unsupported locale name "%s"' % name) if config.changed: - sudo('dpkg-reconfigure locales') + sudo('dpkg-reconfigure --frontend=noninteractive locales') def locale(name): diff --git a/fabtools/tests/fabfiles/system.py b/fabtools/tests/fabfiles/system.py new file mode 100644 index 0000000..7463c34 --- /dev/null +++ b/fabtools/tests/fabfiles/system.py @@ -0,0 +1,13 @@ +from __future__ import with_statement + +from fabric.api import * +from fabtools import require + + +@task +def locales(): + """ + Check locales configuration + """ + require.system.locale('en_US.UTF-8') + require.system.locale('fr_FR.UTF-8') diff --git a/fabtools/tests/test_postgres.py b/fabtools/tests/test_postgres.py index 526d3b5..2a6a1b6 100644 --- a/fabtools/tests/test_postgres.py +++ b/fabtools/tests/test_postgres.py @@ -4,15 +4,23 @@ import unittest class PostgresTestCase(unittest.TestCase): + @mock.patch('fabtools.require.postgres._service_name') + @mock.patch('fabtools.require.postgres.restarted') + @mock.patch('fabtools.require.postgres.watch') + @mock.patch('fabtools.require.postgres.require_locale') @mock.patch('fabtools.require.postgres.create_database') @mock.patch('fabtools.require.postgres.database_exists') - def test_params_respected(self, database_exists, create_database): - """ If require.database is called, ensure that the template, encoding - and locale parameters are passed through to the underlying - create_database call """ + def test_params_respected(self, database_exists, create_database, + require_locale, watch, restarted, service_name): + """ + If require.database is called, ensure that the template, + encoding and locale parameters are passed through to the + underlying create_database call + """ from fabtools import require database_exists.return_value = False require.postgres.database('foo', 'bar', locale='some_locale', encoding='some_encoding', template='some_template') + require_locale.assert_called_with('some_locale') create_database.assert_called_with('foo', 'bar', locale='some_locale', encoding='some_encoding', template='some_template') |