summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/highlight.py55
-rwxr-xr-xtools/makeindex.py53
2 files changed, 108 insertions, 0 deletions
diff --git a/tools/highlight.py b/tools/highlight.py
new file mode 100755
index 0000000..ecdb49e
--- /dev/null
+++ b/tools/highlight.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# vim: set fileencoding=utf8 :
+
+"""
+Highlight elan source file
+"""
+
+if __name__ == '__main__':
+ import sys, os, shutil
+ from pygments import highlight
+ from pygments.lexers import get_lexer_by_name
+ from pygments.formatters import HtmlFormatter
+ from jinja2 import Template
+
+ tpl = Template("""<!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
+ <link rel="stylesheet" href="/style.min.css" type="text/css" />
+ <title>{{ path }}</title>
+ <style>
+ body {
+ max-width: none;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>{{ path }}</h1>
+ <p><a href="{{ rawfile }}">Raw file</a><br><a href="{{ index }}">Back to index</a></p>
+ {{ code|safe }}
+ </body></html>""")
+
+ destdir = '_build'
+ f = sys.argv[1]
+ print (f)
+
+ basedir = os.path.dirname (f)
+ basedestdir = os.path.join (destdir, basedir)
+ os.makedirs (basedestdir, exist_ok=True)
+ shutil.copy (f, os.path.join (destdir, f))
+ destf = os.path.join (destdir, f + '.html')
+
+ try:
+ with open (f, 'r') as srcfd:
+ code = srcfd.read ()
+ except UnicodeDecodeError:
+ # that’s fine
+ sys.exit (0)
+
+ lexer = get_lexer_by_name("elan", stripall=True)
+ formatter = HtmlFormatter (linenos=True, lineanchors='line', anchorlinenos=True)
+ with open (destf, 'w') as destfd:
+ tpl.stream(code=highlight(code, lexer, formatter), path=f, rawfile=os.path.basename (f), index=os.path.relpath ('.', os.path.dirname (f))).dump (destfd)
+
diff --git a/tools/makeindex.py b/tools/makeindex.py
new file mode 100755
index 0000000..76816b2
--- /dev/null
+++ b/tools/makeindex.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# vim: set fileencoding=utf8 :
+
+"""
+Create package index
+"""
+
+if __name__ == '__main__':
+ import os
+ from operator import itemgetter
+ from itertools import groupby
+ from yarl import URL
+
+ pkgs = {}
+
+ for dirpath, dirnames, filenames in os.walk ('.'):
+ dirs = dirpath.split (os.sep)
+ if len (dirs) < 4:
+ continue
+
+ cat = dirs[1]
+ if cat not in {'app', 'devel', 'doc', 'lang', 'system'}:
+ continue
+ pkg = dirs[2]
+ ver = dirs[3]
+
+ i = (cat, pkg, ver)
+ pkgs.setdefault (i, [])
+
+ for f in filenames:
+ # not highlighting anything else currently (doc for example)
+ if dirs[-1] == 'src':
+ pkgs[i].append (os.path.join (*dirs[4:], f))
+
+ for cat, pkgs in groupby (sorted (pkgs.items(), key=itemgetter(0)), key=lambda x: x[0][0]):
+ print (f'{cat}\n{"^"*len(cat)}\n')
+ for (cat, pkg, ver), files in pkgs:
+ heading = f'{pkg}-{ver}'
+ print (f'\n{heading}\n{"*"*len(heading)}\n')
+ disklist = os.path.join (cat, pkg, ver, 'source-disk')
+ if os.path.exists (disklist):
+ with open (disklist) as fd:
+ diskfiles = [x.strip() for x in fd.readlines ()]
+ assert all (map (lambda x: os.path.isfile (os.path.join ('..', 'disks', x)), diskfiles)), diskfiles
+ disks = map (lambda x: URL('../disks/' + x.split('/')[0] + '.zip'), diskfiles)
+ print ('Source disk: ')
+ print (',\n'.join (map (lambda x: f'`{x[0]} <{x[1].raw_path}>`__', enumerate (disks, 1))))
+ print ('')
+ for f in sorted (files, key=lambda x: x.lower()):
+ u = URL (f'{cat}/{pkg}/{ver}/{f}.html')
+ print (f'- `{f} <{u.raw_path}>`__')
+ print ('')
+