1 |
Author: zmedico |
2 |
Date: 2010-02-25 05:15:09 +0000 (Thu, 25 Feb 2010) |
3 |
New Revision: 15450 |
4 |
|
5 |
Added: |
6 |
main/trunk/pym/portage/util/listdir.py |
7 |
Modified: |
8 |
main/trunk/pym/portage/__init__.py |
9 |
main/trunk/pym/portage/dbapi/bintree.py |
10 |
main/trunk/pym/portage/dbapi/porttree.py |
11 |
main/trunk/pym/portage/dbapi/vartree.py |
12 |
main/trunk/pym/portage/util/digraph.py |
13 |
Log: |
14 |
Move cacheddir and listdir to portage.util.listdir. |
15 |
|
16 |
|
17 |
Modified: main/trunk/pym/portage/__init__.py |
18 |
=================================================================== |
19 |
--- main/trunk/pym/portage/__init__.py 2010-02-25 04:32:14 UTC (rev 15449) |
20 |
+++ main/trunk/pym/portage/__init__.py 2010-02-25 05:15:09 UTC (rev 15450) |
21 |
@@ -122,6 +122,7 @@ |
22 |
'stack_lists,unique_array,varexpand,writedict,writemsg,' + \ |
23 |
'writemsg_stdout,write_atomic', |
24 |
'portage.util.digraph:digraph', |
25 |
+ 'portage.util.listdir:cacheddir,listdir', |
26 |
'portage.versions', |
27 |
'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,' + \ |
28 |
'cpv_getkey@getCPFromCPV,endversion_keys,' + \ |
29 |
@@ -533,145 +534,6 @@ |
30 |
mylink=mydir+"/"+mylink |
31 |
return os.path.normpath(mylink) |
32 |
|
33 |
-dircache = {} |
34 |
-cacheHit=0 |
35 |
-cacheMiss=0 |
36 |
-cacheStale=0 |
37 |
-def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True): |
38 |
- global cacheHit,cacheMiss,cacheStale |
39 |
- mypath = normalize_path(my_original_path) |
40 |
- if mypath in dircache: |
41 |
- cacheHit += 1 |
42 |
- cached_mtime, list, ftype = dircache[mypath] |
43 |
- else: |
44 |
- cacheMiss += 1 |
45 |
- cached_mtime, list, ftype = -1, [], [] |
46 |
- try: |
47 |
- pathstat = os.stat(mypath) |
48 |
- if stat.S_ISDIR(pathstat[stat.ST_MODE]): |
49 |
- mtime = pathstat.st_mtime |
50 |
- else: |
51 |
- raise portage.exception.DirectoryNotFound(mypath) |
52 |
- except EnvironmentError as e: |
53 |
- if e.errno == portage.exception.PermissionDenied.errno: |
54 |
- raise portage.exception.PermissionDenied(mypath) |
55 |
- del e |
56 |
- return [], [] |
57 |
- except portage.exception.PortageException: |
58 |
- return [], [] |
59 |
- # Python retuns mtime in seconds, so if it was changed in the last few seconds, it could be invalid |
60 |
- if mtime != cached_mtime or time.time() - mtime < 4: |
61 |
- if mypath in dircache: |
62 |
- cacheStale += 1 |
63 |
- try: |
64 |
- list = os.listdir(mypath) |
65 |
- except EnvironmentError as e: |
66 |
- if e.errno != errno.EACCES: |
67 |
- raise |
68 |
- del e |
69 |
- raise portage.exception.PermissionDenied(mypath) |
70 |
- ftype = [] |
71 |
- for x in list: |
72 |
- try: |
73 |
- if followSymlinks: |
74 |
- pathstat = os.stat(mypath+"/"+x) |
75 |
- else: |
76 |
- pathstat = os.lstat(mypath+"/"+x) |
77 |
- |
78 |
- if stat.S_ISREG(pathstat[stat.ST_MODE]): |
79 |
- ftype.append(0) |
80 |
- elif stat.S_ISDIR(pathstat[stat.ST_MODE]): |
81 |
- ftype.append(1) |
82 |
- elif stat.S_ISLNK(pathstat[stat.ST_MODE]): |
83 |
- ftype.append(2) |
84 |
- else: |
85 |
- ftype.append(3) |
86 |
- except (IOError, OSError): |
87 |
- ftype.append(3) |
88 |
- dircache[mypath] = mtime, list, ftype |
89 |
- |
90 |
- ret_list = [] |
91 |
- ret_ftype = [] |
92 |
- for x in range(0, len(list)): |
93 |
- if list[x] in ignorelist: |
94 |
- pass |
95 |
- elif ignorecvs: |
96 |
- if list[x][:2] != ".#": |
97 |
- ret_list.append(list[x]) |
98 |
- ret_ftype.append(ftype[x]) |
99 |
- else: |
100 |
- ret_list.append(list[x]) |
101 |
- ret_ftype.append(ftype[x]) |
102 |
- |
103 |
- writemsg("cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale),10) |
104 |
- return ret_list, ret_ftype |
105 |
- |
106 |
-_ignorecvs_dirs = ('CVS', 'SCCS', '.svn', '.git') |
107 |
- |
108 |
-def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelist=[], followSymlinks=True, |
109 |
- EmptyOnError=False, dirsonly=False): |
110 |
- """ |
111 |
- Portage-specific implementation of os.listdir |
112 |
- |
113 |
- @param mypath: Path whose contents you wish to list |
114 |
- @type mypath: String |
115 |
- @param recursive: Recursively scan directories contained within mypath |
116 |
- @type recursive: Boolean |
117 |
- @param filesonly; Only return files, not more directories |
118 |
- @type filesonly: Boolean |
119 |
- @param ignorecvs: Ignore CVS directories ('CVS','SCCS','.svn','.git') |
120 |
- @type ignorecvs: Boolean |
121 |
- @param ignorelist: List of filenames/directories to exclude |
122 |
- @type ignorelist: List |
123 |
- @param followSymlinks: Follow Symlink'd files and directories |
124 |
- @type followSymlinks: Boolean |
125 |
- @param EmptyOnError: Return [] if an error occurs (deprecated, always True) |
126 |
- @type EmptyOnError: Boolean |
127 |
- @param dirsonly: Only return directories. |
128 |
- @type dirsonly: Boolean |
129 |
- @rtype: List |
130 |
- @returns: A list of files and directories (or just files or just directories) or an empty list. |
131 |
- """ |
132 |
- |
133 |
- list, ftype = cacheddir(mypath, ignorecvs, ignorelist, EmptyOnError, followSymlinks) |
134 |
- |
135 |
- if list is None: |
136 |
- list=[] |
137 |
- if ftype is None: |
138 |
- ftype=[] |
139 |
- |
140 |
- if not (filesonly or dirsonly or recursive): |
141 |
- return list |
142 |
- |
143 |
- if recursive: |
144 |
- x=0 |
145 |
- while x<len(ftype): |
146 |
- if ftype[x] == 1 and not \ |
147 |
- (ignorecvs and os.path.basename(list[x]) in _ignorecvs_dirs): |
148 |
- l,f = cacheddir(mypath+"/"+list[x], ignorecvs, ignorelist, EmptyOnError, |
149 |
- followSymlinks) |
150 |
- |
151 |
- l=l[:] |
152 |
- for y in range(0,len(l)): |
153 |
- l[y]=list[x]+"/"+l[y] |
154 |
- list=list+l |
155 |
- ftype=ftype+f |
156 |
- x+=1 |
157 |
- if filesonly: |
158 |
- rlist=[] |
159 |
- for x in range(0,len(ftype)): |
160 |
- if ftype[x]==0: |
161 |
- rlist=rlist+[list[x]] |
162 |
- elif dirsonly: |
163 |
- rlist = [] |
164 |
- for x in range(0, len(ftype)): |
165 |
- if ftype[x] == 1: |
166 |
- rlist = rlist + [list[x]] |
167 |
- else: |
168 |
- rlist=list |
169 |
- |
170 |
- return rlist |
171 |
- |
172 |
#parse /etc/env.d and generate /etc/profile.env |
173 |
|
174 |
def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, |
175 |
|
176 |
Modified: main/trunk/pym/portage/dbapi/bintree.py |
177 |
=================================================================== |
178 |
--- main/trunk/pym/portage/dbapi/bintree.py 2010-02-25 04:32:14 UTC (rev 15449) |
179 |
+++ main/trunk/pym/portage/dbapi/bintree.py 2010-02-25 05:15:09 UTC (rev 15450) |
180 |
@@ -13,6 +13,7 @@ |
181 |
'portage.package.ebuild.doebuild:_vdb_use_conditional_atoms', |
182 |
'portage.update:update_dbentries', |
183 |
'portage.util:ensure_dirs,normalize_path,writemsg,writemsg_stdout', |
184 |
+ 'portage.util.listdir:listdir', |
185 |
'portage.versions:best,catpkgsplit,catsplit', |
186 |
) |
187 |
|
188 |
@@ -22,7 +23,7 @@ |
189 |
PermissionDenied, PortageException |
190 |
from portage.localization import _ |
191 |
|
192 |
-from portage import dep_expand, listdir, _movefile |
193 |
+from portage import dep_expand, _movefile |
194 |
from portage import os |
195 |
from portage import _encodings |
196 |
from portage import _unicode_decode |
197 |
|
198 |
Modified: main/trunk/pym/portage/dbapi/porttree.py |
199 |
=================================================================== |
200 |
--- main/trunk/pym/portage/dbapi/porttree.py 2010-02-25 04:32:14 UTC (rev 15449) |
201 |
+++ main/trunk/pym/portage/dbapi/porttree.py 2010-02-25 05:15:09 UTC (rev 15450) |
202 |
@@ -11,9 +11,11 @@ |
203 |
import portage |
204 |
portage.proxy.lazyimport.lazyimport(globals(), |
205 |
'portage.checksum', |
206 |
- 'portage.dep:dep_getkey,match_from_list,paren_reduce,use_reduce', |
207 |
+ 'portage.dep:dep_getkey,flatten,match_from_list,paren_reduce,use_reduce', |
208 |
'portage.env.loaders:KeyValuePairFileLoader', |
209 |
+ 'portage.package.ebuild.doebuild:doebuild', |
210 |
'portage.util:ensure_dirs,writemsg,writemsg_level', |
211 |
+ 'portage.util.listdir:listdir', |
212 |
'portage.versions:best,catpkgsplit,_pkgsplit@pkgsplit,ver_regexp', |
213 |
) |
214 |
|
215 |
@@ -27,8 +29,8 @@ |
216 |
from portage.localization import _ |
217 |
from portage.manifest import Manifest |
218 |
|
219 |
-from portage import eclass_cache, auxdbkeys, doebuild, flatten, \ |
220 |
- listdir, dep_expand, eapi_is_supported, dep_check, \ |
221 |
+from portage import eclass_cache, auxdbkeys, \ |
222 |
+ dep_expand, eapi_is_supported, dep_check, \ |
223 |
_eapi_is_deprecated |
224 |
from portage import os |
225 |
from portage import _encodings |
226 |
|
227 |
Modified: main/trunk/pym/portage/dbapi/vartree.py |
228 |
=================================================================== |
229 |
--- main/trunk/pym/portage/dbapi/vartree.py 2010-02-25 04:32:14 UTC (rev 15449) |
230 |
+++ main/trunk/pym/portage/dbapi/vartree.py 2010-02-25 05:15:09 UTC (rev 15450) |
231 |
@@ -11,7 +11,7 @@ |
232 |
import portage |
233 |
portage.proxy.lazyimport.lazyimport(globals(), |
234 |
'portage.checksum:_perform_md5_merge@perform_md5', |
235 |
- 'portage.dep:dep_getkey,isjustname,match_from_list,' + \ |
236 |
+ 'portage.dep:dep_getkey,isjustname,flatten,match_from_list,' + \ |
237 |
'use_reduce,paren_reduce,_slot_re', |
238 |
'portage.elog:elog_process', |
239 |
'portage.locks:lockdir,unlockdir', |
240 |
@@ -23,7 +23,10 @@ |
241 |
'portage.util:apply_secpass_permissions,ConfigProtect,ensure_dirs,' + \ |
242 |
'writemsg,writemsg_level,write_atomic,atomic_ofstream,writedict,' + \ |
243 |
'grabfile,grabdict,normalize_path,new_protect_filename,getlibpaths', |
244 |
- 'portage.versions:best,catpkgsplit,catsplit,pkgcmp,_pkgsplit@pkgsplit', |
245 |
+ 'portage.util.digraph:digraph', |
246 |
+ 'portage.util.listdir:dircache,listdir', |
247 |
+ 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,pkgcmp,' + \ |
248 |
+ '_pkgsplit@pkgsplit', |
249 |
) |
250 |
|
251 |
from portage.const import CACHE_PATH, CONFIG_MEMORY_FILE, \ |
252 |
@@ -35,9 +38,8 @@ |
253 |
FileNotFound, PermissionDenied, UnsupportedAPIException |
254 |
from portage.localization import _ |
255 |
|
256 |
-from portage import listdir, dep_expand, digraph, flatten, \ |
257 |
- env_update, \ |
258 |
- abssymlink, movefile, _movefile, bsd_chflags, cpv_getkey |
259 |
+from portage import dep_expand, env_update, \ |
260 |
+ abssymlink, movefile, _movefile, bsd_chflags |
261 |
|
262 |
# This is a special version of the os module, wrapped for unicode support. |
263 |
from portage import os |
264 |
@@ -1086,7 +1088,6 @@ |
265 |
self.mtdircache.pop(pkg_dblink.cat, None) |
266 |
self.matchcache.pop(pkg_dblink.cat, None) |
267 |
self.cpcache.pop(pkg_dblink.mysplit[0], None) |
268 |
- from portage import dircache |
269 |
dircache.pop(pkg_dblink.dbcatdir, None) |
270 |
|
271 |
def match(self, origdep, use_cache=1): |
272 |
|
273 |
Modified: main/trunk/pym/portage/util/digraph.py |
274 |
=================================================================== |
275 |
--- main/trunk/pym/portage/util/digraph.py 2010-02-25 04:32:14 UTC (rev 15449) |
276 |
+++ main/trunk/pym/portage/util/digraph.py 2010-02-25 05:15:09 UTC (rev 15450) |
277 |
@@ -2,6 +2,8 @@ |
278 |
# Distributed under the terms of the GNU General Public License v2 |
279 |
# $Id$ |
280 |
|
281 |
+__all__ = ['digraph'] |
282 |
+ |
283 |
from portage.util import writemsg |
284 |
|
285 |
class digraph(object): |
286 |
|
287 |
Added: main/trunk/pym/portage/util/listdir.py |
288 |
=================================================================== |
289 |
--- main/trunk/pym/portage/util/listdir.py (rev 0) |
290 |
+++ main/trunk/pym/portage/util/listdir.py 2010-02-25 05:15:09 UTC (rev 15450) |
291 |
@@ -0,0 +1,153 @@ |
292 |
+# Copyright 2010 Gentoo Foundation |
293 |
+# Distributed under the terms of the GNU General Public License v2 |
294 |
+# $Id$ |
295 |
+ |
296 |
+__all__ = ['cacheddir', 'listdir'] |
297 |
+ |
298 |
+import errno |
299 |
+import stat |
300 |
+import time |
301 |
+ |
302 |
+from portage import os |
303 |
+from portage.exception import DirectoryNotFound, PermissionDenied, PortageException |
304 |
+from portage.util import normalize_path, writemsg |
305 |
+ |
306 |
+dircache = {} |
307 |
+cacheHit = 0 |
308 |
+cacheMiss = 0 |
309 |
+cacheStale = 0 |
310 |
+ |
311 |
+def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True): |
312 |
+ global cacheHit,cacheMiss,cacheStale |
313 |
+ mypath = normalize_path(my_original_path) |
314 |
+ if mypath in dircache: |
315 |
+ cacheHit += 1 |
316 |
+ cached_mtime, list, ftype = dircache[mypath] |
317 |
+ else: |
318 |
+ cacheMiss += 1 |
319 |
+ cached_mtime, list, ftype = -1, [], [] |
320 |
+ try: |
321 |
+ pathstat = os.stat(mypath) |
322 |
+ if stat.S_ISDIR(pathstat[stat.ST_MODE]): |
323 |
+ mtime = pathstat.st_mtime |
324 |
+ else: |
325 |
+ raise DirectoryNotFound(mypath) |
326 |
+ except EnvironmentError as e: |
327 |
+ if e.errno == PermissionDenied.errno: |
328 |
+ raise PermissionDenied(mypath) |
329 |
+ del e |
330 |
+ return [], [] |
331 |
+ except PortageException: |
332 |
+ return [], [] |
333 |
+ # Python retuns mtime in seconds, so if it was changed in the last few seconds, it could be invalid |
334 |
+ if mtime != cached_mtime or time.time() - mtime < 4: |
335 |
+ if mypath in dircache: |
336 |
+ cacheStale += 1 |
337 |
+ try: |
338 |
+ list = os.listdir(mypath) |
339 |
+ except EnvironmentError as e: |
340 |
+ if e.errno != errno.EACCES: |
341 |
+ raise |
342 |
+ del e |
343 |
+ raise PermissionDenied(mypath) |
344 |
+ ftype = [] |
345 |
+ for x in list: |
346 |
+ try: |
347 |
+ if followSymlinks: |
348 |
+ pathstat = os.stat(mypath+"/"+x) |
349 |
+ else: |
350 |
+ pathstat = os.lstat(mypath+"/"+x) |
351 |
+ |
352 |
+ if stat.S_ISREG(pathstat[stat.ST_MODE]): |
353 |
+ ftype.append(0) |
354 |
+ elif stat.S_ISDIR(pathstat[stat.ST_MODE]): |
355 |
+ ftype.append(1) |
356 |
+ elif stat.S_ISLNK(pathstat[stat.ST_MODE]): |
357 |
+ ftype.append(2) |
358 |
+ else: |
359 |
+ ftype.append(3) |
360 |
+ except (IOError, OSError): |
361 |
+ ftype.append(3) |
362 |
+ dircache[mypath] = mtime, list, ftype |
363 |
+ |
364 |
+ ret_list = [] |
365 |
+ ret_ftype = [] |
366 |
+ for x in range(0, len(list)): |
367 |
+ if list[x] in ignorelist: |
368 |
+ pass |
369 |
+ elif ignorecvs: |
370 |
+ if list[x][:2] != ".#": |
371 |
+ ret_list.append(list[x]) |
372 |
+ ret_ftype.append(ftype[x]) |
373 |
+ else: |
374 |
+ ret_list.append(list[x]) |
375 |
+ ret_ftype.append(ftype[x]) |
376 |
+ |
377 |
+ writemsg("cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale),10) |
378 |
+ return ret_list, ret_ftype |
379 |
+ |
380 |
+_ignorecvs_dirs = ('CVS', 'SCCS', '.svn', '.git') |
381 |
+ |
382 |
+def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelist=[], followSymlinks=True, |
383 |
+ EmptyOnError=False, dirsonly=False): |
384 |
+ """ |
385 |
+ Portage-specific implementation of os.listdir |
386 |
+ |
387 |
+ @param mypath: Path whose contents you wish to list |
388 |
+ @type mypath: String |
389 |
+ @param recursive: Recursively scan directories contained within mypath |
390 |
+ @type recursive: Boolean |
391 |
+ @param filesonly; Only return files, not more directories |
392 |
+ @type filesonly: Boolean |
393 |
+ @param ignorecvs: Ignore CVS directories ('CVS','SCCS','.svn','.git') |
394 |
+ @type ignorecvs: Boolean |
395 |
+ @param ignorelist: List of filenames/directories to exclude |
396 |
+ @type ignorelist: List |
397 |
+ @param followSymlinks: Follow Symlink'd files and directories |
398 |
+ @type followSymlinks: Boolean |
399 |
+ @param EmptyOnError: Return [] if an error occurs (deprecated, always True) |
400 |
+ @type EmptyOnError: Boolean |
401 |
+ @param dirsonly: Only return directories. |
402 |
+ @type dirsonly: Boolean |
403 |
+ @rtype: List |
404 |
+ @returns: A list of files and directories (or just files or just directories) or an empty list. |
405 |
+ """ |
406 |
+ |
407 |
+ list, ftype = cacheddir(mypath, ignorecvs, ignorelist, EmptyOnError, followSymlinks) |
408 |
+ |
409 |
+ if list is None: |
410 |
+ list=[] |
411 |
+ if ftype is None: |
412 |
+ ftype=[] |
413 |
+ |
414 |
+ if not (filesonly or dirsonly or recursive): |
415 |
+ return list |
416 |
+ |
417 |
+ if recursive: |
418 |
+ x=0 |
419 |
+ while x<len(ftype): |
420 |
+ if ftype[x] == 1 and not \ |
421 |
+ (ignorecvs and os.path.basename(list[x]) in _ignorecvs_dirs): |
422 |
+ l,f = cacheddir(mypath+"/"+list[x], ignorecvs, ignorelist, EmptyOnError, |
423 |
+ followSymlinks) |
424 |
+ |
425 |
+ l=l[:] |
426 |
+ for y in range(0,len(l)): |
427 |
+ l[y]=list[x]+"/"+l[y] |
428 |
+ list=list+l |
429 |
+ ftype=ftype+f |
430 |
+ x+=1 |
431 |
+ if filesonly: |
432 |
+ rlist=[] |
433 |
+ for x in range(0,len(ftype)): |
434 |
+ if ftype[x]==0: |
435 |
+ rlist=rlist+[list[x]] |
436 |
+ elif dirsonly: |
437 |
+ rlist = [] |
438 |
+ for x in range(0, len(ftype)): |
439 |
+ if ftype[x] == 1: |
440 |
+ rlist = rlist + [list[x]] |
441 |
+ else: |
442 |
+ rlist=list |
443 |
+ |
444 |
+ return rlist |
445 |
|
446 |
|
447 |
Property changes on: main/trunk/pym/portage/util/listdir.py |
448 |
___________________________________________________________________ |
449 |
Added: svn:keywords |
450 |
+ Id |