mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
a resource module for 2 functions is overkill. database is the right place for those
This commit is contained in:
parent
72e58651b2
commit
a17d8883fd
4 changed files with 171 additions and 195 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue