Mercurial > cpython-lru_cache-weakref
diff Lib/packaging/database.py @ 70516:035ffa0af9f9
a resource module for 2 functions is overkill. database is the right place for those
| author | Tarek Ziade <tarek@ziade.org> |
|---|---|
| date | Mon, 30 May 2011 10:57:44 +0200 |
| parents | 391aa4da36b5 |
| children | d3f8c1cda108 |
line wrap: on
line diff
--- a/Lib/packaging/database.py Mon May 30 02:09:54 2011 +0200 +++ b/Lib/packaging/database.py Mon May 30 10:57:44 2011 +0200 @@ -18,6 +18,7 @@ '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 @@ 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)
