We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
The PDF option for `--post` should work with lowercase 
Right now to get a PDF out of nbconvert you have to to

```
ipython nbconvert --to latex --post PDF foo.ipynb
```

Many users will try `pdf` instead and the error message is very confusing.  We should just make it work with lowercase.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `IPython/nbconvert/nbconvertapp.py`
Content:
```
1 #!/usr/bin/env python
2 """NBConvert is a utility for conversion of .ipynb files.
3 
4 Command-line interface for the NbConvert conversion utility.
5 """
6 #-----------------------------------------------------------------------------
7 #Copyright (c) 2013, the IPython Development Team.
8 #
9 #Distributed under the terms of the Modified BSD License.
10 #
11 #The full license is in the file COPYING.txt, distributed with this software.
12 #-----------------------------------------------------------------------------
13 
14 #-----------------------------------------------------------------------------
15 #Imports
16 #-----------------------------------------------------------------------------
17 
18 # Stdlib imports
19 from __future__ import print_function
20 
21 import logging
22 import sys
23 import os
24 import glob
25 
26 # From IPython
27 from IPython.core.application import BaseIPythonApplication, base_aliases, base_flags
28 from IPython.config import catch_config_error, Configurable
29 from IPython.utils.traitlets import (
30     Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,
31 )
32 from IPython.utils.importstring import import_item
33 from IPython.utils.text import dedent
34 
35 from .exporters.export import get_export_names, exporter_map
36 from IPython.nbconvert import exporters, transformers, writers, post_processors
37 from .utils.base import NbConvertBase
38 from .utils.exceptions import ConversionException
39 
40 #-----------------------------------------------------------------------------
41 #Classes and functions
42 #-----------------------------------------------------------------------------
43 
44 class DottedOrNone(DottedObjectName):
45     """
46     A string holding a valid dotted object name in Python, such as A.b3._c
47     Also allows for None type."""
48     
49     default_value = u''
50 
51     def validate(self, obj, value):
52         if value is not None and len(value) > 0:
53             return super(DottedOrNone, self).validate(obj, value)
54         else:
55             return value
56             
57 nbconvert_aliases = {}
58 nbconvert_aliases.update(base_aliases)
59 nbconvert_aliases.update({
60     'to' : 'NbConvertApp.export_format',
61     'template' : 'Exporter.template_file',
62     'notebooks' : 'NbConvertApp.notebooks',
63     'writer' : 'NbConvertApp.writer_class',
64     'post': 'NbConvertApp.post_processor_class',
65     'output': 'NbConvertApp.output_base'
66 })
67 
68 nbconvert_flags = {}
69 nbconvert_flags.update(base_flags)
70 nbconvert_flags.update({
71     'stdout' : (
72         {'NbConvertApp' : {'writer_class' : "StdoutWriter"}},
73         "Write notebook output to stdout instead of files."
74         )
75 })
76 
77 
78 class NbConvertApp(BaseIPythonApplication):
79     """Application used to convert to and from notebook file type (*.ipynb)"""
80 
81     name = 'ipython-nbconvert'
82     aliases = nbconvert_aliases
83     flags = nbconvert_flags
84     
85     def _log_level_default(self):
86         return logging.INFO
87     
88     def _classes_default(self):
89         classes = [NbConvertBase]
90         for pkg in (exporters, transformers, writers):
91             for name in dir(pkg):
92                 cls = getattr(pkg, name)
93                 if isinstance(cls, type) and issubclass(cls, Configurable):
94                     classes.append(cls)
95         return classes
96 
97     description = Unicode(
98         u"""This application is used to convert notebook files (*.ipynb)
99         to various other formats.
100 
101         WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.""")
102 
103     output_base = Unicode('', config=True, help='''overwrite base name use for output files.
104             can only  be use when converting one notebook at a time.
105             ''')
106 
107     examples = Unicode(u"""
108         The simplest way to use nbconvert is
109         
110         > ipython nbconvert mynotebook.ipynb
111         
112         which will convert mynotebook.ipynb to the default format (probably HTML).
113         
114         You can specify the export format with `--to`.
115         Options include {0}
116         
117         > ipython nbconvert --to latex mynotebook.ipnynb
118 
119         Both HTML and LaTeX support multiple output templates. LaTeX includes
120         'basic', 'book', and 'article'.  HTML includes 'basic' and 'full'.  You 
121         can specify the flavor of the format used.
122 
123         > ipython nbconvert --to html --template basic mynotebook.ipynb
124         
125         You can also pipe the output to stdout, rather than a file
126         
127         > ipython nbconvert mynotebook.ipynb --stdout
128 
129         A post-processor can be used to compile a PDF
130 
131         > ipython nbconvert mynotebook.ipynb --to latex --post PDF
132         
133         You can get (and serve) a Reveal.js-powered slideshow
134         
135         > ipython nbconvert myslides.ipynb --to slides --post serve
136         
137         Multiple notebooks can be given at the command line in a couple of 
138         different ways:
139   
140         > ipython nbconvert notebook*.ipynb
141         > ipython nbconvert notebook1.ipynb notebook2.ipynb
142         
143         or you can specify the notebooks list in a config file, containing::
144         
145             c.NbConvertApp.notebooks = ["my_notebook.ipynb"]
146         
147         > ipython nbconvert --config mycfg.py
148         """.format(get_export_names()))
149 
150     # Writer specific variables
151     writer = Instance('IPython.nbconvert.writers.base.WriterBase',  
152                       help="""Instance of the writer class used to write the 
153                       results of the conversion.""")
154     writer_class = DottedObjectName('FilesWriter', config=True, 
155                                     help="""Writer class used to write the 
156                                     results of the conversion""")
157     writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',
158                       'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',
159                       'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}
160     writer_factory = Type()
161 
162     def _writer_class_changed(self, name, old, new):
163         if new in self.writer_aliases:
164             new = self.writer_aliases[new]
165         self.writer_factory = import_item(new)
166 
167     # Post-processor specific variables
168     post_processor = Instance('IPython.nbconvert.post_processors.base.PostProcessorBase',  
169                       help="""Instance of the PostProcessor class used to write the 
170                       results of the conversion.""")
171 
172     post_processor_class = DottedOrNone(config=True, 
173                                     help="""PostProcessor class used to write the 
174                                     results of the conversion""")
175     post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',
176                               'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}
177     post_processor_factory = Type()
178 
179     def _post_processor_class_changed(self, name, old, new):
180         if new in self.post_processor_aliases:
181             new = self.post_processor_aliases[new]
182         if new:
183             self.post_processor_factory = import_item(new)
184 
185 
186     # Other configurable variables
187     export_format = CaselessStrEnum(get_export_names(),
188         default_value="html",
189         config=True,
190         help="""The export format to be used."""
191     )
192 
193     notebooks = List([], config=True, help="""List of notebooks to convert.
194                      Wildcards are supported.
195                      Filenames passed positionally will be added to the list.
196                      """)
197 
198     @catch_config_error
199     def initialize(self, argv=None):
200         super(NbConvertApp, self).initialize(argv)
201         self.init_syspath()
202         self.init_notebooks()
203         self.init_writer()
204         self.init_post_processor()
205 
206 
207 
208     def init_syspath(self):
209         """
210         Add the cwd to the sys.path ($PYTHONPATH)
211         """
212         sys.path.insert(0, os.getcwd())
213         
214 
215     def init_notebooks(self):
216         """Construct the list of notebooks.
217         If notebooks are passed on the command-line,
218         they override notebooks specified in config files.
219         Glob each notebook to replace notebook patterns with filenames.
220         """
221 
222         # Specifying notebooks on the command-line overrides (rather than adds)
223         # the notebook list
224         if self.extra_args:
225             patterns = self.extra_args
226         else:
227             patterns = self.notebooks
228 
229         # Use glob to replace all the notebook patterns with filenames.
230         filenames = []
231         for pattern in patterns:
232             
233             # Use glob to find matching filenames.  Allow the user to convert 
234             # notebooks without having to type the extension.
235             globbed_files = glob.glob(pattern)
236             globbed_files.extend(glob.glob(pattern + '.ipynb'))
237             if not globbed_files:
238                 self.log.warn("pattern %r matched no files", pattern)
239 
240             for filename in globbed_files:
241                 if not filename in filenames:
242                     filenames.append(filename)
243         self.notebooks = filenames
244 
245     def init_writer(self):
246         """
247         Initialize the writer (which is stateless)
248         """
249         self._writer_class_changed(None, self.writer_class, self.writer_class)
250         self.writer = self.writer_factory(parent=self)
251 
252     def init_post_processor(self):
253         """
254         Initialize the post_processor (which is stateless)
255         """
256         self._post_processor_class_changed(None, self.post_processor_class, 
257             self.post_processor_class)
258         if self.post_processor_factory:
259             self.post_processor = self.post_processor_factory(parent=self)
260 
261     def start(self):
262         """
263         Ran after initialization completed
264         """
265         super(NbConvertApp, self).start()
266         self.convert_notebooks()
267 
268     def convert_notebooks(self):
269         """
270         Convert the notebooks in the self.notebook traitlet
271         """
272         # Export each notebook
273         conversion_success = 0
274 
275         if self.output_base != '' and len(self.notebooks) > 1:
276             self.log.error(
277             """UsageError: --output flag or `NbConvertApp.output_base` config option
278             cannot be used when converting multiple notebooks.
279             """)
280             self.exit(1)
281         
282         exporter = exporter_map[self.export_format](config=self.config)
283 
284         for notebook_filename in self.notebooks:
285             self.log.info("Converting notebook %s to %s", notebook_filename, self.export_format)
286 
287             # Get a unique key for the notebook and set it in the resources object.
288             basename = os.path.basename(notebook_filename)
289             notebook_name = basename[:basename.rfind('.')]
290             if self.output_base:
291                 notebook_name = self.output_base
292             resources = {}
293             resources['unique_key'] = notebook_name
294             resources['output_files_dir'] = '%s_files' % notebook_name
295             self.log.info("Support files will be in %s", os.path.join(resources['output_files_dir'], ''))
296 
297             # Try to export
298             try:
299                 output, resources = exporter.from_filename(notebook_filename, resources=resources)
300             except ConversionException as e:
301                 self.log.error("Error while converting '%s'", notebook_filename,
302                       exc_info=True)
303                 self.exit(1)
304             else:
305                 write_resultes = self.writer.write(output, resources, notebook_name=notebook_name)
306 
307                 #Post-process if post processor has been defined.
308                 if hasattr(self, 'post_processor') and self.post_processor:
309                     self.post_processor(write_resultes)
310                 conversion_success += 1
311 
312         # If nothing was converted successfully, help the user.
313         if conversion_success == 0:
314             self.print_help()
315             sys.exit(-1)
316             
317 #-----------------------------------------------------------------------------
318 # Main entry point
319 #-----------------------------------------------------------------------------
320 
321 launch_new_instance = NbConvertApp.launch_instance
322
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py
--- a/IPython/nbconvert/nbconvertapp.py
+++ b/IPython/nbconvert/nbconvertapp.py
@@ -154,14 +154,14 @@
     writer_class = DottedObjectName('FilesWriter', config=True, 
                                     help="""Writer class used to write the 
                                     results of the conversion""")
-    writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',
-                      'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',
-                      'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}
+    writer_aliases = {'fileswriter': 'IPython.nbconvert.writers.files.FilesWriter',
+                      'debugwriter': 'IPython.nbconvert.writers.debug.DebugWriter',
+                      'stdoutwriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}
     writer_factory = Type()
 
     def _writer_class_changed(self, name, old, new):
-        if new in self.writer_aliases:
-            new = self.writer_aliases[new]
+        if new.lower() in self.writer_aliases:
+            new = self.writer_aliases[new.lower()]
         self.writer_factory = import_item(new)
 
     # Post-processor specific variables
@@ -172,13 +172,13 @@
     post_processor_class = DottedOrNone(config=True, 
                                     help="""PostProcessor class used to write the 
                                     results of the conversion""")
-    post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',
+    post_processor_aliases = {'pdf': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',
                               'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}
     post_processor_factory = Type()
 
     def _post_processor_class_changed(self, name, old, new):
-        if new in self.post_processor_aliases:
-            new = self.post_processor_aliases[new]
+        if new.lower() in self.post_processor_aliases:
+            new = self.post_processor_aliases[new.lower()]
         if new:
             self.post_processor_factory = import_item(new)

{"golden_diff": "diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py\n--- a/IPython/nbconvert/nbconvertapp.py\n+++ b/IPython/nbconvert/nbconvertapp.py\n@@ -154,14 +154,14 @@\n     writer_class = DottedObjectName('FilesWriter', config=True, \n                                     help=\"\"\"Writer class used to write the \n                                     results of the conversion\"\"\")\n-    writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',\n-                      'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',\n-                      'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}\n+    writer_aliases = {'fileswriter': 'IPython.nbconvert.writers.files.FilesWriter',\n+                      'debugwriter': 'IPython.nbconvert.writers.debug.DebugWriter',\n+                      'stdoutwriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}\n     writer_factory = Type()\n \n     def _writer_class_changed(self, name, old, new):\n-        if new in self.writer_aliases:\n-            new = self.writer_aliases[new]\n+        if new.lower() in self.writer_aliases:\n+            new = self.writer_aliases[new.lower()]\n         self.writer_factory = import_item(new)\n \n     # Post-processor specific variables\n@@ -172,13 +172,13 @@\n     post_processor_class = DottedOrNone(config=True, \n                                     help=\"\"\"PostProcessor class used to write the \n                                     results of the conversion\"\"\")\n-    post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',\n+    post_processor_aliases = {'pdf': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',\n                               'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}\n     post_processor_factory = Type()\n \n     def _post_processor_class_changed(self, name, old, new):\n-        if new in self.post_processor_aliases:\n-            new = self.post_processor_aliases[new]\n+        if new.lower() in self.post_processor_aliases:\n+            new = self.post_processor_aliases[new.lower()]\n         if new:\n             self.post_processor_factory = import_item(new)\n", "issue": "The PDF option for `--post` should work with lowercase \nRight now to get a PDF out of nbconvert you have to to\n\n```\nipython nbconvert --to latex --post PDF foo.ipynb\n```\n\nMany users will try `pdf` instead and the error message is very confusing.  We should just make it work with lowercase.\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"NBConvert is a utility for conversion of .ipynb files.\n\nCommand-line interface for the NbConvert conversion utility.\n\"\"\"\n#-----------------------------------------------------------------------------\n#Copyright (c) 2013, the IPython Development Team.\n#\n#Distributed under the terms of the Modified BSD License.\n#\n#The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n#Imports\n#-----------------------------------------------------------------------------\n\n# Stdlib imports\nfrom __future__ import print_function\n\nimport logging\nimport sys\nimport os\nimport glob\n\n# From IPython\nfrom IPython.core.application import BaseIPythonApplication, base_aliases, base_flags\nfrom IPython.config import catch_config_error, Configurable\nfrom IPython.utils.traitlets import (\n    Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,\n)\nfrom IPython.utils.importstring import import_item\nfrom IPython.utils.text import dedent\n\nfrom .exporters.export import get_export_names, exporter_map\nfrom IPython.nbconvert import exporters, transformers, writers, post_processors\nfrom .utils.base import NbConvertBase\nfrom .utils.exceptions import ConversionException\n\n#-----------------------------------------------------------------------------\n#Classes and functions\n#-----------------------------------------------------------------------------\n\nclass DottedOrNone(DottedObjectName):\n    \"\"\"\n    A string holding a valid dotted object name in Python, such as A.b3._c\n    Also allows for None type.\"\"\"\n    \n    default_value = u''\n\n    def validate(self, obj, value):\n        if value is not None and len(value) > 0:\n            return super(DottedOrNone, self).validate(obj, value)\n        else:\n            return value\n            \nnbconvert_aliases = {}\nnbconvert_aliases.update(base_aliases)\nnbconvert_aliases.update({\n    'to' : 'NbConvertApp.export_format',\n    'template' : 'Exporter.template_file',\n    'notebooks' : 'NbConvertApp.notebooks',\n    'writer' : 'NbConvertApp.writer_class',\n    'post': 'NbConvertApp.post_processor_class',\n    'output': 'NbConvertApp.output_base'\n})\n\nnbconvert_flags = {}\nnbconvert_flags.update(base_flags)\nnbconvert_flags.update({\n    'stdout' : (\n        {'NbConvertApp' : {'writer_class' : \"StdoutWriter\"}},\n        \"Write notebook output to stdout instead of files.\"\n        )\n})\n\n\nclass NbConvertApp(BaseIPythonApplication):\n    \"\"\"Application used to convert to and from notebook file type (*.ipynb)\"\"\"\n\n    name = 'ipython-nbconvert'\n    aliases = nbconvert_aliases\n    flags = nbconvert_flags\n    \n    def _log_level_default(self):\n        return logging.INFO\n    \n    def _classes_default(self):\n        classes = [NbConvertBase]\n        for pkg in (exporters, transformers, writers):\n            for name in dir(pkg):\n                cls = getattr(pkg, name)\n                if isinstance(cls, type) and issubclass(cls, Configurable):\n                    classes.append(cls)\n        return classes\n\n    description = Unicode(\n        u\"\"\"This application is used to convert notebook files (*.ipynb)\n        to various other formats.\n\n        WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.\"\"\")\n\n    output_base = Unicode('', config=True, help='''overwrite base name use for output files.\n            can only  be use when converting one notebook at a time.\n            ''')\n\n    examples = Unicode(u\"\"\"\n        The simplest way to use nbconvert is\n        \n        > ipython nbconvert mynotebook.ipynb\n        \n        which will convert mynotebook.ipynb to the default format (probably HTML).\n        \n        You can specify the export format with `--to`.\n        Options include {0}\n        \n        > ipython nbconvert --to latex mynotebook.ipnynb\n\n        Both HTML and LaTeX support multiple output templates. LaTeX includes\n        'basic', 'book', and 'article'.  HTML includes 'basic' and 'full'.  You \n        can specify the flavor of the format used.\n\n        > ipython nbconvert --to html --template basic mynotebook.ipynb\n        \n        You can also pipe the output to stdout, rather than a file\n        \n        > ipython nbconvert mynotebook.ipynb --stdout\n\n        A post-processor can be used to compile a PDF\n\n        > ipython nbconvert mynotebook.ipynb --to latex --post PDF\n        \n        You can get (and serve) a Reveal.js-powered slideshow\n        \n        > ipython nbconvert myslides.ipynb --to slides --post serve\n        \n        Multiple notebooks can be given at the command line in a couple of \n        different ways:\n  \n        > ipython nbconvert notebook*.ipynb\n        > ipython nbconvert notebook1.ipynb notebook2.ipynb\n        \n        or you can specify the notebooks list in a config file, containing::\n        \n            c.NbConvertApp.notebooks = [\"my_notebook.ipynb\"]\n        \n        > ipython nbconvert --config mycfg.py\n        \"\"\".format(get_export_names()))\n\n    # Writer specific variables\n    writer = Instance('IPython.nbconvert.writers.base.WriterBase',  \n                      help=\"\"\"Instance of the writer class used to write the \n                      results of the conversion.\"\"\")\n    writer_class = DottedObjectName('FilesWriter', config=True, \n                                    help=\"\"\"Writer class used to write the \n                                    results of the conversion\"\"\")\n    writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',\n                      'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',\n                      'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}\n    writer_factory = Type()\n\n    def _writer_class_changed(self, name, old, new):\n        if new in self.writer_aliases:\n            new = self.writer_aliases[new]\n        self.writer_factory = import_item(new)\n\n    # Post-processor specific variables\n    post_processor = Instance('IPython.nbconvert.post_processors.base.PostProcessorBase',  \n                      help=\"\"\"Instance of the PostProcessor class used to write the \n                      results of the conversion.\"\"\")\n\n    post_processor_class = DottedOrNone(config=True, \n                                    help=\"\"\"PostProcessor class used to write the \n                                    results of the conversion\"\"\")\n    post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',\n                              'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}\n    post_processor_factory = Type()\n\n    def _post_processor_class_changed(self, name, old, new):\n        if new in self.post_processor_aliases:\n            new = self.post_processor_aliases[new]\n        if new:\n            self.post_processor_factory = import_item(new)\n\n\n    # Other configurable variables\n    export_format = CaselessStrEnum(get_export_names(),\n        default_value=\"html\",\n        config=True,\n        help=\"\"\"The export format to be used.\"\"\"\n    )\n\n    notebooks = List([], config=True, help=\"\"\"List of notebooks to convert.\n                     Wildcards are supported.\n                     Filenames passed positionally will be added to the list.\n                     \"\"\")\n\n    @catch_config_error\n    def initialize(self, argv=None):\n        super(NbConvertApp, self).initialize(argv)\n        self.init_syspath()\n        self.init_notebooks()\n        self.init_writer()\n        self.init_post_processor()\n\n\n\n    def init_syspath(self):\n        \"\"\"\n        Add the cwd to the sys.path ($PYTHONPATH)\n        \"\"\"\n        sys.path.insert(0, os.getcwd())\n        \n\n    def init_notebooks(self):\n        \"\"\"Construct the list of notebooks.\n        If notebooks are passed on the command-line,\n        they override notebooks specified in config files.\n        Glob each notebook to replace notebook patterns with filenames.\n        \"\"\"\n\n        # Specifying notebooks on the command-line overrides (rather than adds)\n        # the notebook list\n        if self.extra_args:\n            patterns = self.extra_args\n        else:\n            patterns = self.notebooks\n\n        # Use glob to replace all the notebook patterns with filenames.\n        filenames = []\n        for pattern in patterns:\n            \n            # Use glob to find matching filenames.  Allow the user to convert \n            # notebooks without having to type the extension.\n            globbed_files = glob.glob(pattern)\n            globbed_files.extend(glob.glob(pattern + '.ipynb'))\n            if not globbed_files:\n                self.log.warn(\"pattern %r matched no files\", pattern)\n\n            for filename in globbed_files:\n                if not filename in filenames:\n                    filenames.append(filename)\n        self.notebooks = filenames\n\n    def init_writer(self):\n        \"\"\"\n        Initialize the writer (which is stateless)\n        \"\"\"\n        self._writer_class_changed(None, self.writer_class, self.writer_class)\n        self.writer = self.writer_factory(parent=self)\n\n    def init_post_processor(self):\n        \"\"\"\n        Initialize the post_processor (which is stateless)\n        \"\"\"\n        self._post_processor_class_changed(None, self.post_processor_class, \n            self.post_processor_class)\n        if self.post_processor_factory:\n            self.post_processor = self.post_processor_factory(parent=self)\n\n    def start(self):\n        \"\"\"\n        Ran after initialization completed\n        \"\"\"\n        super(NbConvertApp, self).start()\n        self.convert_notebooks()\n\n    def convert_notebooks(self):\n        \"\"\"\n        Convert the notebooks in the self.notebook traitlet\n        \"\"\"\n        # Export each notebook\n        conversion_success = 0\n\n        if self.output_base != '' and len(self.notebooks) > 1:\n            self.log.error(\n            \"\"\"UsageError: --output flag or `NbConvertApp.output_base` config option\n            cannot be used when converting multiple notebooks.\n            \"\"\")\n            self.exit(1)\n        \n        exporter = exporter_map[self.export_format](config=self.config)\n\n        for notebook_filename in self.notebooks:\n            self.log.info(\"Converting notebook %s to %s\", notebook_filename, self.export_format)\n\n            # Get a unique key for the notebook and set it in the resources object.\n            basename = os.path.basename(notebook_filename)\n            notebook_name = basename[:basename.rfind('.')]\n            if self.output_base:\n                notebook_name = self.output_base\n            resources = {}\n            resources['unique_key'] = notebook_name\n            resources['output_files_dir'] = '%s_files' % notebook_name\n            self.log.info(\"Support files will be in %s\", os.path.join(resources['output_files_dir'], ''))\n\n            # Try to export\n            try:\n                output, resources = exporter.from_filename(notebook_filename, resources=resources)\n            except ConversionException as e:\n                self.log.error(\"Error while converting '%s'\", notebook_filename,\n                      exc_info=True)\n                self.exit(1)\n            else:\n                write_resultes = self.writer.write(output, resources, notebook_name=notebook_name)\n\n                #Post-process if post processor has been defined.\n                if hasattr(self, 'post_processor') and self.post_processor:\n                    self.post_processor(write_resultes)\n                conversion_success += 1\n\n        # If nothing was converted successfully, help the user.\n        if conversion_success == 0:\n            self.print_help()\n            sys.exit(-1)\n            \n#-----------------------------------------------------------------------------\n# Main entry point\n#-----------------------------------------------------------------------------\n\nlaunch_new_instance = NbConvertApp.launch_instance\n", "path": "IPython/nbconvert/nbconvertapp.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"NBConvert is a utility for conversion of .ipynb files.\n\nCommand-line interface for the NbConvert conversion utility.\n\"\"\"\n#-----------------------------------------------------------------------------\n#Copyright (c) 2013, the IPython Development Team.\n#\n#Distributed under the terms of the Modified BSD License.\n#\n#The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n#Imports\n#-----------------------------------------------------------------------------\n\n# Stdlib imports\nfrom __future__ import print_function\n\nimport logging\nimport sys\nimport os\nimport glob\n\n# From IPython\nfrom IPython.core.application import BaseIPythonApplication, base_aliases, base_flags\nfrom IPython.config import catch_config_error, Configurable\nfrom IPython.utils.traitlets import (\n    Unicode, List, Instance, DottedObjectName, Type, CaselessStrEnum,\n)\nfrom IPython.utils.importstring import import_item\nfrom IPython.utils.text import dedent\n\nfrom .exporters.export import get_export_names, exporter_map\nfrom IPython.nbconvert import exporters, transformers, writers, post_processors\nfrom .utils.base import NbConvertBase\nfrom .utils.exceptions import ConversionException\n\n#-----------------------------------------------------------------------------\n#Classes and functions\n#-----------------------------------------------------------------------------\n\nclass DottedOrNone(DottedObjectName):\n    \"\"\"\n    A string holding a valid dotted object name in Python, such as A.b3._c\n    Also allows for None type.\"\"\"\n    \n    default_value = u''\n\n    def validate(self, obj, value):\n        if value is not None and len(value) > 0:\n            return super(DottedOrNone, self).validate(obj, value)\n        else:\n            return value\n            \nnbconvert_aliases = {}\nnbconvert_aliases.update(base_aliases)\nnbconvert_aliases.update({\n    'to' : 'NbConvertApp.export_format',\n    'template' : 'Exporter.template_file',\n    'notebooks' : 'NbConvertApp.notebooks',\n    'writer' : 'NbConvertApp.writer_class',\n    'post': 'NbConvertApp.post_processor_class',\n    'output': 'NbConvertApp.output_base'\n})\n\nnbconvert_flags = {}\nnbconvert_flags.update(base_flags)\nnbconvert_flags.update({\n    'stdout' : (\n        {'NbConvertApp' : {'writer_class' : \"StdoutWriter\"}},\n        \"Write notebook output to stdout instead of files.\"\n        )\n})\n\n\nclass NbConvertApp(BaseIPythonApplication):\n    \"\"\"Application used to convert to and from notebook file type (*.ipynb)\"\"\"\n\n    name = 'ipython-nbconvert'\n    aliases = nbconvert_aliases\n    flags = nbconvert_flags\n    \n    def _log_level_default(self):\n        return logging.INFO\n    \n    def _classes_default(self):\n        classes = [NbConvertBase]\n        for pkg in (exporters, transformers, writers):\n            for name in dir(pkg):\n                cls = getattr(pkg, name)\n                if isinstance(cls, type) and issubclass(cls, Configurable):\n                    classes.append(cls)\n        return classes\n\n    description = Unicode(\n        u\"\"\"This application is used to convert notebook files (*.ipynb)\n        to various other formats.\n\n        WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.\"\"\")\n\n    output_base = Unicode('', config=True, help='''overwrite base name use for output files.\n            can only  be use when converting one notebook at a time.\n            ''')\n\n    examples = Unicode(u\"\"\"\n        The simplest way to use nbconvert is\n        \n        > ipython nbconvert mynotebook.ipynb\n        \n        which will convert mynotebook.ipynb to the default format (probably HTML).\n        \n        You can specify the export format with `--to`.\n        Options include {0}\n        \n        > ipython nbconvert --to latex mynotebook.ipnynb\n\n        Both HTML and LaTeX support multiple output templates. LaTeX includes\n        'basic', 'book', and 'article'.  HTML includes 'basic' and 'full'.  You \n        can specify the flavor of the format used.\n\n        > ipython nbconvert --to html --template basic mynotebook.ipynb\n        \n        You can also pipe the output to stdout, rather than a file\n        \n        > ipython nbconvert mynotebook.ipynb --stdout\n\n        A post-processor can be used to compile a PDF\n\n        > ipython nbconvert mynotebook.ipynb --to latex --post PDF\n        \n        You can get (and serve) a Reveal.js-powered slideshow\n        \n        > ipython nbconvert myslides.ipynb --to slides --post serve\n        \n        Multiple notebooks can be given at the command line in a couple of \n        different ways:\n  \n        > ipython nbconvert notebook*.ipynb\n        > ipython nbconvert notebook1.ipynb notebook2.ipynb\n        \n        or you can specify the notebooks list in a config file, containing::\n        \n            c.NbConvertApp.notebooks = [\"my_notebook.ipynb\"]\n        \n        > ipython nbconvert --config mycfg.py\n        \"\"\".format(get_export_names()))\n\n    # Writer specific variables\n    writer = Instance('IPython.nbconvert.writers.base.WriterBase',  \n                      help=\"\"\"Instance of the writer class used to write the \n                      results of the conversion.\"\"\")\n    writer_class = DottedObjectName('FilesWriter', config=True, \n                                    help=\"\"\"Writer class used to write the \n                                    results of the conversion\"\"\")\n    writer_aliases = {'fileswriter': 'IPython.nbconvert.writers.files.FilesWriter',\n                      'debugwriter': 'IPython.nbconvert.writers.debug.DebugWriter',\n                      'stdoutwriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}\n    writer_factory = Type()\n\n    def _writer_class_changed(self, name, old, new):\n        if new.lower() in self.writer_aliases:\n            new = self.writer_aliases[new.lower()]\n        self.writer_factory = import_item(new)\n\n    # Post-processor specific variables\n    post_processor = Instance('IPython.nbconvert.post_processors.base.PostProcessorBase',  \n                      help=\"\"\"Instance of the PostProcessor class used to write the \n                      results of the conversion.\"\"\")\n\n    post_processor_class = DottedOrNone(config=True, \n                                    help=\"\"\"PostProcessor class used to write the \n                                    results of the conversion\"\"\")\n    post_processor_aliases = {'pdf': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',\n                              'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}\n    post_processor_factory = Type()\n\n    def _post_processor_class_changed(self, name, old, new):\n        if new.lower() in self.post_processor_aliases:\n            new = self.post_processor_aliases[new.lower()]\n        if new:\n            self.post_processor_factory = import_item(new)\n\n\n    # Other configurable variables\n    export_format = CaselessStrEnum(get_export_names(),\n        default_value=\"html\",\n        config=True,\n        help=\"\"\"The export format to be used.\"\"\"\n    )\n\n    notebooks = List([], config=True, help=\"\"\"List of notebooks to convert.\n                     Wildcards are supported.\n                     Filenames passed positionally will be added to the list.\n                     \"\"\")\n\n    @catch_config_error\n    def initialize(self, argv=None):\n        super(NbConvertApp, self).initialize(argv)\n        self.init_syspath()\n        self.init_notebooks()\n        self.init_writer()\n        self.init_post_processor()\n\n\n\n    def init_syspath(self):\n        \"\"\"\n        Add the cwd to the sys.path ($PYTHONPATH)\n        \"\"\"\n        sys.path.insert(0, os.getcwd())\n        \n\n    def init_notebooks(self):\n        \"\"\"Construct the list of notebooks.\n        If notebooks are passed on the command-line,\n        they override notebooks specified in config files.\n        Glob each notebook to replace notebook patterns with filenames.\n        \"\"\"\n\n        # Specifying notebooks on the command-line overrides (rather than adds)\n        # the notebook list\n        if self.extra_args:\n            patterns = self.extra_args\n        else:\n            patterns = self.notebooks\n\n        # Use glob to replace all the notebook patterns with filenames.\n        filenames = []\n        for pattern in patterns:\n            \n            # Use glob to find matching filenames.  Allow the user to convert \n            # notebooks without having to type the extension.\n            globbed_files = glob.glob(pattern)\n            globbed_files.extend(glob.glob(pattern + '.ipynb'))\n            if not globbed_files:\n                self.log.warn(\"pattern %r matched no files\", pattern)\n\n            for filename in globbed_files:\n                if not filename in filenames:\n                    filenames.append(filename)\n        self.notebooks = filenames\n\n    def init_writer(self):\n        \"\"\"\n        Initialize the writer (which is stateless)\n        \"\"\"\n        self._writer_class_changed(None, self.writer_class, self.writer_class)\n        self.writer = self.writer_factory(parent=self)\n\n    def init_post_processor(self):\n        \"\"\"\n        Initialize the post_processor (which is stateless)\n        \"\"\"\n        self._post_processor_class_changed(None, self.post_processor_class, \n            self.post_processor_class)\n        if self.post_processor_factory:\n            self.post_processor = self.post_processor_factory(parent=self)\n\n    def start(self):\n        \"\"\"\n        Ran after initialization completed\n        \"\"\"\n        super(NbConvertApp, self).start()\n        self.convert_notebooks()\n\n    def convert_notebooks(self):\n        \"\"\"\n        Convert the notebooks in the self.notebook traitlet\n        \"\"\"\n        # Export each notebook\n        conversion_success = 0\n\n        if self.output_base != '' and len(self.notebooks) > 1:\n            self.log.error(\n            \"\"\"UsageError: --output flag or `NbConvertApp.output_base` config option\n            cannot be used when converting multiple notebooks.\n            \"\"\")\n            self.exit(1)\n        \n        exporter = exporter_map[self.export_format](config=self.config)\n\n        for notebook_filename in self.notebooks:\n            self.log.info(\"Converting notebook %s to %s\", notebook_filename, self.export_format)\n\n            # Get a unique key for the notebook and set it in the resources object.\n            basename = os.path.basename(notebook_filename)\n            notebook_name = basename[:basename.rfind('.')]\n            if self.output_base:\n                notebook_name = self.output_base\n            resources = {}\n            resources['unique_key'] = notebook_name\n            resources['output_files_dir'] = '%s_files' % notebook_name\n            self.log.info(\"Support files will be in %s\", os.path.join(resources['output_files_dir'], ''))\n\n            # Try to export\n            try:\n                output, resources = exporter.from_filename(notebook_filename, resources=resources)\n            except ConversionException as e:\n                self.log.error(\"Error while converting '%s'\", notebook_filename,\n                      exc_info=True)\n                self.exit(1)\n            else:\n                write_resultes = self.writer.write(output, resources, notebook_name=notebook_name)\n\n                #Post-process if post processor has been defined.\n                if hasattr(self, 'post_processor') and self.post_processor:\n                    self.post_processor(write_resultes)\n                conversion_success += 1\n\n        # If nothing was converted successfully, help the user.\n        if conversion_success == 0:\n            self.print_help()\n            sys.exit(-1)\n            \n#-----------------------------------------------------------------------------\n# Main entry point\n#-----------------------------------------------------------------------------\n\nlaunch_new_instance = NbConvertApp.launch_instance\n", "path": "IPython/nbconvert/nbconvertapp.py"}]}