28
28
29
29
30
30
def open_file_map ():
31
+ """
32
+ Opens the file_map file stored in the cache that maps the filenames to the urls of the
33
+ respective terminolgies.
34
+ """
31
35
file_map = {}
32
36
if not os .path .exists (FILE_MAP_FILE ):
33
37
return file_map
@@ -41,7 +45,7 @@ def open_file_map():
41
45
42
46
def cache_load (url ):
43
47
"""
44
- load the url and store it in a temporary cache directory
48
+ Load the url and store it in a temporary cache directory
45
49
subsequent requests for this url will use the cached version
46
50
"""
47
51
filename = md5 (url .encode ()).hexdigest () + '__' + os .path .basename (url )
@@ -64,12 +68,18 @@ def cache_load(url):
64
68
65
69
66
70
def cached_files ():
71
+ """
72
+ Returns a list of all locally cached files.
73
+ """
67
74
filelist = [ f for f in os .listdir (CACHE_DIR ) if \
68
75
(f .endswith (".xml" ) and os .path .isfile (os .path .join (CACHE_DIR , f )))]
69
76
return filelist
70
77
71
78
72
79
def show_cache ():
80
+ """
81
+ Show all locally cached files. Just for display.
82
+ """
73
83
print ("terminology %s \t updated" % (19 * " " ))
74
84
print (60 * "-" )
75
85
files = cached_files ()
@@ -85,6 +95,9 @@ def show_cache():
85
95
86
96
87
97
def clear_cache ():
98
+ """
99
+ Clears the cache, i.e. deletes all locally stored files. Does not remove the cache folder, though.
100
+ """
88
101
filelist = cached_files ();
89
102
for f in filelist :
90
103
os .remove (os .path .join (CACHE_DIR , f ))
@@ -93,6 +106,10 @@ def clear_cache():
93
106
94
107
95
108
def from_cache (term ):
109
+ """
110
+ Fills the terminology with the definitions stored in the cache.
111
+ """
112
+ assert isinstance (term , Terminologies )
96
113
file_list = cached_files ();
97
114
file_map = open_file_map ();
98
115
for f in file_map :
@@ -150,9 +167,15 @@ def deferred_load(self, url):
150
167
self .loading [url ].start ()
151
168
152
169
def empty (self ):
170
+ """
171
+ Tells whether there are no terminolgies stored.
172
+ """
153
173
return len (self ) == 0
154
174
155
175
def type_list (self ):
176
+ """
177
+ returns a dict of all types stored in the cache together with the terminologies it is defined in.
178
+ """
156
179
if self .empty ():
157
180
from_cache (self )
158
181
if not self .types :
@@ -240,7 +263,7 @@ def get_section_by_type(section_type, pattern=None, relaxed=False):
240
263
if __name__ == "__main__" :
241
264
from IPython import embed
242
265
print ("Terminologies!" )
266
+ # from_cache(terminologies)
243
267
# t.load('http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml')
244
- embed ()
245
268
# t.load('http://portal.g-node.org/odml/terminologies/v1.0/analysis/power_spectrum.xml')
246
-
269
+ embed ()
0 commit comments