##// END OF EJS Templates
Merge pull request #5835 from minrk/v2-typo...
Thomas Kluyver -
r16727:09d3a4ee merge
parent child Browse files
Show More
@@ -1,61 +1,61 b''
1 1 """Code for converting notebooks to and from the v2 format.
2 2
3 3 Authors:
4 4
5 5 * Brian Granger
6 6 * Jonathan Frederic
7 7 """
8 8
9 9 #-----------------------------------------------------------------------------
10 10 # Copyright (C) 2008-2011 The IPython Development Team
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #-----------------------------------------------------------------------------
15 15
16 16 #-----------------------------------------------------------------------------
17 17 # Imports
18 18 #-----------------------------------------------------------------------------
19 19
20 20 from .nbbase import (
21 21 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
22 22 )
23 23
24 24 #-----------------------------------------------------------------------------
25 25 # Code
26 26 #-----------------------------------------------------------------------------
27 27
28 28 def upgrade(nb, from_version=1):
29 29 """Convert a notebook to the v2 format.
30 30
31 31 Parameters
32 32 ----------
33 33 nb : NotebookNode
34 34 The Python representation of the notebook to convert.
35 orig_version : int
36 The original version of the notebook to convert.
35 from_version : int
36 The version of the notebook to convert from.
37 37 """
38 if orig_version == 1:
38 if from_version == 1:
39 39 newnb = new_notebook()
40 40 ws = new_worksheet()
41 41 for cell in nb.cells:
42 42 if cell.cell_type == u'code':
43 43 newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number'))
44 44 elif cell.cell_type == u'text':
45 45 newcell = new_text_cell(u'markdown',source=cell.get('text'))
46 46 ws.cells.append(newcell)
47 47 newnb.worksheets.append(ws)
48 48 return newnb
49 49 else:
50 raise ValueError('Cannot convert a notebook from v%s to v2' % orig_version)
50 raise ValueError('Cannot convert a notebook from v%s to v2' % from_version)
51 51
52 52
53 53 def downgrade(nb):
54 54 """Convert a v2 notebook to v1.
55 55
56 56 Parameters
57 57 ----------
58 58 nb : NotebookNode
59 59 The Python representation of the notebook to convert.
60 60 """
61 61 raise Exception("Downgrade from notebook v2 to v1 is not supported.")
General Comments 0
You need to be logged in to leave comments. Login now