]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/build_helpers/gen-package-table.py
add alternating grey-background to make it easier to scan across the table left to...
[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 FILENAME_RE  = re.compile(r'([a-zA-Z_0-9\.]*)-([0-9\.a-vx-z_]*)(-py[0-9\.]*)?(-.*)?')
12 FILENAME_RE2 = re.compile(r'([a-zA-Z_0-9\.]*)-([0-9\.a-vx-z_]*)(win32|win-amd64)?(-py[0-9\.]*)?')
13
14 matrix = {}
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             pkgs.add(pkg)
57             if platform:
58                 platform_dependent_pkgs.add(pkg)
59             if pythonver not in matrix:
60                 python_versions.add(pythonver)
61                 matrix[pythonver] = {}
62             add(matrix[pythonver], platform, (pkg, fname))
63             break
64
65 platform_independent_pkgs = pkgs - platform_dependent_pkgs
66
67 width = 100 / (len(platform_independent_pkgs) + 1)
68
69 greybgstyle = '; background-color: #E0E0E0'
70 nobgstyle = ''
71
72 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
73 print '<html>'
74 print '<head>'
75 print '  <meta http-equiv="Content-Type" content="text/html;charset=us-ascii">'
76 print '  <title>Software packages that Tahoe-LAFS depends on</title>'
77 print '</head>'
78 print '<body>'
79 print '<h2>What is this?</h2>'
80 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>.'
81 print '<h2>Software packages that Tahoe-LAFS depends on</h2>'
82 print
83 for pyver in reversed(sorted(python_versions)):
84     greybackground = False
85     if pyver:
86         print '<p>Packages for Python %s that have compiled C/C++ code:</p>' % (pyver,)
87         print '<table border="1">'
88         print '  <tr>'
89         print '    <th style="background-color: #FFFFD0" width="%d%%">&nbsp;Platform&nbsp;</th>' % (width,)
90         for pkg in sorted(platform_dependent_pkgs):
91             print '    <th style="background-color:#FFE8FF;" width="%d%%">&nbsp;%s&nbsp;</th>' % (width, pkg)
92         print '  </tr>'
93
94         first = True
95         for platform in sorted(matrix[pyver]):
96             if greybackground:
97                 bgstyle = greybgstyle
98             else:
99                 bgstyle = nobgstyle
100             greybackground = not greybackground
101             row_files = sorted(matrix[pyver][platform])
102             style1 = first and 'border-top: 2px solid #000000' or ''
103             style1 += bgstyle
104             style2 = first and 'border-top: 2px solid #000000' or ''
105             style2 += bgstyle
106             print '  <tr>'
107             print '    <td style="%s">&nbsp;%s&nbsp;</td>' % (style1, platform,)
108             for pkg in sorted(platform_dependent_pkgs):
109                 files = [n for (p, n) in row_files if pkg == p]
110                 bestfile = files and max([(pkg_resources.parse_version(x), x) for x in files])[1] or None
111                 if pkg == 'pywin32' and not platform.startswith('windows'):
112                     print '    <td style="border: 0; text-align: center; %s"> n/a </td>' % (style2,)
113                 else:
114                     print '    <td style="%s">&nbsp;%s</td>' % (style2,
115                             bestfile and '<a href="%s">%s</a>' % (bestfile, bestfile) or '')
116             print '  </tr>'
117             first = False
118
119     print '</table>'
120     print
121
122 print '<p>Packages that are platform-independent or source-only:</p>'
123 print '<table border="1">'
124 print '  <tr>'
125 print '    <th style="background-color:#FFFFD0;">&nbsp;Package&nbsp;</th>'
126 print '    <th style="background-color:#FFE8FF;">&nbsp;All Python versions&nbsp;</th>'
127 print '  </tr>'
128
129 style1 = 'border-top: 2px solid #000000; background-color:#FFFFF0;'
130 style2 = 'border-top: 2px solid #000000;'
131 m = matrix['']['']
132 for pkg in sorted(platform_independent_pkgs):
133     print '  <tr>'
134     print '    <th style="%s">&nbsp;%s&nbsp;</th>' % (style1, pkg)
135     files = [n for (p, n) in m if pkg == p]
136     print '    <td style="%s">&nbsp;%s</td>' % (style2, '<br>&nbsp;'.join(['<a href="%s">%s</a>' % (f, f) for f in files]))
137     print '  </tr>'
138
139 print '</table>'
140
141 # The document does validate, but not when it is included at the bottom of a directory listing.
142 #print '<hr>'
143 #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>'
144 print '</body></html>'