summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/database.py
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2011-05-30 08:57:44 (GMT)
committerTarek Ziade <tarek@ziade.org>2011-05-30 08:57:44 (GMT)
commita17d8883fd6b001bef57cc1f7cfdb0504446d9db (patch)
treede947fb31b04725df3affe9b466aeccd9ab9dfcc /Lib/packaging/database.py
parent72e58651b27e8b0a8f4170531ca6e985d9947d1b (diff)
downloadcpython-a17d8883fd6b001bef57cc1f7cfdb0504446d9db.zip
cpython-a17d8883fd6b001bef57cc1f7cfdb0504446d9db.tar.gz
cpython-a17d8883fd6b001bef57cc1f7cfdb0504446d9db.tar.bz2
a resource module for 2 functions is overkill. database is the right place for those
Diffstat (limited to 'Lib/packaging/database.py')
-rw-r--r--Lib/packaging/database.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/packaging/database.py b/Lib/packaging/database.py
index b107148..010c4eb 100644
--- a/Lib/packaging/database.py
+++ b/Lib/packaging/database.py
@@ -18,6 +18,7 @@ __all__ = [
'get_distributions', 'get_distribution', 'get_file_users',
'provides_distribution', 'obsoletes_distribution',
'enable_cache', 'disable_cache', 'clear_cache',
+ 'get_file_path', 'get_file'
]
@@ -627,3 +628,17 @@ def get_file_users(path):
for dist in get_distributions():
if dist.uses(path):
yield dist
+
+
+def get_file_path(distribution_name, relative_path):
+ """Return the path to a resource file."""
+ dist = get_distribution(distribution_name)
+ if dist != None:
+ return dist.get_resource_path(relative_path)
+ raise LookupError('no distribution named %r found' % distribution_name)
+
+
+def get_file(distribution_name, relative_path, *args, **kwargs):
+ """Open and return a resource file."""
+ return open(get_file_path(distribution_name, relative_path),
+ *args, **kwargs)