Show More
@@ -1,50 +1,50 b'' | |||
|
1 | 1 | """ fabfile to prepare the notebook """ |
|
2 | 2 | |
|
3 | 3 | from fabric.api import local,lcd |
|
4 | 4 | from fabric.utils import abort |
|
5 | 5 | import os |
|
6 | 6 | from distutils.version import LooseVersion as V |
|
7 | 7 | from subprocess import check_output |
|
8 | 8 | |
|
9 | 9 | pjoin = os.path.join |
|
10 | 10 | static_dir = 'static' |
|
11 | 11 | components_dir = os.path.join(static_dir, 'components') |
|
12 | 12 | |
|
13 | 13 | min_less_version = '1.4.0' |
|
14 | 14 | max_less_version = '1.5.0' # exclusive |
|
15 | 15 | |
|
16 | 16 | def css(minify=True, verbose=False): |
|
17 | 17 | """generate the css from less files""" |
|
18 | 18 | for name in ('style', 'ipython'): |
|
19 | 19 | source = pjoin('style', "%s.less" % name) |
|
20 | 20 | target = pjoin('style', "%s.min.css" % name) |
|
21 | 21 | _compile_less(source, target, minify, verbose) |
|
22 | 22 | |
|
23 | 23 | def _to_bool(b): |
|
24 | 24 | if not b in ['True', 'False', True, False]: |
|
25 | 25 | abort('boolean expected, got: %s' % b) |
|
26 | 26 | return (b in ['True', True]) |
|
27 | 27 | |
|
28 | 28 | def _compile_less(source, target, minify=True, verbose=False): |
|
29 | 29 | """Compile a less file by source and target relative to static_dir""" |
|
30 | 30 | minify = _to_bool(minify) |
|
31 | 31 | verbose = _to_bool(verbose) |
|
32 | 32 | min_flag = '-x' if minify is True else '' |
|
33 | 33 | ver_flag = '--verbose' if verbose is True else '' |
|
34 | 34 | |
|
35 | 35 | # pin less to 1.4 |
|
36 | 36 | try: |
|
37 | out = check_output(['lessc', '--version']) | |
|
37 | out = check_output(['lessc', '--version']) | |
|
38 | 38 | except OSError as err: |
|
39 | 39 | raise ValueError("Unable to find lessc. Please install lessc >= %s and < %s " \ |
|
40 | 40 | % (min_less_version, max_less_version)) |
|
41 | 41 | out = out.decode('utf8', 'replace') |
|
42 | 42 | less_version = out.split()[1] |
|
43 | 43 | if V(less_version) < V(min_less_version): |
|
44 | 44 | raise ValueError("lessc too old: %s < %s" % (less_version, min_less_version)) |
|
45 | 45 | if V(less_version) >= V(max_less_version): |
|
46 | 46 | raise ValueError("lessc too new: %s >= %s" % (less_version, max_less_version)) |
|
47 | 47 | |
|
48 | 48 | with lcd(static_dir): |
|
49 | 49 | local('lessc {min_flag} {ver_flag} {source} {target}'.format(**locals())) |
|
50 | 50 |
General Comments 0
You need to be logged in to leave comments.
Login now