~aleteoryx/gloss

ref: 898681c2532beaac134259024aaa83b794af13e4 gloss/gloss/__main__.py -rwxr-xr-x 1.5 KiB
898681c2Aleteoryx build system 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/env python3

from time import time
start = time()

from sys import argv
from pathlib import Path
from math import log10

from . import get_steps
from .util import die


usage = f'''
usage: {argv[0]} <SRCDIR> <OUTDIR>

recurses into SRCDIR, parsing each .gloss file as YAML and running the
requested parser. if a directory does not contain a '.gloss' file, or
said file's 'mode' key is missing, the mode defaults to 'copy'.

.gloss may include the following fields:
	mode:	sets the mode. may be one of 'copy', 'ignore', or
		'gloss'. if mode is 'ignore', the directory and all
		subdirectories will be skipped.
	out:	sets the output directory, relative to OUTDIR. if
		omitted, it defaults to the current path relative to
		SRCDIR.
'''[1:]


argv = argv[1:]
if len(argv) != 2 or argv[0][0] == '-' or argv[1][0] == '-':
	die(usage)
srcdir = Path(argv[0]).absolute()
outdir = Path(argv[1]).absolute()


print('collecting steps...')
steps = get_steps(srcdir, outdir)

numlen = int(log10(len(steps))+1)
nfmt = f'[{{0:{numlen}}}/{len(steps)}]' # calculates the correct width for e.g. [ 5/52]
sfmt = f'<{{0:^{numlen*2+1}}}> {{1}}'   # and for the status, e.g.              < END >

print(sfmt.format('...', 'testing!'))
for n, step in enumerate(steps):
	print(f'{nfmt} testing {{1}}'.format(n+1, Path('/', step.reldir)))
	step.test()

print(sfmt.format('...', 'building!'))
for n, step in enumerate(steps):
	print(f'{nfmt} building {{1}}'.format(n+1, Path('/', step.reldir)))
	step.exec(sfmt)

stop = time()
print(sfmt.format('END', f'build complete in {stop-start:.2}s! :3'))