2 # This script takes an ipython notebook as an argument and rewrites the file
3 # with metadata stripped to make change tracking with git easier.
10 if not os
.path
.exists(infile
):
11 sys
.exit('command line argument must be an existing filename')
12 tempfile
= infile
+'.tmp'
14 with
open(infile
, 'r') as fh
:
15 json_in
= json
.load(fh
)
17 nb_metadata
= json_in
["metadata"]
18 def strip_output_from_cell(cell
):
21 if "execution_count" in cell
:
22 cell
["execution_count"] = None
24 for cell
in json_in
["cells"]:
25 strip_output_from_cell(cell
)
27 with
open(tempfile
, 'w') as fh
:
28 json
.dump(json_in
, fh
, sort_keys
=True, indent
=1, separators
=(",",": "))
29 shutil
.move(tempfile
, infile
)