annotate tripal.py @ 0:5ce8ae1288c1 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:51:14 -0400
parents
children 16acaa0aa58c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
4
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
6
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
8
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
9
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
10 #############################################
5ce8ae1288c1 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 #
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
12 #############################################
5ce8ae1288c1 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 #
5ce8ae1288c1 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 #
5ce8ae1288c1 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. #
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
16 # e27332bc82f4e327aedaec17c9b656ae719322ed #
5ce8ae1288c1 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/ #
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
18 #############################################
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
20
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
21 __slots__ = ()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
22
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
23 @abstractmethod
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
26
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
27 @abstractmethod
5ce8ae1288c1 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
5ce8ae1288c1 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__'):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
31 else:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
33
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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]
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
37 else:
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
39
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
41
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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]
5ce8ae1288c1 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]
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
48 else:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
51
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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]
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
55 else:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
58
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
59
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
61
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
62
5ce8ae1288c1 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):
5ce8ae1288c1 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, _):
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
66
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
69
5ce8ae1288c1 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, _):
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
72
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
73
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
76
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
78
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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()
5ce8ae1288c1 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()
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
88
5ce8ae1288c1 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):
5ce8ae1288c1 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)' % (
5ce8ae1288c1 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__,
5ce8ae1288c1 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()),
5ce8ae1288c1 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,
5ce8ae1288c1 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,
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
95 )
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
96
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
98 try:
5ce8ae1288c1 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]
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
102
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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)
5ce8ae1288c1 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:
5ce8ae1288c1 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')
5ce8ae1288c1 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:
5ce8ae1288c1 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:
5ce8ae1288c1 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()
5ce8ae1288c1 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:
5ce8ae1288c1 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]
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
113 else:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
118
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 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]
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
123
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
126
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
129 try:
5ce8ae1288c1 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)
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
134
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
137
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
140
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
141 @staticmethod
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
144
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
145 @staticmethod
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
148
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
149 @property
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
153
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
154 @property
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
158
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
162
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
163
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
165
5ce8ae1288c1 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')
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
167
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
171
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
174
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
180
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
181
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
183
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
187
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
191 else:
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
193
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
197 else:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
201
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
204
5ce8ae1288c1 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):
5ce8ae1288c1 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,)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
207
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
210
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
211
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
214
5ce8ae1288c1 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,
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 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()
5ce8ae1288c1 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
5ce8ae1288c1 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()
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
223
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
225 try:
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
229 else:
5ce8ae1288c1 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())
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
231
5ce8ae1288c1 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__):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
233 try:
5ce8ae1288c1 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)
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
237 else:
5ce8ae1288c1 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()
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
241 else:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
243
5ce8ae1288c1 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__):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
248 try:
5ce8ae1288c1 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)
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
252 else:
5ce8ae1288c1 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()
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
258
5ce8ae1288c1 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__):
5ce8ae1288c1 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)
5ce8ae1288c1 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)
5ce8ae1288c1 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()
5ce8ae1288c1 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():
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
265
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
275
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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()
5ce8ae1288c1 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)
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
285
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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())
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
295
5ce8ae1288c1 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__):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
300
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
301 @property
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
306
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
307 @property
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
311
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
312 @property
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
316
5ce8ae1288c1 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):
5ce8ae1288c1 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."""
5ce8ae1288c1 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:
5ce8ae1288c1 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()
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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__
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 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]
5ce8ae1288c1 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
5ce8ae1288c1 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()
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
331
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
336
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
340
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
344
5ce8ae1288c1 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):
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
348
5ce8ae1288c1 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):
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
352
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
353 """
5ce8ae1288c1 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:
5ce8ae1288c1 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)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
356 try:
5ce8ae1288c1 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))
5ce8ae1288c1 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:
5ce8ae1288c1 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__)
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
360 else:
5ce8ae1288c1 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))
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
362
5ce8ae1288c1 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'):
5ce8ae1288c1 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):
5ce8ae1288c1 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]
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
368 else:
5ce8ae1288c1 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):
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
373
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
374
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
375 #############################################
5ce8ae1288c1 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 #
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
377 #############################################
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
378
5ce8ae1288c1 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(
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
382 )
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
383
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
384
5ce8ae1288c1 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():
5ce8ae1288c1 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(
5ce8ae1288c1 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'],
5ce8ae1288c1 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'],
5ce8ae1288c1 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']
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
390 )
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
391
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
392
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
394
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
396
5ce8ae1288c1 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
5ce8ae1288c1 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'
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
403 # there.
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
407 try:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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]
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
420
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
421
5ce8ae1288c1 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):
5ce8ae1288c1 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.
5ce8ae1288c1 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 = []
5ce8ae1288c1 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():
5ce8ae1288c1 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'])
5ce8ae1288c1 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']:
5ce8ae1288c1 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'])
5ce8ae1288c1 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))
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
431
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
432
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
434
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
436
5ce8ae1288c1 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
5ce8ae1288c1 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'
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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"?>
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
444
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
448 try:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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]
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
461
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
462
5ce8ae1288c1 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):
5ce8ae1288c1 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 = []
5ce8ae1288c1 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():
5ce8ae1288c1 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))
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
468
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
469
5ce8ae1288c1 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):
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
471
5ce8ae1288c1 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()
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
473
5ce8ae1288c1 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
5ce8ae1288c1 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'
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
480 # there.
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
484 try:
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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]
5ce8ae1288c1 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
5ce8ae1288c1 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:
5ce8ae1288c1 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
5ce8ae1288c1 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.
5ce8ae1288c1 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)
5ce8ae1288c1 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
5ce8ae1288c1 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
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
497
5ce8ae1288c1 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/tripal commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
498
5ce8ae1288c1 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):
5ce8ae1288c1 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 = []
5ce8ae1288c1 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():
5ce8ae1288c1 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))
5ce8ae1288c1 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