Skip to content

Commit 0583a6a

Browse files
committed
[terminology] extract method for getting cached files list
1 parent c986655 commit 0583a6a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

odml/terminology.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ def deferred_load(self, url):
109109
self.loading[url] = threading.Thread(target=self._load, args=(url,))
110110
self.loading[url].start()
111111

112+
def cached_files(self):
113+
filelist = [ f for f in os.listdir(CACHE_DIR) if \
114+
(f.endswith(".xml") and os.path.isfile(os.path.join(CACHE_DIR, f)))]
115+
return filelist
116+
112117
def show_cache(self):
113-
cache_dir = os.path.join(tempfile.gettempdir(), "odml.cache")
114-
onlyfiles = [f for f in os.listdir(cache_dir) if os.path.isfile(os.path.join(cache_dir, f))]
115118
print("terminology %s \t updated"%(19*" "))
116119
print(60*"-")
117-
for f in onlyfiles:
118-
cache_file = os.path.join(cache_dir, f)
120+
for f in self.cached_files():
121+
cache_file = os.path.join(CACHE_DIR, f)
119122
file_timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(cache_file))
120123
disp_name = '_'.join(f.split('__')[1:])
121124
if len(disp_name) > 30:
@@ -125,11 +128,11 @@ def show_cache(self):
125128
print(" %s \t %s"%(disp_name, file_timestamp))
126129

127130
def clear_cache(self):
128-
cache_dir = os.path.join(tempfile.gettempdir(), "odml.cache")
129-
filelist = [ f for f in os.listdir(cache_dir) if f.endswith(".xml") ]
131+
filelist = self.cached_files();
130132
for f in filelist:
131-
os.remove(os.path.join(cache_dir, f))
132-
133+
os.remove(os.path.join(CACHE_DIR, f))
134+
if os.path.exists(FILE_MAP_FILE):
135+
os.remove(FILE_MAP_FILE)
133136

134137
terminologies = Terminologies()
135138
load = terminologies.load

0 commit comments

Comments
 (0)