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 | |
---|
6 | import re, os, sys |
---|
7 | import pkg_resources |
---|
8 | |
---|
9 | extensions = ('.egg', '.tar.bz2', '.tar.gz', '.exe') |
---|
10 | platform_aliases = [('i686','x86'), ('i386','x86'), ('i86pc','x86'), ('win32','windows-x86'), |
---|
11 | ('win-amd64','windows-x86_64'), ('amd64','x86_64')] |
---|
12 | min_supported_python = {'windows-x86': '2.7', 'windows-x86_64': '2.7'} |
---|
13 | pkg_name_continuations = ('modules') |
---|
14 | |
---|
15 | FILENAME_RE = re.compile(r'([a-zA-Z_0-9\.]*)-([0-9\.a-vx-z_]*)(-py[0-9\.]*)?(-.*)?') |
---|
16 | FILENAME_RE2 = re.compile(r'([a-zA-Z_0-9\.]*)-([0-9\.a-vx-z_]*)(win32|win-amd64)?(-py[0-9\.]*)?') |
---|
17 | |
---|
18 | matrix = {} |
---|
19 | pkgs = set() |
---|
20 | platform_dependent_pkgs = set() |
---|
21 | python_versions = set() |
---|
22 | |
---|
23 | depdirs = ['.', '../tahoe-dep-sdists'] |
---|
24 | if len(sys.argv) > 1: |
---|
25 | depdirs = sys.argv[1 :] |
---|
26 | |
---|
27 | filenames = set() |
---|
28 | for depdir in depdirs: |
---|
29 | filenames = filenames.union(os.listdir(depdir)) |
---|
30 | |
---|
31 | def add(d, k, v): |
---|
32 | if k in d: |
---|
33 | d[k] += [v] |
---|
34 | else: |
---|
35 | d[k] = [v] |
---|
36 | |
---|
37 | for fname in filenames: |
---|
38 | for ext in extensions: |
---|
39 | if fname.endswith(ext): |
---|
40 | m = FILENAME_RE.match(fname[:-len(ext)]) |
---|
41 | try: |
---|
42 | pkg = m.group(1) |
---|
43 | pkg2 = m.group(2) |
---|
44 | if pkg2 in pkg_name_continuations: |
---|
45 | pkg += '-' + pkg2 |
---|
46 | else: |
---|
47 | pythonver = (m.group(3) or '-py')[3:] |
---|
48 | platform = (m.group(4) or '-')[1:] |
---|
49 | except (IndexError, AttributeError, TypeError): |
---|
50 | continue |
---|
51 | |
---|
52 | if not pkg2 in pkg_name_continuations and not pythonver: |
---|
53 | m = FILENAME_RE2.match(fname[:-len(ext)]) |
---|
54 | if m.group(3): |
---|
55 | try: |
---|
56 | platform = m.group(3) |
---|
57 | pythonver = (m.group(4) or '-py')[3:] |
---|
58 | except (IndexError, AttributeError, TypeError): |
---|
59 | continue |
---|
60 | |
---|
61 | for (alias, replacement) in platform_aliases: |
---|
62 | if platform.endswith(alias): |
---|
63 | platform = platform[:-len(alias)] + replacement |
---|
64 | break |
---|
65 | |
---|
66 | pkgs.add(pkg) |
---|
67 | if platform: |
---|
68 | platform_dependent_pkgs.add(pkg) |
---|
69 | if pythonver not in matrix: |
---|
70 | python_versions.add(pythonver) |
---|
71 | matrix[pythonver] = {} |
---|
72 | add(matrix[pythonver], platform, (pkg, fname)) |
---|
73 | break |
---|
74 | |
---|
75 | platform_independent_pkgs = pkgs - platform_dependent_pkgs |
---|
76 | |
---|
77 | width = 100 / (len(platform_dependent_pkgs) + 1) |
---|
78 | |
---|
79 | def file_list(all_files, pkg): |
---|
80 | files = sorted([(pkg_resources.parse_version(n), n) for (p, n) in all_files if pkg == p]) |
---|
81 | return '<br> '.join(['<a href="%s">%s</a>' % (f, f) for (v, f) in files]) |
---|
82 | |
---|
83 | greybgstyle = '; background-color: #E0E0E0' |
---|
84 | nobgstyle = '' |
---|
85 | unsupportedstyle = '; color: #C00000' |
---|
86 | |
---|
87 | print('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">') |
---|
88 | print('<html>') |
---|
89 | print('<head>') |
---|
90 | print(' <meta http-equiv="Content-Type" content="text/html;charset=us-ascii">') |
---|
91 | print(' <title>Software packages that Tahoe-LAFS depends on</title>') |
---|
92 | print('</head>') |
---|
93 | print('<body>') |
---|
94 | print('<h2>What is this?</h2>') |
---|
95 | print('<p>See <a href="https://tahoe-lafs.org/trac/tahoe-lafs/browser/docs/quickstart.rst">quickstart.rst</a>, <a href="https://tahoe-lafs.org/trac/tahoe-lafs/wiki/Installation">wiki:Installation</a>, and <a href="https://tahoe-lafs.org/trac/tahoe-lafs/wiki/CompileError">wiki:CompileError</a>.') |
---|
96 | print('<h2>Software packages that Tahoe-LAFS depends on</h2>') |
---|
97 | print() |
---|
98 | for pyver in reversed(sorted(python_versions)): |
---|
99 | greybackground = False |
---|
100 | if pyver: |
---|
101 | print('<p>Packages for Python %s that have compiled C/C++ code:</p>' % (pyver,)) |
---|
102 | print('<table border="1">') |
---|
103 | print(' <tr>') |
---|
104 | print(' <th style="background-color: #FFFFD0" width="%d%%"> Platform </th>' % (width,)) |
---|
105 | for pkg in sorted(platform_dependent_pkgs): |
---|
106 | print(' <th style="background-color: #FFE8FF;" width="%d%%"> %s </th>' % (width, pkg)) |
---|
107 | print(' </tr>') |
---|
108 | |
---|
109 | first = True |
---|
110 | for platform in sorted(matrix[pyver]): |
---|
111 | unsupported_python = (platform in min_supported_python and |
---|
112 | pyver.split('.') < min_supported_python[platform].split('.')) |
---|
113 | |
---|
114 | if greybackground: |
---|
115 | bgstyle = greybgstyle |
---|
116 | else: |
---|
117 | bgstyle = nobgstyle |
---|
118 | greybackground = not greybackground |
---|
119 | row_files = sorted(matrix[pyver][platform]) |
---|
120 | style1 = first and 'border-top: 2px solid #000000' or '' |
---|
121 | style1 += bgstyle |
---|
122 | style1 += unsupported_python and unsupportedstyle or '' |
---|
123 | style2 = first and 'border-top: 2px solid #000000' or '' |
---|
124 | style2 += bgstyle |
---|
125 | annotated_platform = platform.replace('-', '‑') + (unsupported_python and ' (unsupported)' or '') |
---|
126 | print(' <tr>') |
---|
127 | print(' <td style="%s"> %s </td>' % (style1, annotated_platform)) |
---|
128 | for pkg in sorted(platform_dependent_pkgs): |
---|
129 | if pkg == 'pywin32' and not platform.startswith('windows'): |
---|
130 | print(' <td style="border: 0; text-align: center; %s"> n/a </td>' % (style2,)) |
---|
131 | else: |
---|
132 | print(' <td style="%s"> %s</td>' % (style2, file_list(row_files, pkg))) |
---|
133 | print(' </tr>') |
---|
134 | first = False |
---|
135 | |
---|
136 | print('</table>') |
---|
137 | print() |
---|
138 | |
---|
139 | print('<p>Packages that are platform-independent or source-only:</p>') |
---|
140 | print('<table border="1">') |
---|
141 | print(' <tr>') |
---|
142 | print(' <th style="background-color:#FFFFD0;"> Package </th>') |
---|
143 | print(' <th style="background-color:#FFE8FF;"> All Python versions </th>') |
---|
144 | print(' </tr>') |
---|
145 | |
---|
146 | style1 = 'border-top: 2px solid #000000; background-color:#FFFFF0;' |
---|
147 | style2 = 'border-top: 2px solid #000000;' |
---|
148 | m = matrix[''][''] |
---|
149 | for pkg in sorted(platform_independent_pkgs): |
---|
150 | print(' <tr>') |
---|
151 | print(' <th style="%s"> %s </th>' % (style1, pkg)) |
---|
152 | print(' <td style="%s"> %s</td>' % (style2, file_list(m, pkg))) |
---|
153 | print(' </tr>') |
---|
154 | |
---|
155 | print('</table>') |
---|
156 | |
---|
157 | # The document does validate, but not when it is included at the bottom of a directory listing. |
---|
158 | #print('<hr>') |
---|
159 | #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>') |
---|
160 | print('</body></html>') |
---|