##// 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 """Code for converting notebooks to and from the v2 format.
1 """Code for converting notebooks to and from the v2 format.
2
2
3 Authors:
3 Authors:
4
4
5 * Brian Granger
5 * Brian Granger
6 * Jonathan Frederic
6 * Jonathan Frederic
7 """
7 """
8
8
9 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
10 # Copyright (C) 2008-2011 The IPython Development Team
10 # Copyright (C) 2008-2011 The IPython Development Team
11 #
11 #
12 # Distributed under the terms of the BSD License. The full license is in
12 # Distributed under the terms of the BSD License. The full license is in
13 # the file COPYING, distributed as part of this software.
13 # the file COPYING, distributed as part of this software.
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15
15
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 # Imports
17 # Imports
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19
19
20 from .nbbase import (
20 from .nbbase import (
21 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
21 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
22 )
22 )
23
23
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 # Code
25 # Code
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27
27
28 def upgrade(nb, from_version=1):
28 def upgrade(nb, from_version=1):
29 """Convert a notebook to the v2 format.
29 """Convert a notebook to the v2 format.
30
30
31 Parameters
31 Parameters
32 ----------
32 ----------
33 nb : NotebookNode
33 nb : NotebookNode
34 The Python representation of the notebook to convert.
34 The Python representation of the notebook to convert.
35 orig_version : int
35 from_version : int
36 The original version of the notebook to convert.
36 The version of the notebook to convert from.
37 """
37 """
38 if orig_version == 1:
38 if from_version == 1:
39 newnb = new_notebook()
39 newnb = new_notebook()
40 ws = new_worksheet()
40 ws = new_worksheet()
41 for cell in nb.cells:
41 for cell in nb.cells:
42 if cell.cell_type == u'code':
42 if cell.cell_type == u'code':
43 newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number'))
43 newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number'))
44 elif cell.cell_type == u'text':
44 elif cell.cell_type == u'text':
45 newcell = new_text_cell(u'markdown',source=cell.get('text'))
45 newcell = new_text_cell(u'markdown',source=cell.get('text'))
46 ws.cells.append(newcell)
46 ws.cells.append(newcell)
47 newnb.worksheets.append(ws)
47 newnb.worksheets.append(ws)
48 return newnb
48 return newnb
49 else:
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 def downgrade(nb):
53 def downgrade(nb):
54 """Convert a v2 notebook to v1.
54 """Convert a v2 notebook to v1.
55
55
56 Parameters
56 Parameters
57 ----------
57 ----------
58 nb : NotebookNode
58 nb : NotebookNode
59 The Python representation of the notebook to convert.
59 The Python representation of the notebook to convert.
60 """
60 """
61 raise Exception("Downgrade from notebook v2 to v1 is not supported.")
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