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