Attachment 'pycruft.py'
Download 1 #!/usr/bin/python
2
3 import glob
4 import os
5 import sys
6
7 # dict that maps path -> list of packages that contain the path
8 files = {}
9
10 for lf in glob.glob ('/var/lib/dpkg/info/*.list'):
11 package = lf[19:-5]
12 for file in [line.strip () for line in open (lf)]:
13 if not file in files:
14 files[file] = []
15 files[file].append (package)
16
17 dirs = sys.path[1:] # sys.path[0] is the dir that contains this script
18
19 def raise_error (e):
20 raise e
21
22 for dir in dirs:
23 if not os.path.isdir (dir):
24 continue
25
26 for dirpath, dirnames, filenames in os.walk (dir, onerror = raise_error):
27 for filename in filenames:
28 path = os.path.join (dirpath, filename)
29
30 # symlinks are OK as long as they point to an existing file
31 if os.path.islink (path):
32 if not os.path.exists (path):
33 print 'broken link: %s' % (path)
34 continue
35
36 # .pyc files should be accompanied by a corresponding .py file
37 if path.endswith ('.pyc'):
38 if not os.path.exists (path[:-1]):
39 print 'orphaned .pyc: %s' % (path)
40 continue
41
42 # other files should be in dpkg's datbase
43 if path not in files:
44 if filename == '__init__.py' and os.path.getsize (path) == 0:
45 # possibly a python-central-created __init__.py
46 continue
47
48 print 'untracked: %s' % (path)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.