Advertisement
FacetedFox

config2html.py

Feb 27th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.84 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import os.path as op
  4. import sys
  5. import html
  6.  
  7. master = []
  8. actual = {}
  9.  
  10. def add(config, arch, mode='n'):
  11.     if config not in master:
  12.         return
  13.     if config not in actual:
  14.         actual[config] = {arch: mode}
  15.     else:
  16.         actual[config][arch] = mode
  17.  
  18. mode2class = {
  19.     'y': 'yes',
  20.     'n': 'no',
  21.     'm': 'module'
  22. }
  23. mode2str = {
  24.     'y': '✔',
  25.     'n': '✗',
  26.     'm': '✱'
  27. }
  28.  
  29. archs = ('armv7', 'aarch64', 'ppc', 'ppc64', 'ppc64-p8', 'sparc64', 'pmmx', 'x86_64')
  30.  
  31. with open('uniconfig', mode='rt') as f:
  32.     lines = f.readlines()
  33.  
  34. for line in lines:
  35.     line = line[:-1]
  36.     config, *trash = line.split('=')
  37.     master.append(config)
  38.  
  39. for arch in archs:
  40.     with open('config-{}'.format(arch), mode='rt') as f:
  41.         lines = f.readlines()
  42.  
  43.     for line in lines:
  44.         line = line[:-1]
  45.         if len(line) < 2:
  46.             continue
  47.  
  48.         mode = '?'
  49.  
  50.         if line.startswith('#'):
  51.             args = line.split()
  52.             config = args[1]
  53.             mode = 'n'
  54.  
  55.         if '=' in line:
  56.             config, mode = line.split('=', 2)
  57.         elif mode == '?':
  58.             config = line
  59.             mode = 'y'
  60.         add(config, arch, mode)
  61.  
  62. with open('config.html', mode='wt') as f:
  63.     f.write('\n'.join([
  64.         '<!DOCTYPE html>',
  65.         '<html>',
  66.         '\t<head>',
  67.         '\t\t<meta charset="UTF-8">',
  68.         '\t\t<title>Kernel config map</title>',
  69.         '\t\t<link href="style.css" rel="stylesheet">',
  70.         '\t</head>',
  71.         '\t<body>',
  72.         '\t\t<p><b>Notes</b>:</p>',
  73.         '\t\t<ul>',
  74.         '\t\t\t<li>32-bit ARM is ARMv7. No config exists for this platform as of yet.</li>',
  75.         '\t\t\t<li>32-bit x86 is Pentium® with MMX® technology. This platform omits SSE instructions.</li>',
  76.         '\t\t\t<li>SPARC64 config exists, but Adélie support is waiting for a port of the musl libc to this arch.</li>',
  77.         '\t\t\t<li>P8 is POWER8+. This is necessary because <tt>CONFIG_GENERIC=y</tt> produces unsuable images on POWER8+.</li>',
  78.         '\t\t</ul>',
  79.         '\t\t<table>',
  80.         '\t\t\t<thead>'
  81.         '\t\t\t\t<tr class="header"><th rowspan="2">Flag</th><th colspan="2">ARM</th><th colspan="3">PPC</th><th rowspan="2">Sparc64</th><th colspan="2">x86</th></tr>',
  82.         '\t\t\t\t<tr class="header"><th>32</th><th>64</th><th>32</th><th>64</th><th>P8</th><th>32</th><th>64</th></tr>',
  83.         '\t\t\t</thead>',
  84.         '\t\t\t<tbody>',
  85.     ]))
  86.     for config in sorted(actual.keys()):
  87.         arch_conf = actual[config]
  88.         if not op.exists('kconfig/{}.html'.format(config)):
  89.             text = config
  90.         else:
  91.             with open('kconfig/{}.html'.format(config), mode='rt') as g:
  92.                 text = ''.join(g.readlines())
  93.         f.write('\t\t\t<tr><th>{}</th>'.format(text))
  94.         for arch in archs:
  95.             if arch in arch_conf:
  96.                 mode = arch_conf[arch]
  97.                 if mode in 'ynm':
  98.                     string = '<td class="{}">{}</td>'.format(
  99.                         mode2class[arch_conf[arch]],
  100.                         mode2str[arch_conf[arch]]
  101.                     )
  102.                 else:
  103.                     if len(mode) > 8:
  104.                         string = '<td title={}>{}</td>'.format(
  105.                             '"{}"'.format(mode if not mode.startswith('"') else html.escape(mode)),
  106.                             '{}…'.format(mode[:7])
  107.                         )
  108.                     else:
  109.                         string = '<td>{}</td>'.format(mode)
  110.                 f.write(string)
  111.             else:
  112.                 f.write('<td class="{}">{}</td>'.format(
  113.                     mode2class['n'], mode2str['n']
  114.                 ))
  115.         f.write('</tr>\n')
  116.     f.write('\n'.join([
  117.         '\t\t\t</tbody>',
  118.         '\t\t</table>',
  119.         '\t</body>',
  120.         '</html>'
  121.     ]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement