|
@@ -1,11 +1,12 @@
|
|
import argparse
|
|
import argparse
|
|
|
|
+from functools import lru_cache
|
|
from jinja2 import Environment, FileSystemLoader, contextfilter
|
|
from jinja2 import Environment, FileSystemLoader, contextfilter
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
from os import walk, makedirs, listdir, symlink, readlink
|
|
from os import walk, makedirs, listdir, symlink, readlink
|
|
from os.path import join, exists, splitext, split, islink, isdir
|
|
from os.path import join, exists, splitext, split, islink, isdir
|
|
from shutil import rmtree, copy2, copystat, Error
|
|
from shutil import rmtree, copy2, copystat, Error
|
|
from time import sleep
|
|
from time import sleep
|
|
-from functools import lru_cache
|
|
|
|
|
|
+from traceback import print_exc
|
|
|
|
|
|
#TODO: load from config file (and watch it too)
|
|
#TODO: load from config file (and watch it too)
|
|
LANGUAGES = 'languages'
|
|
LANGUAGES = 'languages'
|
|
@@ -195,15 +196,24 @@ def gen_root(args):
|
|
def gen_static(args):
|
|
def gen_static(args):
|
|
copytree(STATIC, join(args.target, 'static'))
|
|
copytree(STATIC, join(args.target, 'static'))
|
|
|
|
|
|
|
|
+def save_generate(generator, args, msg):
|
|
|
|
+ print(f'* {msg}')
|
|
|
|
+ try:
|
|
|
|
+ generator(args)
|
|
|
|
+ print(' done!')
|
|
|
|
+ except:
|
|
|
|
+ print_exc()
|
|
|
|
+ return False
|
|
|
|
+ return True
|
|
|
|
+
|
|
# Runtime
|
|
# Runtime
|
|
|
|
|
|
def run(args):
|
|
def run(args):
|
|
print('initial compilation')
|
|
print('initial compilation')
|
|
init_gen(args)
|
|
init_gen(args)
|
|
- gen_layout(args)
|
|
|
|
- gen_root(args)
|
|
|
|
- gen_static(args)
|
|
|
|
- print(' done')
|
|
|
|
|
|
+ save_generate(gen_layout, args, 'generating layout')
|
|
|
|
+ save_generate(gen_root, args, 'copying root files')
|
|
|
|
+ save_generate(gen_static, args, 'copying static dir')
|
|
|
|
|
|
if not args.watch:
|
|
if not args.watch:
|
|
return
|
|
return
|
|
@@ -222,24 +232,18 @@ def run(args):
|
|
new_source_mt = mtimes(args.source)
|
|
new_source_mt = mtimes(args.source)
|
|
new_source_mt.update(mtimes(LANGUAGES))
|
|
new_source_mt.update(mtimes(LANGUAGES))
|
|
if source_mt != new_source_mt:
|
|
if source_mt != new_source_mt:
|
|
- print('recompiling layout')
|
|
|
|
source_mt = new_source_mt
|
|
source_mt = new_source_mt
|
|
- gen_layout(args)
|
|
|
|
- print(' done!')
|
|
|
|
|
|
+ save_generate(gen_layout, args, 'recompiling layout')
|
|
|
|
|
|
new_root_mt = mtimes(ROOT)
|
|
new_root_mt = mtimes(ROOT)
|
|
if root_mt != new_root_mt:
|
|
if root_mt != new_root_mt:
|
|
- print('copying root files')
|
|
|
|
root_mt = new_root_mt
|
|
root_mt = new_root_mt
|
|
- gen_root(args)
|
|
|
|
- print(' done!')
|
|
|
|
|
|
+ save_generate(gen_root, args, 'copying root files')
|
|
|
|
|
|
new_static_mt = mtimes(STATIC)
|
|
new_static_mt = mtimes(STATIC)
|
|
if static_mt != new_static_mt:
|
|
if static_mt != new_static_mt:
|
|
- print('copying static files')
|
|
|
|
static_mt = new_static_mt
|
|
static_mt = new_static_mt
|
|
- gen_static(args)
|
|
|
|
- print(' done!')
|
|
|
|
|
|
+ save_generate(gen_static, args, 'copying static files')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser("Site generator")
|
|
parser = argparse.ArgumentParser("Site generator")
|