Skip to content
Snippets Groups Projects
Commit 9b8bac52 authored by Manuel Günther's avatar Manuel Günther
Browse files

Implemented #25 by adding a '--packages' option to ./bin/resources.py

parent f19871c0
No related branches found
No related tags found
No related merge requests found
......@@ -15,12 +15,14 @@ def resources(command_line_parameters = None):
parser.add_argument("--details", '-d', action='store_true', help = "Prints the complete configuration for all resources")
parser.add_argument("--packages", '-p', nargs='+', help = "If given, shows only resources defined in the given package(s)")
parser.add_argument("--no-strip-dummy", '-s', action = 'store_true',
help = "If given, the dummy elements (usually used for testing purposes only) are **not** removed from the list.")
args = parser.parse_args(command_line_parameters)
kwargs = {'verbose' : args.details}
kwargs = {'verbose' : args.details, "packages" : args.packages}
if args.no_strip_dummy:
kwargs['strip'] = []
......
......@@ -369,7 +369,7 @@ def test_resources():
# simply test that the collect_results script works
from bob.bio.base.script.resources import resources, databases
with utils.Quiet():
resources(['--types', 'database', 'preprocessor', 'extractor', 'algorithm', 'grid', '--details'])
resources(['--types', 'database', 'preprocessor', 'extractor', 'algorithm', 'grid', '--details', '--packages', 'bob.bio.base'])
databases([])
......
......@@ -194,7 +194,7 @@ def resource_keys(keyword, exclude_packages=[], package_prefix='bob.bio.', strip
if entry_point.dist.project_name not in exclude_packages])
def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=False):
def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=False, packages=None):
"""Returns a string containing a detailed list of resources that are registered with the given keyword."""
if keyword not in valid_keywords:
raise ValueError("The given keyword '%s' is not valid. Please use one of %s!" % (str(keyword), str(valid_keywords)))
......@@ -204,7 +204,10 @@ def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=
retval = ""
length = max(len(entry_point.name) for entry_point in entry_points) if entry_points else 1
for entry_point in sorted(entry_points, key=lambda p: p.dist.project_name):
if packages is not None:
entry_points = [entry_point for entry_point in entry_points if entry_point.dist.project_name in packages]
for entry_point in sorted(entry_points, key=lambda p: (p.dist.project_name, p.name)):
if last_dist != str(entry_point.dist):
retval += "\n- %s @ %s: \n" % (str(entry_point.dist), str(entry_point.dist.location))
last_dist = str(entry_point.dist)
......@@ -224,7 +227,7 @@ def database_directories(strip=['dummy'], replacements = None, package_prefix='b
entry_points = _get_entry_points('database', strip, package_prefix=package_prefix)
dirs = {}
for entry_point in sorted(entry_points, key=lambda entry_point: entry_point.name):
for entry_point in sorted(entry_points, key=lambda entry_point: entry_point.name):
try:
db = load_resource(entry_point.name, 'database')
db.replace_directories(replacements)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment