File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,29 @@ def cache_load(url):
5858 return open (cache_file )
5959
6060
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+
6184class Terminologies (dict ):
6285 """
6386 Terminologies facilitates synchronous and deferred loading, caching,
You can’t perform that action at this time.
0 commit comments