2017-08-11 14:57:32 +02:00
|
|
|
def task_gen_logo():
|
|
|
|
"""generate versions of the logo in various sizes"""
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2017-08-11 21:26:17 +02:00
|
|
|
def resize_logo(width):
|
2017-08-11 14:57:32 +02:00
|
|
|
with Image.open('assets/logotype.png') as im:
|
|
|
|
im = im.convert('L')
|
2017-08-11 21:26:17 +02:00
|
|
|
height = im.height * width // im.width
|
|
|
|
new = im.resize((width,height), resample=Image.LANCZOS)
|
|
|
|
new.save('static/logotype-{}.png'.format(width), optimize=True)
|
|
|
|
|
|
|
|
widths = (200, 400, 600, 800)
|
|
|
|
for width in widths:
|
|
|
|
yield dict(
|
|
|
|
name=str(width),
|
2017-08-11 21:44:37 +02:00
|
|
|
actions=[(resize_logo, (width,))],
|
2017-08-11 21:26:17 +02:00
|
|
|
targets=[f'static/logotype-{width}.png'],
|
|
|
|
file_dep=['assets/logotype.png'],
|
|
|
|
clean=True,
|
|
|
|
)
|
2017-08-11 14:57:32 +02:00
|
|
|
|
|
|
|
|
2017-08-11 21:26:17 +02:00
|
|
|
def task_copy_asset():
|
2017-08-11 16:41:31 +02:00
|
|
|
import shutil
|
2017-08-12 07:26:06 +02:00
|
|
|
assets = ('icon.png', 'logotype.png', 'settings.js')
|
2017-08-11 21:26:17 +02:00
|
|
|
for asset in assets:
|
|
|
|
yield dict(
|
|
|
|
name=asset,
|
2017-08-11 21:44:37 +02:00
|
|
|
actions=[(lambda asset: shutil.copy(f'assets/{asset}', f'static/{asset}'), (asset,))],
|
2017-08-11 21:26:17 +02:00
|
|
|
targets=[f'static/{asset}'],
|
|
|
|
file_dep=[f'assets/{asset}'],
|
|
|
|
clean=True,
|
|
|
|
)
|
2017-08-11 16:41:31 +02:00
|
|
|
|
|
|
|
def task_minify_css():
|
|
|
|
"""minify css"""
|
|
|
|
|
|
|
|
from csscompressor import compress
|
|
|
|
|
|
|
|
def minify():
|
|
|
|
with open('assets/styles.css') as in_:
|
|
|
|
with open('static/styles.css', 'w') as out:
|
|
|
|
out.write(compress(in_.read()))
|
|
|
|
|
2017-08-11 21:18:40 +02:00
|
|
|
return dict(
|
|
|
|
actions=[minify],
|
|
|
|
targets=['static/styles.css'],
|
|
|
|
file_dep=['assets/styles.css'],
|
|
|
|
clean=True,
|
|
|
|
)
|
2017-08-11 16:41:31 +02:00
|
|
|
|
2017-08-11 20:03:18 +02:00
|
|
|
def task_compress_static():
|
|
|
|
import brotli
|
|
|
|
import gzip
|
|
|
|
|
2017-08-12 01:07:12 +02:00
|
|
|
files = (
|
|
|
|
'static/styles.css',
|
|
|
|
'static/icon.png',
|
|
|
|
'static/logotype.png',
|
|
|
|
'static/version.js',
|
2017-08-12 07:26:06 +02:00
|
|
|
'static/settings.js',
|
2017-08-12 01:07:12 +02:00
|
|
|
) + tuple((f'static/logotype-{width}.png' for width in (200, 400, 600, 800)))
|
2017-08-11 20:03:18 +02:00
|
|
|
|
|
|
|
def compress_brotli(dependencies):
|
|
|
|
for filename in dependencies:
|
|
|
|
with open(filename, 'rb') as in_:
|
|
|
|
with open(filename + '.br', 'wb') as out:
|
|
|
|
out.write(brotli.compress(in_.read()))
|
|
|
|
def compress_gzip(dependencies):
|
|
|
|
for filename in dependencies:
|
|
|
|
with open(filename, 'rb') as in_:
|
|
|
|
with gzip.open(filename + '.gz', 'wb') as out:
|
|
|
|
out.write(in_.read())
|
|
|
|
|
2017-08-11 20:29:48 +02:00
|
|
|
for filename in files:
|
|
|
|
yield dict(
|
|
|
|
file_dep=(filename,),
|
|
|
|
targets=(filename+'.br',),
|
|
|
|
name=filename+'.br',
|
|
|
|
actions=[compress_brotli],
|
|
|
|
clean=True,
|
|
|
|
)
|
|
|
|
yield dict(
|
|
|
|
file_dep=(filename,),
|
|
|
|
targets=(filename+'.gz',),
|
|
|
|
name=filename+'.gz',
|
|
|
|
actions=[compress_gzip],
|
|
|
|
clean=True,
|
|
|
|
)
|
2017-08-11 20:03:18 +02:00
|
|
|
|
2017-08-11 14:57:32 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import doit
|
|
|
|
doit.run(globals())
|