Commit 61e526cc authored by Manuel Günther's avatar Manuel Günther
Browse files

Implemented detailed listing of resources

parent 7a950416
......@@ -98,7 +98,7 @@ class Algorithm:
info : str
A string containing the full information of all parameters of this (and the derived) class.
"""
return "%s(%s)" % (str(self.__class__), ", ".join(["%s=%s" % (key, value) for key,value in self._kwargs.items() if value is not None]))
return utils.pretty_print(self, self._kwargs)
def project(self, feature):
......
......@@ -88,7 +88,7 @@ class Extractor:
info : str
A string containing the full information of all parameters of this (and the derived) class.
"""
return "%s(%s)" % (str(self.__class__), ", ".join(["%s=%s" % (key, value) for key,value in self._kwargs.items() if value is not None]))
return utils.pretty_print(self, self._kwargs)
############################################################
......
......@@ -91,6 +91,15 @@ class Grid:
):
self.grid_type = grid_type
if self.is_local():
self._kwargs = dict(grid_type=grid_type, number_of_parallel_processes=number_of_parallel_processes, scheduler_sleep_time=scheduler_sleep_time)
else:
self._kwargs = dict(
grid_type=grid_type,
number_of_preprocessing_jobs=number_of_preprocessing_jobs, number_of_extraction_jobs=number_of_extraction_jobs, number_of_projection_jobs=number_of_projection_jobs, number_of_enrollment_jobs=number_of_enrollment_jobs,
training_queue=training_queue, preprocessing_queue=preprocessing_queue, extraction_queue=extraction_queue, projection_queue=projection_queue, enrollment_queue=enrollment_queue, scoring_queue=scoring_queue
)
# the numbers
if self.is_local():
......@@ -118,6 +127,10 @@ class Grid:
self.scheduler_sleep_time = scheduler_sleep_time
def __str__(self):
"""Converts this grid configuration into a string, which contains the complete set of parameters."""
return utils.pretty_print(self, self._kwargs)
def queue(self, params):
"""queue(params) -> dict
......
......@@ -78,7 +78,7 @@ class Preprocessor:
info : str
A string containing the full information of all parameters of this (and the derived) class.
"""
return "%s(%s)" % (str(self.__class__), ", ".join(["%s=%s" % (key, value) for key,value in self._kwargs.items() if value is not None]))
return utils.pretty_print(self, self._kwargs)
############################################################
### Special functions that might be overwritten on need
......
......@@ -8,20 +8,23 @@ def resources():
import argparse
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--details", '-d', nargs = '+',
parser.add_argument("--types", '-t', nargs = '+',
choices = ('d', 'database', 'p', 'preprocessor', 'e', 'extractor', 'a', 'algorithm', 'g', 'grid'),
default = ('d', 'p', 'e', 'a', 'g'),
help = "Select the resource types that should be listed.")
parser.add_argument("--details", '-d', action='store_true', help = "Prints the complete configuration for all resources")
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()
kwargs = {}
kwargs = {'verbose' : args.verbose}
if args.no_strip_dummy:
kwargs['strip'] = []
if 'd' in args.details or 'database' in args.details:
print ("\nList of registered databases:")
print (bob.bio.base.list_resources('database', **kwargs))
......
......@@ -51,3 +51,7 @@ def selected_elements(list_of_elements, desired_number_of_elements = None):
return list_of_elements
# sub-select
return [list_of_elements[i] for i in selected_indices(total_number_of_elements, desired_number_of_elements)]
def pretty_print(obj, kwargs):
"""Returns a pretty-print of the parameters to the constructor of a class, which should be able to copy-paste on the command line to create the object (with few exceptions)."""
return "%s(%s)" % (str(obj.__class__), ", ".join(["%s='%s'" % (key,value) if isinstance(value, str) else "%s=%s" % (key, value) for key,value in kwargs.items() if value is not None]))
......@@ -178,7 +178,7 @@ def extensions(keywords=valid_keywords, package_prefix='bob.bio.'):
keywords : [str]
A list of keywords to load entry points for.
Defaults to all :py:attr:`valid_keywords`.
package_prefix : str
Package namespace, in which we search for entry points, e.g., ``bob.bio``.
"""
......@@ -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.'):
def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=False):
"""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)))
......@@ -213,6 +213,9 @@ def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.'):
retval += " + %s --> %s: %s\n" % (entry_point.name + " "*(length - len(entry_point.name)), entry_point.module_name, entry_point.attrs[0])
else:
retval += " + %s --> %s\n" % (entry_point.name + " "*(length - len(entry_point.name)), entry_point.module_name)
if verbose:
retval += " ==> " + str(entry_point.load()) + "\n\n"
return retval
......
......@@ -82,7 +82,13 @@ To get a list of registered resources, please call:
$ ./bin/resources.py
Each package in ``bob.bio`` defines its own resources, and the printed list of registered resources differs according to the installed packages.
If only ``bob.bio.base`` is installed, no databases and no preprocessors will be listed.
If only ``bob.bio.base`` is installed, no databases and only one preprocessor will be listed.
To see more details about the resources, i.e., the full constructor call fo the respective class, use the ``--details`` (or shortly ``-d``) option, and to sub-select only specific types of resources, use the ``--types`` (or ``-t``) option:
.. code-block:: sh
$ ./bin/resources.py -dt algorithm
.. note::
You will also find some ``grid`` resources being listed.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment