-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tickets/dm 6459 #17
Tickets/dm 6459 #17
Changes from all commits
bdad6bd
32fc8a9
85cf64a
02d56d4
52d223b
631f247
34246b1
1cfb8af
e70330b
cf4eadd
cc178c2
c7ba1c7
d256cb0
e9770bd
8d9b691
fadbfc8
e268dbe
64a7917
15452cf
515261f
0ef38c7
d989bc8
818c87b
a3a4f44
b17d368
245428c
76a22d6
09a7e99
2fb8145
eabcc23
ba289af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
|
||
from __future__ import with_statement | ||
|
||
from . import DataId | ||
|
||
class ButlerSubset(object): | ||
|
||
"""ButlerSubset is a container for ButlerDataRefs. It represents a | ||
|
@@ -70,11 +72,11 @@ def __init__(self, butler, datasetType, level, dataId): | |
""" | ||
self.butler = butler | ||
self.datasetType = datasetType | ||
self.dataId = dataId | ||
self.dataId = DataId(dataId) | ||
self.cache = [] | ||
self.level = level | ||
|
||
keys = self.butler.getKeys(datasetType, level) | ||
keys = self.butler.getKeys(datasetType, level, tag=dataId.tag) | ||
if keys is None: | ||
return | ||
fmt = list(keys.iterkeys()) | ||
|
@@ -218,11 +220,13 @@ def subLevels(self): | |
|
||
return set( | ||
self.butlerSubset.butler.getKeys( | ||
self.butlerSubset.datasetType).keys() | ||
self.butlerSubset.datasetType, | ||
tag=self.butlerSubset.dataId.tag).keys() | ||
) - set( | ||
self.butlerSubset.butler.getKeys( | ||
self.butlerSubset.datasetType, | ||
self.butlerSubset.level).keys() | ||
self.butlerSubset.level, | ||
tag=self.butlerSubset.dataId.tag).keys() | ||
) | ||
|
||
def subItems(self, level=None): | ||
|
@@ -238,7 +242,10 @@ def subItems(self, level=None): | |
""" | ||
|
||
if level is None: | ||
mappers = self.butlerSubset.butler.repository.mappers() | ||
mappers = [] | ||
for repoData in self.butlerSubset.butler._repos.all(): | ||
if repoData.repo._mapper not in mappers: | ||
mappers.append(repoData.repo._mapper) | ||
if len(mappers) != 1: | ||
raise RuntimeError("Support for multiple repositories not yet implemented!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least this should say "Support for multiple mappers", since this PR is about multiple repositories 😃. It might be possible to use multiple mappers if they all had the same default level. (I'm a little concerned about the "todo" comment below, as well.) |
||
mapper = mappers[0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# LSST Data Management System | ||
# Copyright 2016 LSST Corporation. | ||
# | ||
# This product includes software developed by the | ||
# LSST Project (http://www.lsst.org/). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the LSST License Statement and | ||
# the GNU General Public License along with this program. If not, | ||
# see <http://www.lsstcorp.org/LegalNotices/>. | ||
# | ||
|
||
import copy | ||
import UserDict | ||
|
||
class DataId(UserDict.IterableUserDict): | ||
"""DataId is used to pass scientifically meaningful key-value pairs. It may be tagged as applicable only | ||
to repositories that are tagged with the same value""" | ||
|
||
def __init__(self, initialdata=None, tag=None, **kwargs): | ||
"""Constructor | ||
|
||
Parameters | ||
----------- | ||
initialdata : dict or dataId | ||
A dict of initial data for the DataId | ||
tag : any type, or a container of any type | ||
A value or container of values used to restrict the DataId to one or more repositories that | ||
share that tag value. It will be stored in a set for comparison with the set of tags assigned to | ||
repositories. | ||
kwargs : any values | ||
key-value pairs to be used as part of the DataId's data. | ||
""" | ||
UserDict.UserDict.__init__(self, initialdata) | ||
try: | ||
self.tag = copy.deepcopy(initialdata.tag) | ||
except AttributeError: | ||
self.tag = set() | ||
|
||
if tag is not None: | ||
if isinstance(tag, basestring): | ||
self.tag.update([tag]) | ||
else: | ||
try: | ||
self.tag.update(tag) | ||
except TypeError: | ||
self.tag.update([tag]) | ||
|
||
self.data.update(kwargs) | ||
|
||
def __repr__(self): | ||
return "DataId(initialdata=%s, tag=%s)" %(self.data.__repr__(), self.tag) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,36 @@ def getStringArray(self, key): | |
val = [val] | ||
return val | ||
|
||
def __lt__(self, other): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it really make sense to be doing these types of comparisons on Policies? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it had to do with putting these into a container, these rich comparison methods were needed for that. |
||
if isinstance(other, Policy): | ||
other = other.data | ||
return self.data < other | ||
|
||
def __le__(self, other): | ||
if isinstance(other, Policy): | ||
other = other.data | ||
return self.data <= other | ||
|
||
def __eq__(self, other): | ||
if isinstance(other, Policy): | ||
other = other.data | ||
return self.data == other | ||
|
||
def __ne__(self, other): | ||
if isinstance(other, Policy): | ||
other = other.data | ||
return self.data != other | ||
|
||
def __gt__(self, other): | ||
if isinstance(other, Policy): | ||
other = other.data | ||
return self.data > other | ||
|
||
def __ge__(self, other): | ||
if isinstance(other, Policy): | ||
other = other.data | ||
return self.data >= other | ||
|
||
####### | ||
# i/o # | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this class at all? I think all the places that use it can be converted to just the
Butler()
constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that but it'll touch maybe a dozen packages, and I think it would be more manageable to do it as part of a separate ticket.