def run(self, caller, request, inventory): datasets = [] # collect information from the inventory and registry according to the requests if 'dataset' in request: match_name = request['dataset'] if '*' in match_name: pattern = re.compile(fnmatch.translate(match_name)) for name in inventory.datasets.iterkeys(): if pattern.match(name): datasets.append(inventory.datasets[name]) else: try: datasets.append(inventory.datasets[match_name]) except KeyError: pass response = [] for dataset in datasets: response.append({'name': dataset.name, 'size': dataset.size, 'num_files': dataset.num_files, 'status': Dataset.status_name(dataset.status), 'type': Dataset.data_type_name(dataset.data_type)}) # return any JSONizable python object (maybe should be limited to a list) return response
def customize_stats(categories): categories.categories = collections.OrderedDict([ ('campaign', ('Production campaign', Dataset, campaign_name)), ('data_tier', ('Data tier', Dataset, lambda d: d.name[d.name.rfind('/') + 1:])), ('dataset_status', ('Dataset status', Dataset, lambda d: Dataset.status_name(d.status))), ('dataset', ('Dataset name', Dataset, lambda d: d.name)), ('site', ('Site name', Site, lambda s: s.name)), ('group', ('Group name', Group, lambda g: g.name)) ])
class InventoryStatCategories(object): """ Just a holder for available data categorization. Specify (category_name, (category_title, target, mapping)) where target is either Dataset, Site, or Group and mapping is a function that takes an instance of the target class and returns a value to be used for categorization. Categories can be made specific to the Dynamo instance using _customize.customize_stats. """ categories = collections.OrderedDict([ ('data_type', ('Dataset type', Dataset, lambda d: Dataset.data_type_name(d.data_type))), ('dataset_status', ('Dataset status', Dataset, lambda d: Dataset.status_name(d.status))), ('dataset_software_version', ('Dataset software version', Dataset, lambda d: d.software_version)), ('dataset', ('Dataset name', Dataset, lambda d: d.name)), ('site', ('Site name', Site, lambda s: s.name)), ('site_status', ('Site status', Site, lambda s: Site.status_name(s.status))), ('group', ('Group name', Group, lambda g: g.name)) ])