OpenStack Image Management (Glance)
Go to file
Mark McLoughlin d35e558b93 Remove gettext.install() from glance/__init__.py
The gettext.install() function installs a builtin _() function which
translates a string in the translation domain supplied to the install()
function. If gettext.install() is called multiple times, it's the last
call to the function which wins and the last supplied translation domain
which is used e.g.

 >>> import os
 >>> os.environ['LANG'] = 'ja.UTF-8'
 >>> import gettext
 >>> gettext.install('keystone', unicode=1, localedir='/opt/stack/keystone/keystone/locale')
 >>> print _('Invalid syslog facility')
 無効な syslog ファシリティ
 >>> gettext.install('nova', unicode=1, localedir='/opt/stack/nova/nova/locale')
 >>> print _('Invalid syslog facility')
 Invalid syslog facility

Usually this function is called early on in a toplevel script and we
assume that no other code will call it and override the installed _().
However, in Glance, we have taken a shortcut to avoid having to call it
explicitly from each script and instead call it from glance/__init__.py.

This shortcut would be perfectly fine if we were absolutely sure that
glance modules would never be imported from another program. It's probably
quite incorrect for a program to use glance code (indeed, if we wanted to
support this, Glance code shouldn't use the default _() function) but
nevertheless there are some corner cases where it happens. For example,
the keystoneclient auth_token middleware tries to import cfg from
gance.openstack.common and this in turn causes gettext.install('glance')
to be called in other projects like glance or quantum.

To avoid any doubt here, let's just rip out the shortcut and always
call gettext.install() from the top-level script.

However, there's a bit of an annoying detail here - by default,
nosetests starts in the current directly and tries to import all modules
it finds to look for tests. Without the _() builtin installed, importing
some modules like glance.common.exception will fail.

Since it only ever makes sense to load tests from the glance/tests dir,
we can ask nose to do that by using the --tests argument via setup.cfg.

Note, this means that if you previously did this:

  $> tox -- glance.tests.foo glance.tests.bar

then you must now do this:

  $> tox -- --tests glance.tests.foo,glance.tests.bar

Change-Id: If4125d6bcbde63df95de129ac5c83b4a6d6f130a
2013-05-08 09:21:46 +01:00
doc/source Convert scripts to entry points 2013-04-29 14:08:29 -10:00
etc Use RBAC policy to determine if context is admin. 2013-05-02 16:40:24 +01:00
glance Remove gettext.install() from glance/__init__.py 2013-05-08 09:21:46 +01:00
tools Verify SSL certificates at boot time 2013-04-03 07:29:15 -10:00
.coveragerc Update .coveragerc 2013-02-06 16:47:06 +02:00
.gitignore Move to tag-based versioning. 2012-08-12 16:10:03 +00:00
.gitreview Add .gitreview config file for gerrit. 2011-10-24 11:02:16 -04:00
.mailmap Clean up pep8 E502, E711 violations 2012-09-18 10:10:01 +08:00
babel.cfg Added first step of babel-based translations. 2012-02-28 02:00:37 -08:00
HACKING.rst Expand HACKING with commit message guidelines 2013-04-26 15:27:09 -04:00
LICENSE Add a LICENSE file. 2012-01-03 10:14:01 -05:00
MANIFEST.in Update version code from oslo. 2013-01-13 14:27:48 -08:00
openstack-common.conf Reformat openstack-common.conf 2013-03-25 07:33:21 +00:00
pylintrc Packaging fixups 2010-10-21 15:51:44 -04:00
README.rst Replace README with links to better docs 2012-09-20 09:33:40 -07:00
run_tests.sh Convert scripts to entry points 2013-04-29 14:08:29 -10:00
setup.cfg Remove gettext.install() from glance/__init__.py 2013-05-08 09:21:46 +01:00
setup.py Convert scripts to entry points 2013-04-29 14:08:29 -10:00
tox.ini Convert scripts to entry points 2013-04-29 14:08:29 -10:00

Glance

Glance is a project that defines services for discovering, registering, retrieving and storing virtual machine images. Use the following resources to learn more: