1 | #!/usr/bin/env python |
---|
2 | # This script generates a table of dependencies in HTML format on stdout. |
---|
3 | # It expects to be run in the tahoe-lafs-dep-eggs directory. |
---|
4 | |
---|
5 | import re, os, sys |
---|
6 | |
---|
7 | extensions = ('.egg', '.tar.bz2', '.tar.gz', '.exe') |
---|
8 | platform_aliases = [('i686','x86'), ('i386','x86'), ('i86pc','x86'), ('win32','windows-x86'), |
---|
9 | ('win-amd64','windows-x86_64'), ('amd64','x86_64')] |
---|
10 | FILENAME_RE = re.compile(r'([a-zA-Z_0-9]*)-([0-9\.a-vx-z_]*)(-py[0-9\.]*)?(-.*)?') |
---|
11 | FILENAME_RE2 = re.compile(r'([a-zA-Z_0-9]*)-([0-9\.a-vx-z_]*)(win32|win-amd64)?(-py[0-9\.]*)?') |
---|
12 | |
---|
13 | matrix = {} |
---|
14 | platforms = set() |
---|
15 | pkgs = set() |
---|
16 | platform_dependent_pkgs = set() |
---|
17 | python_versions = set() |
---|
18 | |
---|
19 | depdir = '.' |
---|
20 | if len(sys.argv) > 1: |
---|
21 | depdir = sys.argv[1] |
---|
22 | |
---|
23 | filenames = os.listdir(depdir) |
---|
24 | |
---|
25 | def add(d, k, v): |
---|
26 | if k in d: |
---|
27 | d[k] += [v] |
---|
28 | else: |
---|
29 | d[k] = [v] |
---|
30 | |
---|
31 | for fname in filenames: |
---|
32 | for ext in extensions: |
---|
33 | if fname.endswith(ext): |
---|
34 | m = FILENAME_RE.match(fname[:-len(ext)]) |
---|
35 | try: |
---|
36 | pkg = m.group(1) |
---|
37 | pythonver = (m.group(3) or '-py')[3:] |
---|
38 | platform = (m.group(4) or '-')[1:] |
---|
39 | except (IndexError, AttributeError, TypeError): |
---|
40 | continue |
---|
41 | |
---|
42 | if not pythonver: |
---|
43 | m = FILENAME_RE2.match(fname[:-len(ext)]) |
---|
44 | if m.group(3): |
---|
45 | try: |
---|
46 | platform = m.group(3) |
---|
47 | pythonver = (m.group(4) or '-py')[3:] |
---|
48 | except (IndexError, AttributeError, TypeError): |
---|
49 | continue |
---|
50 | |
---|
51 | for (alias, replacement) in platform_aliases: |
---|
52 | if platform.endswith(alias): |
---|
53 | platform = platform[:-len(alias)] + replacement |
---|
54 | break |
---|
55 | |
---|
56 | platforms.add(platform) |
---|
57 | pkgs.add(pkg) |
---|
58 | if platform: |
---|
59 | platform_dependent_pkgs.add(pkg) |
---|
60 | if pythonver not in matrix: |
---|
61 | python_versions.add(pythonver) |
---|
62 | matrix[pythonver] = {} |
---|
63 | add(matrix[pythonver], platform, (pkg, fname)) |
---|
64 | break |
---|
65 | |
---|
66 | platform_independent_pkgs = pkgs - platform_dependent_pkgs |
---|
67 | |
---|
68 | width = 100 / (len(platform_independent_pkgs) + 1) |
---|
69 | |
---|
70 | print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' |
---|
71 | print '<html>' |
---|
72 | print '<head>' |
---|
73 | print ' <meta http-equiv="Content-Type" content="text/html;charset=us-ascii">' |
---|
74 | print ' <title>Software packages that Tahoe-LAFS depends on</title>' |
---|
75 | print '</head>' |
---|
76 | print '<body>' |
---|
77 | print '<h2>Software packages that Tahoe-LAFS depends on</h2>' |
---|
78 | print |
---|
79 | for pyver in sorted(python_versions): |
---|
80 | if pyver: |
---|
81 | print '<p>Packages for Python %s that have compiled C/C++ code:</p>' % (pyver,) |
---|
82 | print '<table border="1">' |
---|
83 | print ' <tr>' |
---|
84 | print ' <th style="background-color: #FFFFD0" width="%d%%"> Platform </th>' % (width,) |
---|
85 | for pkg in sorted(platform_dependent_pkgs): |
---|
86 | print ' <th style="background-color:#FFE8FF;" width="%d%%"> %s </th>' % (width, pkg) |
---|
87 | print ' </tr>' |
---|
88 | |
---|
89 | first = True |
---|
90 | for platform in sorted(matrix[pyver]): |
---|
91 | row_files = sorted(matrix[pyver][platform]) |
---|
92 | style1 = first and 'border-top: 2px solid #000000; background-color: #FFFFF0' or 'background-color: #FFFFF0' |
---|
93 | style2 = first and 'border-top: 2px solid #000000' or '' |
---|
94 | print ' <tr>' |
---|
95 | print ' <td style="%s"> %s </td>' % (style1, platform,) |
---|
96 | for pkg in sorted(platform_dependent_pkgs): |
---|
97 | files = [n for (p, n) in row_files if pkg == p] |
---|
98 | print ' <td style="%s"> %s</td>' % (style2, |
---|
99 | '<br> '.join(['<a href="%s">%s</a>' % (f, f) for f in files])) |
---|
100 | print ' </tr>' |
---|
101 | first = False |
---|
102 | |
---|
103 | print '</table>' |
---|
104 | print |
---|
105 | |
---|
106 | print '<p>Packages that are platform-independent or source-only:</p>' |
---|
107 | print '<table border="1">' |
---|
108 | print ' <tr>' |
---|
109 | print ' <th style="background-color:#FFFFD0;"> Package </th>' |
---|
110 | print ' <th style="background-color:#FFE8FF;"> All Python versions </th>' |
---|
111 | print ' </tr>' |
---|
112 | |
---|
113 | style1 = 'border-top: 2px solid #000000; background-color:#FFFFF0;' |
---|
114 | style2 = 'border-top: 2px solid #000000;' |
---|
115 | m = matrix[''][''] |
---|
116 | for pkg in sorted(platform_independent_pkgs): |
---|
117 | print ' <tr>' |
---|
118 | print ' <th style="%s"> %s </th>' % (style1, pkg) |
---|
119 | files = [n for (p, n) in m if pkg == p] |
---|
120 | print ' <td style="%s"> %s</td>' % (style2, '<br> '.join(['<a href="%s">%s</a>' % (f, f) for f in files])) |
---|
121 | print ' </tr>' |
---|
122 | |
---|
123 | print '</table>' |
---|
124 | |
---|
125 | # The document does validate, but not when it is included at the bottom of a directory listing. |
---|
126 | #print '<hr>' |
---|
127 | #print '<a href="http://validator.w3.org/check?uri=referer" target="_blank"><img border="0" src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>' |
---|
128 | print '</body></html>' |
---|