Skip to content

Commit

Permalink
Merge pull request SciLifeLab#213 from Galithil/master
Browse files Browse the repository at this point in the history
Update queues
  • Loading branch information
senthil10 authored Mar 28, 2018
2 parents b52a674 + eb0f850 commit 4da79fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
29 changes: 28 additions & 1 deletion genologics/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,35 @@ def __get__(self, instance, cls):
rootnode = rootnode.find(rootkey)
for node in rootnode.findall(self.tag):
result.append(self.klass(instance.lims, uri=node.attrib['uri']))

return result

class MultiPageNestedEntityListDescriptor(EntityListDescriptor):
"""same as NestedEntityListDescriptor, but works on multiple pages, for Queues"""

def __init__(self, tag, klass, *args):
super(EntityListDescriptor, self).__init__(tag, klass)
self.klass = klass
self.tag = tag
self.rootkeys = args
self.max_depth = 10

def __get__(self, instance, cls):
instance.get()
result = []
rootnode = instance.root
for rootkey in self.rootkeys:
rootnode = rootnode.find(rootkey)
for node in rootnode.findall(self.tag):
result.append(self.klass(instance.lims, uri=node.attrib['uri']))

if instance.root.find('next-page') is not None:
next_queue_page = instance.__class__(instance.lims, uri=instance.root.find('next-page').attrib.get('uri'))
result.extend(next_queue_page.artifacts)
return result



class DimensionDescriptor(TagDescriptor):
"""An instance attribute containing a dictionary specifying
the properties of a dimension of a container type.
Expand All @@ -544,7 +570,8 @@ def __get__(self, instance, cls):
node = instance.root.find(self.tag)
return dict(is_alpha=node.find('is-alpha').text.lower() == 'true',
offset=int(node.find('offset').text),
size=int(node.find('size').text))
size=int(node.find('size').text)
)


class LocationDescriptor(TagDescriptor):
Expand Down
7 changes: 4 additions & 3 deletions genologics/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
StringAttributeDescriptor, StringListDescriptor, DimensionDescriptor, IntegerDescriptor, \
PlacementDictionaryDescriptor, InputOutputMapList, LocationDescriptor, ReagentLabelList, NestedEntityListDescriptor, \
NestedStringListDescriptor, NestedAttributeListDescriptor, IntegerAttributeDescriptor, NestedStringDescriptor, \
NestedBooleanDescriptor
NestedBooleanDescriptor, MultiPageNestedEntityListDescriptor

try:
from urllib.parse import urlsplit, urlparse, parse_qs, urlunparse
Expand Down Expand Up @@ -1080,12 +1080,13 @@ def __init__(self, lims, uri=None, id=None):


class Queue(Entity):
"""Queue of a given step"""
"""Queue of a given step. Will recursively get all the pages of artifacts, and therefore, can be quite slow to load"""
_URI = "queues"
_TAG= "queue"
_PREFIX = "que"

artifacts=NestedEntityListDescriptor("artifact", Artifact, "artifacts")

artifacts = MultiPageNestedEntityListDescriptor("artifact", Artifact, "artifacts")

Sample.artifact = EntityDescriptor('artifact', Artifact)
StepActions.step = EntityDescriptor('step', Step)
Expand Down
2 changes: 1 addition & 1 deletion genologics/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.3.21"
__version__="0.3.22"

0 comments on commit 4da79fd

Please sign in to comment.