@@ -62,6 +62,43 @@ def cache_load(url):
62
62
return open (cache_file )
63
63
64
64
65
+ def cached_files ():
66
+ filelist = [ f for f in os .listdir (CACHE_DIR ) if \
67
+ (f .endswith (".xml" ) and os .path .isfile (os .path .join (CACHE_DIR , f )))]
68
+ return filelist
69
+
70
+
71
+ def show_cache ():
72
+ print ("terminology %s \t updated" % (19 * " " ))
73
+ print (60 * "-" )
74
+ files = cached_files ()
75
+ for f in files :
76
+ cache_file = os .path .join (CACHE_DIR , f )
77
+ file_timestamp = datetime .datetime .fromtimestamp (os .path .getmtime (cache_file ))
78
+ disp_name = '_' .join (f .split ('__' )[1 :])
79
+ if len (disp_name ) > 30 :
80
+ disp_name = disp_name [:16 ] + "..."
81
+ if len (disp_name ) < 30 :
82
+ disp_name = disp_name + (30 - len (disp_name )) * " "
83
+ print (" %s \t %s" % (disp_name , file_timestamp ))
84
+
85
+
86
+ def clear_cache ():
87
+ filelist = cached_files ();
88
+ for f in filelist :
89
+ os .remove (os .path .join (CACHE_DIR , f ))
90
+ if os .path .exists (FILE_MAP_FILE ):
91
+ os .remove (FILE_MAP_FILE )
92
+
93
+
94
+ def from_cache (term ):
95
+ file_list = cached_files ();
96
+ file_map = open_file_map ();
97
+ for f in file_map :
98
+ if file_map [f ] not in term :
99
+ term .load (file_map [f ])
100
+
101
+
65
102
class Terminologies (dict ):
66
103
loading = {}
67
104
@@ -110,38 +147,6 @@ def deferred_load(self, url):
110
147
self .loading [url ] = threading .Thread (target = self ._load , args = (url ,))
111
148
self .loading [url ].start ()
112
149
113
- def cached_files (self ):
114
- filelist = [ f for f in os .listdir (CACHE_DIR ) if \
115
- (f .endswith (".xml" ) and os .path .isfile (os .path .join (CACHE_DIR , f )))]
116
- return filelist
117
-
118
- def show_cache (self ):
119
- print ("terminology %s \t updated" % (19 * " " ))
120
- print (60 * "-" )
121
- for f in self .cached_files ():
122
- cache_file = os .path .join (CACHE_DIR , f )
123
- file_timestamp = datetime .datetime .fromtimestamp (os .path .getmtime (cache_file ))
124
- disp_name = '_' .join (f .split ('__' )[1 :])
125
- if len (disp_name ) > 30 :
126
- disp_name = disp_name [:16 ] + "..."
127
- if len (disp_name ) < 30 :
128
- disp_name = disp_name + (30 - len (disp_name )) * " "
129
- print (" %s \t %s" % (disp_name , file_timestamp ))
130
-
131
- def clear_cache (self ):
132
- filelist = self .cached_files ();
133
- for f in filelist :
134
- os .remove (os .path .join (CACHE_DIR , f ))
135
- if os .path .exists (FILE_MAP_FILE ):
136
- os .remove (FILE_MAP_FILE )
137
-
138
- def from_cache (self ):
139
- file_list = self .cached_files ();
140
- file_map = open_file_map ();
141
- for f in file_map :
142
- if file_map [f ] not in self :
143
- self .load (file_map [f ])
144
-
145
150
terminologies = Terminologies ()
146
151
load = terminologies .load
147
152
deferred_load = terminologies .deferred_load
0 commit comments