]>
git.sthu.org Git - shutils.git/blob - eFindStaleFiles.py
4 __author__
= "Stefan Huber"
5 __email__
= "shuber@cosy.sbg.ac.at"
13 # portage (output module) and gentoolkit need special path modifications
14 sys
.path
.insert(0, "/usr/lib/portage/pym")
15 sys
.path
.insert(0, "/usr/lib/gentoolkit/pym")
25 sys
.stderr
.write("\033[0;34m" + str + "\033[m")
29 if len(f
)>1 and f
[-1]=="/":
34 def getNontrackedFiles( directory
, trackedFiles
):
36 directory
= stripSlash(directory
)
37 print_dbg("Scan '" + directory
+ "'...\n")
39 if not os
.access(directory
, os
.F_OK
):
40 print_dbg(" not existing.\n")
41 elif os
.path
.islink(directory
):
42 print_dbg(" symlink, skipping.\n")
45 # The directory is not tracked -- yield it
46 if not directory
in trackedFiles
and directory
!="/":
50 # So 'directory' is tracked -- get its content
51 for dirpath
, dirnames
, filenames
in os
.walk(directory
):
53 # just interested in this directory
54 if dirpath
!=directory
:
58 return os
.path
.join(dirpath
,f
)
62 if not topath(f
) in trackedFiles
:
65 # check the directories and, if necessary, start recursive scan
67 if not topath(d
) in trackedFiles
:
70 for f
in getNontrackedFiles(topath(d
), trackedFiles
):
77 def getTrackedFiles( directory
):
79 directory
= stripSlash(directory
)
80 print_dbg("Get tracked files from '" + directory
+ "'...\n")
82 rxexp
= "^" + directory
83 rx
= re
.compile(rxexp
)
85 #Get all packages installed
87 vartree
= portage
.db
[root
]["vartree"]
88 allcpv
= vartree
.getallcpv()
91 #Now, really get the files
97 print_dbg("%d of %d packages done...\n" % (no
, len(allcpv
)))
99 #Get all files of this cpv
100 cpvsplit
= cpv
.split("/")
101 cat
,pkg
= cpvsplit
[0:2]
102 db
= portage
.dblink(cat
, pkg
, root
, vartree
.settings
)
103 cpvfiles
= db
.getcontents().keys()
105 #Check for all files of cpv, whether it matches regex
107 if rx
.search(f
) or directory
=="/":
112 if __name__
== "__main__":
114 # get directories to scan
119 # get the files tracked and which are in the directories
122 trackedfiles |
= set(getTrackedFiles(d
))
124 # get the non-tracked files
126 for f
in getNontrackedFiles(d
, trackedfiles
):