Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50640 views
1
###
2
Node.js interface to nbconvert.
3
###
4
5
misc = require('smc-util/misc')
6
{defaults, required} = misc
7
8
misc_node = require('smc-util-node/misc_node')
9
10
exports.nbconvert = (opts) ->
11
opts = defaults opts,
12
args : required
13
directory : undefined
14
timeout : 30
15
cb : required
16
17
to = undefined
18
j = undefined
19
for i in [0...opts.args.length]
20
if opts.args[i] == '--to'
21
j = i
22
to = opts.args[i+1]
23
break
24
if to == 'sagews'
25
# support sagews convertor, which is its own script, not in nbconvert.
26
command = 'smc-ipynb2sagews'
27
args = opts.args.slice(0, j).concat(opts.args.slice(j+2))
28
else
29
command = 'jupyter'
30
args = ['nbconvert'].concat(opts.args)
31
32
misc_node.execute_code
33
command : command
34
args : args
35
path : opts.directory
36
err_on_exit : true
37
timeout : opts.timeout # in seconds
38
cb : (err, output) =>
39
if err and output?.stderr
40
err = output?.stderr
41
opts.cb(err)
42
43