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 ya2
.build
.build
import InsideDir
6 from pathlib
import Path
7 from re
import match
, findall
, sub
11 #TODO refactor: make class DocsBuilder
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')]
20 for fname
in glob('docs/*.html'):
22 with
open(fname
) as fhtml
:
23 lines
= fhtml
.readlines()
25 occurs
= findall('"#[0-9A-Fa-f]{6}"', line
)
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
))
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')