##// END OF EJS Templates
Fixed inferring the base name.
cel -
Show More
@@ -1,79 +1,80 b''
1 """The main API for the v2 notebook format.
1 """The main API for the v2 notebook format.
2
2
3 Authors:
3 Authors:
4
4
5 * Brian Granger
5 * Brian Granger
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import os
19 import os
20
20
21 from .nbbase import (
21 from .nbbase import (
22 NotebookNode,
22 NotebookNode,
23 new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet,
23 new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet,
24 new_metadata, new_author
24 new_metadata, new_author
25 )
25 )
26
26
27 from .nbjson import reads as reads_json, writes as writes_json
27 from .nbjson import reads as reads_json, writes as writes_json
28 from .nbjson import reads as read_json, writes as write_json
28 from .nbjson import reads as read_json, writes as write_json
29 from .nbjson import to_notebook as to_notebook_json
29 from .nbjson import to_notebook as to_notebook_json
30
30
31 from .nbxml import reads as reads_xml
31 from .nbxml import reads as reads_xml
32 from .nbxml import reads as read_xml
32 from .nbxml import reads as read_xml
33 from .nbxml import to_notebook as to_notebook_xml
33 from .nbxml import to_notebook as to_notebook_xml
34
34
35 from .nbpy import reads as reads_py, writes as writes_py
35 from .nbpy import reads as reads_py, writes as writes_py
36 from .nbpy import reads as read_py, writes as write_py
36 from .nbpy import reads as read_py, writes as write_py
37 from .nbpy import to_notebook as to_notebook_py
37 from .nbpy import to_notebook as to_notebook_py
38
38
39 from .convert import downgrade, upgrade
39 from .convert import downgrade, upgrade
40
40
41 #-----------------------------------------------------------------------------
41 #-----------------------------------------------------------------------------
42 # Code
42 # Code
43 #-----------------------------------------------------------------------------
43 #-----------------------------------------------------------------------------
44
44
45 def parse_filename(fname):
45 def parse_filename(fname):
46 """Parse a notebook filename.
46 """Parse a notebook filename.
47
47
48 This function takes a notebook filename and returns the notebook
48 This function takes a notebook filename and returns the notebook
49 format (json/py) and the notebook name. This logic can be
49 format (json/py) and the notebook name. This logic can be
50 summarized as follows:
50 summarized as follows:
51
51
52 * notebook.ipynb -> (notebook.ipynb, notebook, json)
52 * notebook.ipynb -> (notebook.ipynb, notebook, json)
53 * notebook.json -> (notebook.json, notebook, json)
53 * notebook.json -> (notebook.json, notebook, json)
54 * notebook.py -> (notebook.py, notebook, py)
54 * notebook.py -> (notebook.py, notebook, py)
55 * notebook -> (notebook.ipynb, notebook, json)
55 * notebook -> (notebook.ipynb, notebook, json)
56
56
57 Parameters
57 Parameters
58 ----------
58 ----------
59 fname : unicode
59 fname : unicode
60 The notebook filename. The filename can use a specific filename
60 The notebook filename. The filename can use a specific filename
61 extention (.ipynb, .json, .py) or none, in which case .ipynb will
61 extention (.ipynb, .json, .py) or none, in which case .ipynb will
62 be assumed.
62 be assumed.
63
63
64 Returns
64 Returns
65 -------
65 -------
66 (fname, name, format) : (unicode, unicode, unicode)
66 (fname, name, format) : (unicode, unicode, unicode)
67 The filename, notebook name and format.
67 The filename, notebook name and format.
68 """
68 """
69 basename, ext = os.path.splitext(fname)
69 basename, ext = os.path.splitext(fname)
70 if ext == u'.ipynb':
70 if ext == u'.ipynb':
71 format = u'json'
71 format = u'json'
72 elif ext == u'.json':
72 elif ext == u'.json':
73 format = u'json'
73 format = u'json'
74 elif ext == u'.py':
74 elif ext == u'.py':
75 format = u'py'
75 format = u'py'
76 else:
76 else:
77 basename = fname
77 fname = fname + u'.ipynb'
78 fname = fname + u'.ipynb'
78 format = u'json'
79 format = u'json'
79 return fname, basename, format
80 return fname, basename, format
@@ -1,76 +1,77 b''
1 """The main API for the v3 notebook format.
1 """The main API for the v3 notebook format.
2
2
3 Authors:
3 Authors:
4
4
5 * Brian Granger
5 * Brian Granger
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import os
19 import os
20
20
21 from .nbbase import (
21 from .nbbase import (
22 NotebookNode,
22 NotebookNode,
23 new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet,
23 new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet,
24 new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor,
24 new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor,
25 nbformat_schema
25 nbformat_schema
26 )
26 )
27
27
28 from .nbjson import reads as reads_json, writes as writes_json
28 from .nbjson import reads as reads_json, writes as writes_json
29 from .nbjson import reads as read_json, writes as write_json
29 from .nbjson import reads as read_json, writes as write_json
30 from .nbjson import to_notebook as to_notebook_json
30 from .nbjson import to_notebook as to_notebook_json
31
31
32 from .nbpy import reads as reads_py, writes as writes_py
32 from .nbpy import reads as reads_py, writes as writes_py
33 from .nbpy import reads as read_py, writes as write_py
33 from .nbpy import reads as read_py, writes as write_py
34 from .nbpy import to_notebook as to_notebook_py
34 from .nbpy import to_notebook as to_notebook_py
35
35
36 from .convert import downgrade, upgrade
36 from .convert import downgrade, upgrade
37
37
38 #-----------------------------------------------------------------------------
38 #-----------------------------------------------------------------------------
39 # Code
39 # Code
40 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
41
41
42 def parse_filename(fname):
42 def parse_filename(fname):
43 """Parse a notebook filename.
43 """Parse a notebook filename.
44
44
45 This function takes a notebook filename and returns the notebook
45 This function takes a notebook filename and returns the notebook
46 format (json/py) and the notebook name. This logic can be
46 format (json/py) and the notebook name. This logic can be
47 summarized as follows:
47 summarized as follows:
48
48
49 * notebook.ipynb -> (notebook.ipynb, notebook, json)
49 * notebook.ipynb -> (notebook.ipynb, notebook, json)
50 * notebook.json -> (notebook.json, notebook, json)
50 * notebook.json -> (notebook.json, notebook, json)
51 * notebook.py -> (notebook.py, notebook, py)
51 * notebook.py -> (notebook.py, notebook, py)
52 * notebook -> (notebook.ipynb, notebook, json)
52 * notebook -> (notebook.ipynb, notebook, json)
53
53
54 Parameters
54 Parameters
55 ----------
55 ----------
56 fname : unicode
56 fname : unicode
57 The notebook filename. The filename can use a specific filename
57 The notebook filename. The filename can use a specific filename
58 extention (.ipynb, .json, .py) or none, in which case .ipynb will
58 extention (.ipynb, .json, .py) or none, in which case .ipynb will
59 be assumed.
59 be assumed.
60
60
61 Returns
61 Returns
62 -------
62 -------
63 (fname, name, format) : (unicode, unicode, unicode)
63 (fname, name, format) : (unicode, unicode, unicode)
64 The filename, notebook name and format.
64 The filename, notebook name and format.
65 """
65 """
66 basename, ext = os.path.splitext(fname)
66 basename, ext = os.path.splitext(fname)
67 if ext == u'.ipynb':
67 if ext == u'.ipynb':
68 format = u'json'
68 format = u'json'
69 elif ext == u'.json':
69 elif ext == u'.json':
70 format = u'json'
70 format = u'json'
71 elif ext == u'.py':
71 elif ext == u'.py':
72 format = u'py'
72 format = u'py'
73 else:
73 else:
74 basename = fname
74 fname = fname + u'.ipynb'
75 fname = fname + u'.ipynb'
75 format = u'json'
76 format = u'json'
76 return fname, basename, format
77 return fname, basename, format
General Comments 0
You need to be logged in to leave comments. Login now