1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
4 # Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 from __future__ import absolute_import
23 from ._gi import _API, Repository
25 # Force loading the GObject typelib so we have available the wrappers for
26 # base classes such as GInitiallyUnowned
30 _API = _API # pyflakes
35 _overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
38 def require_version(namespace, version):
39 repository = Repository.get_default()
41 if namespace in repository.get_loaded_namespaces():
42 loaded_version = repository.get_version(namespace)
43 if loaded_version != version:
44 raise ValueError('Namespace %s is already loaded with version %s' % \
45 (namespace, loaded_version))
47 if namespace in _versions and _versions[namespace] != version:
48 raise ValueError('Namespace %s already requires version %s' % \
49 (namespace, _versions[namespace]))
51 available_versions = repository.enumerate_versions(namespace)
52 if not available_versions:
53 raise ValueError('Namespace %s not available' % namespace)
55 if version not in available_versions:
56 raise ValueError('Namespace %s not available for version %s' % \
59 _versions[namespace] = version
62 def get_required_version(namespace):
63 return _versions.get(namespace, None)