Mercurial > repos > gga > tripal_analysis_load_fasta
annotate tripal.py @ 0:ca1eb54c95d6 draft
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
| author | gga | 
|---|---|
| date | Mon, 11 Sep 2017 05:50:45 -0400 | 
| parents | |
| children | 0fbe72b81b9e | 
| rev | line source | 
|---|---|
| 0 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 1 import collections | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 2 import os | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 3 import time | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 4 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 5 from abc import abstractmethod | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 6 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 7 import tripal | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 8 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 9 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 10 ############################################# | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 11 # BEGIN IMPORT OF CACHING LIBRARY # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 12 ############################################# | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 13 # This code is licensed under the MIT # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 14 # License and is a copy of code publicly # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 15 # available in rev. # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 16 # e27332bc82f4e327aedaec17c9b656ae719322ed # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 17 # of https://github.com/tkem/cachetools/ # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 18 ############################################# | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 19 class DefaultMapping(collections.MutableMapping): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 20 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 21 __slots__ = () | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 22 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 23 @abstractmethod | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 24 def __contains__(self, key): # pragma: nocover | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 25 return False | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 26 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 27 @abstractmethod | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 28 def __getitem__(self, key): # pragma: nocover | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 29 if hasattr(self.__class__, '__missing__'): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 30 return self.__class__.__missing__(self, key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 31 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 32 raise KeyError(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 33 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 34 def get(self, key, default=None): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 35 if key in self: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 36 return self[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 37 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 38 return default | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 39 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 40 __marker = object() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 41 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 42 def pop(self, key, default=__marker): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 43 if key in self: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 44 value = self[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 45 del self[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 46 elif default is self.__marker: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 47 raise KeyError(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 48 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 49 value = default | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 50 return value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 51 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 52 def setdefault(self, key, default=None): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 53 if key in self: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 54 value = self[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 55 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 56 self[key] = value = default | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 57 return value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 58 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 59 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 60 DefaultMapping.register(dict) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 61 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 62 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 63 class _DefaultSize(object): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 64 def __getitem__(self, _): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 65 return 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 66 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 67 def __setitem__(self, _, value): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 68 assert value == 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 69 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 70 def pop(self, _): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 71 return 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 72 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 73 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 74 class Cache(DefaultMapping): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 75 """Mutable mapping to serve as a simple cache or cache base class.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 76 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 77 __size = _DefaultSize() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 78 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 79 def __init__(self, maxsize, missing=None, getsizeof=None): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 80 if missing: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 81 self.__missing = missing | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 82 if getsizeof: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 83 self.__getsizeof = getsizeof | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 84 self.__size = dict() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 85 self.__data = dict() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 86 self.__currsize = 0 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 87 self.__maxsize = maxsize | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 88 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 89 def __repr__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 90 return '%s(%r, maxsize=%r, currsize=%r)' % ( | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 91 self.__class__.__name__, | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 92 list(self.__data.items()), | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 93 self.__maxsize, | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 94 self.__currsize, | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 95 ) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 96 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 97 def __getitem__(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 98 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 99 return self.__data[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 100 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 101 return self.__missing__(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 102 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 103 def __setitem__(self, key, value): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 104 maxsize = self.__maxsize | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 105 size = self.getsizeof(value) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 106 if size > maxsize: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 107 raise ValueError('value too large') | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 108 if key not in self.__data or self.__size[key] < size: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 109 while self.__currsize + size > maxsize: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 110 self.popitem() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 111 if key in self.__data: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 112 diffsize = size - self.__size[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 113 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 114 diffsize = size | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 115 self.__data[key] = value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 116 self.__size[key] = size | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 117 self.__currsize += diffsize | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 118 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 119 def __delitem__(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 120 size = self.__size.pop(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 121 del self.__data[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 122 self.__currsize -= size | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 123 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 124 def __contains__(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 125 return key in self.__data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 126 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 127 def __missing__(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 128 value = self.__missing(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 129 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 130 self.__setitem__(key, value) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 131 except ValueError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 132 pass # value too large | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 133 return value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 134 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 135 def __iter__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 136 return iter(self.__data) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 137 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 138 def __len__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 139 return len(self.__data) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 140 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 141 @staticmethod | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 142 def __getsizeof(value): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 143 return 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 144 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 145 @staticmethod | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 146 def __missing(key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 147 raise KeyError(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 148 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 149 @property | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 150 def maxsize(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 151 """The maximum size of the cache.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 152 return self.__maxsize | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 153 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 154 @property | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 155 def currsize(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 156 """The current size of the cache.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 157 return self.__currsize | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 158 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 159 def getsizeof(self, value): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 160 """Return the size of a cache element's value.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 161 return self.__getsizeof(value) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 162 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 163 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 164 class _Link(object): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 165 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 166 __slots__ = ('key', 'expire', 'next', 'prev') | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 167 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 168 def __init__(self, key=None, expire=None): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 169 self.key = key | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 170 self.expire = expire | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 171 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 172 def __reduce__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 173 return _Link, (self.key, self.expire) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 174 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 175 def unlink(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 176 next = self.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 177 prev = self.prev | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 178 prev.next = next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 179 next.prev = prev | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 180 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 181 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 182 class _Timer(object): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 183 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 184 def __init__(self, timer): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 185 self.__timer = timer | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 186 self.__nesting = 0 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 187 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 188 def __call__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 189 if self.__nesting == 0: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 190 return self.__timer() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 191 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 192 return self.__time | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 193 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 194 def __enter__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 195 if self.__nesting == 0: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 196 self.__time = time = self.__timer() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 197 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 198 time = self.__time | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 199 self.__nesting += 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 200 return time | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 201 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 202 def __exit__(self, *exc): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 203 self.__nesting -= 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 204 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 205 def __reduce__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 206 return _Timer, (self.__timer,) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 207 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 208 def __getattr__(self, name): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 209 return getattr(self.__timer, name) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 210 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 211 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 212 class TTLCache(Cache): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 213 """LRU Cache implementation with per-item time-to-live (TTL) value.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 214 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 215 def __init__(self, maxsize, ttl, timer=time.time, missing=None, | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 216 getsizeof=None): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 217 Cache.__init__(self, maxsize, missing, getsizeof) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 218 self.__root = root = _Link() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 219 root.prev = root.next = root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 220 self.__links = collections.OrderedDict() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 221 self.__timer = _Timer(timer) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 222 self.__ttl = ttl | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 223 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 224 def __contains__(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 225 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 226 link = self.__links[key] # no reordering | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 227 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 228 return False | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 229 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 230 return not (link.expire < self.__timer()) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 231 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 232 def __getitem__(self, key, cache_getitem=Cache.__getitem__): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 233 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 234 link = self.__getlink(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 235 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 236 expired = False | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 237 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 238 expired = link.expire < self.__timer() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 239 if expired: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 240 return self.__missing__(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 241 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 242 return cache_getitem(self, key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 243 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 244 def __setitem__(self, key, value, cache_setitem=Cache.__setitem__): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 245 with self.__timer as time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 246 self.expire(time) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 247 cache_setitem(self, key, value) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 248 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 249 link = self.__getlink(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 250 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 251 self.__links[key] = link = _Link(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 252 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 253 link.unlink() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 254 link.expire = time + self.__ttl | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 255 link.next = root = self.__root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 256 link.prev = prev = root.prev | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 257 prev.next = root.prev = link | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 258 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 259 def __delitem__(self, key, cache_delitem=Cache.__delitem__): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 260 cache_delitem(self, key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 261 link = self.__links.pop(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 262 link.unlink() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 263 if link.expire < self.__timer(): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 264 raise KeyError(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 265 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 266 def __iter__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 267 root = self.__root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 268 curr = root.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 269 while curr is not root: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 270 # "freeze" time for iterator access | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 271 with self.__timer as time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 272 if not (curr.expire < time): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 273 yield curr.key | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 274 curr = curr.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 275 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 276 def __len__(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 277 root = self.__root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 278 curr = root.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 279 time = self.__timer() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 280 count = len(self.__links) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 281 while curr is not root and curr.expire < time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 282 count -= 1 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 283 curr = curr.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 284 return count | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 285 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 286 def __setstate__(self, state): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 287 self.__dict__.update(state) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 288 root = self.__root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 289 root.prev = root.next = root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 290 for link in sorted(self.__links.values(), key=lambda obj: obj.expire): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 291 link.next = root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 292 link.prev = prev = root.prev | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 293 prev.next = root.prev = link | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 294 self.expire(self.__timer()) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 295 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 296 def __repr__(self, cache_repr=Cache.__repr__): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 297 with self.__timer as time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 298 self.expire(time) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 299 return cache_repr(self) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 300 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 301 @property | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 302 def currsize(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 303 with self.__timer as time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 304 self.expire(time) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 305 return super(TTLCache, self).currsize | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 306 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 307 @property | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 308 def timer(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 309 """The timer function used by the cache.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 310 return self.__timer | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 311 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 312 @property | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 313 def ttl(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 314 """The time-to-live value of the cache's items.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 315 return self.__ttl | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 316 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 317 def expire(self, time=None): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 318 """Remove expired items from the cache.""" | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 319 if time is None: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 320 time = self.__timer() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 321 root = self.__root | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 322 curr = root.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 323 links = self.__links | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 324 cache_delitem = Cache.__delitem__ | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 325 while curr is not root and curr.expire < time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 326 cache_delitem(self, curr.key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 327 del links[curr.key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 328 next = curr.next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 329 curr.unlink() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 330 curr = next | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 331 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 332 def clear(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 333 with self.__timer as time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 334 self.expire(time) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 335 Cache.clear(self) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 336 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 337 def get(self, *args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 338 with self.__timer: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 339 return Cache.get(self, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 340 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 341 def pop(self, *args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 342 with self.__timer: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 343 return Cache.pop(self, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 344 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 345 def setdefault(self, *args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 346 with self.__timer: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 347 return Cache.setdefault(self, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 348 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 349 def popitem(self): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 350 """Remove and return the `(key, value)` pair least recently used that | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 351 has not already expired. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 352 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 353 """ | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 354 with self.__timer as time: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 355 self.expire(time) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 356 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 357 key = next(iter(self.__links)) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 358 except StopIteration: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 359 raise KeyError('%s is empty' % self.__class__.__name__) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 360 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 361 return (key, self.pop(key)) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 362 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 363 if hasattr(collections.OrderedDict, 'move_to_end'): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 364 def __getlink(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 365 value = self.__links[key] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 366 self.__links.move_to_end(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 367 return value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 368 else: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 369 def __getlink(self, key): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 370 value = self.__links.pop(key) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 371 self.__links[key] = value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 372 return value | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 373 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 374 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 375 ############################################# | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 376 # END IMPORT OF CACHING LIBRARY # | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 377 ############################################# | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 378 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 379 cache = TTLCache( | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 380 100, # Up to 100 items | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 381 1 * 60 # 5 minute cache life | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 382 ) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 383 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 384 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 385 def _get_instance(): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 386 return tripal.TripalInstance( | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 387 os.environ['GALAXY_TRIPAL_URL'], | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 388 os.environ['GALAXY_TRIPAL_USER'], | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 389 os.environ['GALAXY_TRIPAL_PASSWORD'] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 390 ) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 391 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 392 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 393 def list_organisms(*args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 394 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 395 ti = _get_instance() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 396 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 397 # Key for cached data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 398 cacheKey = 'orgs' | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 399 # We don't want to trust "if key in cache" because between asking and fetch | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 400 # it might through key error. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 401 if cacheKey not in cache: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 402 # However if it ISN'T there, we know we're safe to fetch + put in | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 403 # there. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 404 data = _list_organisms(ti, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 405 cache[cacheKey] = data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 406 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 407 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 408 # The cache key may or may not be in the cache at this point, it | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 409 # /likely/ is. However we take no chances that it wasn't evicted between | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 410 # when we checked above and now, so we reference the object from the | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 411 # cache in preparation to return. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 412 data = cache[cacheKey] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 413 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 414 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 415 # If access fails due to eviction, we will fail over and can ensure that | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 416 # data is inserted. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 417 data = _list_organisms(ti, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 418 cache[cacheKey] = data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 419 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 420 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 421 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 422 def _list_organisms(ti, *args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 423 # Fetch the orgs. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 424 orgs_data = [] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 425 for org in ti.organism.get_organisms(): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 426 clean_name = '%s %s' % (org['genus'], org['species']) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 427 if org['infraspecific_name']: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 428 clean_name += ' (%s)' % (org['infraspecific_name']) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 429 orgs_data.append((clean_name, org['organism_id'], False)) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 430 return orgs_data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 431 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 432 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 433 def list_analyses(*args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 434 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 435 ti = _get_instance() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 436 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 437 # Key for cached data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 438 cacheKey = 'analyses' | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 439 # We don't want to trust "if key in cache" because between asking and fetch | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 440 # it might through key error. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 441 if cacheKey not in cache: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 442 # However if it ISN'T there, we know we're safe to fetch + put in | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 443 # there.<?xml version="1.0"?> | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 444 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 445 data = _list_analyses(ti, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 446 cache[cacheKey] = data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 447 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 448 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 449 # The cache key may or may not be in the cache at this point, it | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 450 # /likely/ is. However we take no chances that it wasn't evicted between | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 451 # when we checked above and now, so we reference the object from the | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 452 # cache in preparation to return. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 453 data = cache[cacheKey] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 454 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 455 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 456 # If access fails due to eviction, we will fail over and can ensure that | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 457 # data is inserted. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 458 data = _list_analyses(ti, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 459 cache[cacheKey] = data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 460 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 461 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 462 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 463 def _list_analyses(ti, *args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 464 ans_data = [] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 465 for an in ti.analysis.get_analyses(): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 466 ans_data.append((an['name'], an['analysis_id'], False)) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 467 return ans_data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 468 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 469 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 470 def list_blastdbs(*args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 471 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 472 ti = _get_instance() | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 473 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 474 # Key for cached data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 475 cacheKey = 'blastdbs' | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 476 # We don't want to trust "if key in cache" because between asking and fetch | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 477 # it might through key error. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 478 if cacheKey not in cache: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 479 # However if it ISN'T there, we know we're safe to fetch + put in | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 480 # there. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 481 data = _list_blastdbs(ti, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 482 cache[cacheKey] = data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 483 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 484 try: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 485 # The cache key may or may not be in the cache at this point, it | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 486 # /likely/ is. However we take no chances that it wasn't evicted between | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 487 # when we checked above and now, so we reference the object from the | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 488 # cache in preparation to return. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 489 data = cache[cacheKey] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 490 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 491 except KeyError: | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 492 # If access fails due to eviction, we will fail over and can ensure that | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 493 # data is inserted. | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 494 data = _list_blastdbs(ti, *args, **kwargs) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 495 cache[cacheKey] = data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 496 return data | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 497 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 498 | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 499 def _list_blastdbs(ti, *args, **kwargs): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 500 dbs_data = [] | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 501 for db in ti.db.get_dbs(): | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 502 dbs_data.append((db['name'], db['db_id'], False)) | 
| 
ca1eb54c95d6
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
 gga parents: diff
changeset | 503 return dbs_data | 
