Commit | Line | Data |
---|---|---|
8ee66edd FC |
1 | '''This module creates the documentation using pydoc.''' |
2 | from os import system, mkdir, remove, rename | |
3 | from os.path import exists | |
4 | from shutil import rmtree, make_archive | |
5 | from lib.build.build import InsideDir | |
6 | from pathlib import Path | |
fdcee70d | 7 | from re import match, findall, sub |
8ee66edd FC |
8 | from glob import glob |
9 | ||
10 | ||
11 | #TODO refactor: make class DocsBuilder | |
12 | ||
13 | ||
14 | def bld_docs(): | |
15 | '''Builds the docs (inside a zip file).''' | |
16 | system('python -m pydoc -w ./') | |
17 | rmtree('docs', ignore_errors=True) | |
18 | Path('docs').mkdir(exist_ok=True) | |
19 | [rename(fname, 'docs/' + fname) for fname in glob('*.html')] | |
fdcee70d FC |
20 | for fname in glob('docs/*.html'): |
21 | out_lines = [] | |
22 | with open(fname) as fhtml: | |
23 | lines = fhtml.readlines() | |
24 | for line in lines: | |
25 | occurs = findall('"#[0-9A-Fa-f]{6}"', line) | |
26 | new_line = line | |
27 | for occur in occurs: | |
28 | red = int(occur[2:4], 16) / 255 | |
29 | green = int(occur[4:6], 16) / 255 | |
30 | blue = int(occur[6:8], 16) / 255 | |
31 | new_col = .2989 * red + .5870 * green + .1140 * blue | |
32 | new_col = hex(int(round(new_col * 255)))[2:] | |
33 | new_col = '"#%s%s%s"' % (new_col, new_col, new_col) | |
34 | new_line = sub('"#[0-9A-Fa-f]{6}"', new_col, new_line) | |
35 | out_lines += [new_line] | |
36 | with open(fname, 'w') as fhtml: | |
37 | fhtml.write(''.join(out_lines)) | |
8ee66edd FC |
38 | Path('build').mkdir(exist_ok=True) |
39 | rmtree('build/docs', ignore_errors=True) | |
40 | rename('docs', 'build/docs') | |
41 | with InsideDir('build'): | |
42 | exists('docs.zip') and remove('docs.zip') | |
43 | make_archive('docs', 'zip', '.', 'docs') | |
44 | rmtree('docs') |