-
Notifications
You must be signed in to change notification settings - Fork 24
/
convert.py
55 lines (44 loc) · 1.91 KB
/
convert.py
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
#!/usr/bin/env python3
import logging
import os
import platform
import resource
import time
if platform.system() == 'Darwin':
# Raise the rather small default 256-open-files-only limit to 1024
no_files = 1024
resource.setrlimit(resource.RLIMIT_NOFILE, (no_files, no_files))
from nbpages import make_parser, run_parsed, make_html_index
if __name__ == '__main__':
args = make_parser()
args.add_argument("--notebook-path", default='.', dest='nb_path',
help="A relative path to notebooks you wish to execute.")
args.add_argument("--parallel", "-p", default=False, dest='parallel', action="store_true",
help="Run notebooks in parallel")
args = args.parse_args()
if args.template_file is None and os.path.exists('nb_html.tpl'):
args.template_file = 'nb_html.tpl'
if args.exclude is None:
# If there is an "exclude_notebooks" file, use that to find which ones to
# skip. Format is one pattern per line, "#" for comments.
# note that this will be ignored if exclude is given at the command line.
to_exclude = []
if os.path.isfile('exclude_notebooks'):
with open('exclude_notebooks') as f:
for line in f:
if line.strip() != '':
to_exclude.append(line.strip().split('#')[0])
if to_exclude:
args.exclude = ','.join(to_exclude)
if args.report_file is None:
args.report_file = "junit_report.xml"
print("Starting at {}".format(time.ctime()))
try:
converted = run_parsed(args.nb_path, output_type='HTML', args=args, timeout=72000)
except Exception as e:
print("ERROR: {}".format(e))
print("args={}".format(args))
raise e
logging.getLogger('nbpages').info('Generating index.html')
make_html_index(converted, './index.tpl')
print("Finishing at {}".format(time.ctime()))