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