File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,29 @@ def cache_load(url):
58
58
return open (cache_file )
59
59
60
60
61
+ def refresh (url ):
62
+ """
63
+ Deletes the current odML terminology file from cache and reloads
64
+ it from the given URL.
65
+
66
+ :param url: URL from where to load an odML terminology file from.
67
+ """
68
+ filename = '.' .join ([md5 (url .encode ()).hexdigest (), os .path .basename (url )])
69
+ cache_dir = os .path .join (tempfile .gettempdir (), "odml.cache" )
70
+ cache_file = os .path .join (cache_dir , filename )
71
+ try :
72
+ urllib2 .urlopen (url ).read ()
73
+ except Exception as exc :
74
+ print ('Cache for file "%s" could not be refreshed. Failed loading "%s": %s'
75
+ % (filename , url , exc ))
76
+ return
77
+
78
+ if os .path .exists (cache_file ):
79
+ os .remove (cache_file )
80
+
81
+ cache_load (url )
82
+
83
+
61
84
class Terminologies (dict ):
62
85
"""
63
86
Terminologies facilitates synchronous and deferred loading, caching,
You can’t perform that action at this time.
0 commit comments