From 50c676e55d05614774f403a92d487dd78a372c9f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 15 Feb 2017 11:55:12 +0100 Subject: [PATCH] Setting locale --- lib/webhooks/r10k.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 10aeef4..2bea9b1 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -14,6 +14,7 @@ import logging import re import textwrap import datetime +import locale # Third party modules import yaml @@ -27,8 +28,6 @@ from webhooks.base_app import BaseHookApp __version__ = webhooks.__version__ LOG = logging.getLogger(__name__) -DEFAULT_EMAIL = 'frank.brehm@pixelpark.com' -DEFAULT_SENDER = 'Puppetmaster <{}>'.format(DEFAULT_EMAIL) # ============================================================================= @@ -47,6 +46,8 @@ class R10kHookApp(BaseHookApp): the local repository and deploys it with r10k. ''').strip() + self.locale = 'de_DE.utf8' + super(R10kHookApp, self).__init__( appname=appname, verbose=verbose, version=version) @@ -83,6 +84,29 @@ class R10kHookApp(BaseHookApp): elif isinstance(config['add_ignore_projects'], list): self.ignore_projects += config['add_ignore_projects'] + if 'locale' in config and config['locale']: + self.locale = config['locale'] + + # ------------------------------------------------------------------------- + def pre_run(self): + + if not super(R10kHookApp, self).pre_run(): + return False + + if self.full_name in self.ignore_projects or self.name in self.ignore_projects: + LOG.info("Ignoring project {!r}.".format(self.full_name)) + return False + + cur_loc = locale.getlocale() + cur_lang = os.environ.get('LANG', None) + if self.verbose > 1: + LOG.debug("Current locale is: {lo!r}, current LANG is {la!r}.".format( + lo=cur_loc, la=cur_lang)) + + LOG.debug("Setting locale and LANG to: {!r}.".format(self.locale)) + locale.setlocale(locale.LC_ALL, self.locale) + os.environ['LANG'] = self.locale + # ------------------------------------------------------------------------- def run(self): """Main routine.""" -- 2.39.5