autohelp: make sure that oslo.i18n is setup

Some module imports fail without a proper setup of oslo.i18n, so make
sure that it is the case for projects using this package.

Change-Id: I7082cb893ccb52fa7bf065a01655efb9a5bbd4e2
This commit is contained in:
Gauvain Pocentek 2014-07-29 06:40:31 +02:00
parent 53a96cdaeb
commit 07fd34f29d
1 changed files with 11 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import sys
import git
from lxml import etree
import oslo.i18n as i18n
import stevedore
from hooks import HOOKS # noqa
@ -82,6 +83,16 @@ def import_modules(repo_location, package_name, verbose=0):
Loops through the repository, importing module by module to
populate the configuration object (cfg.CONF) created from Oslo.
"""
# If the project uses oslo.i18n, make sure that it is initialized so that
# the builtins contain the _ function.
requirements = os.path.join(repo_location, 'requirements.txt')
with open(requirements) as fd:
for line in fd:
if line.startswith('oslo.i18n'):
i18n.enable_lazy()
i18n.install(package_name)
pkg_location = os.path.join(repo_location, package_name)
for root, dirs, files in os.walk(pkg_location):
skipdir = False