# Path: scribbler/errors.py
# class ScribblerWarning(Warning):
#     pass
# 
# class ScribblerError(Exception):
#     pass
# 
# Path: scribbler/content.py
# class ScribblerContent(object):
#     """
#     Class representing Note and Appendix objects. Must pass the name of
#     the note/appendix, the date it is for, the path to its source file,
#     relative to notebook's notes directory, and the notebook object which
#     contains it.
#     """
#     def __init__(self, name, date, src_path, notebook):
#         self.notebook = notebook
#         self.name = name
#         self.date = date
#         basename = os.path.basename(src_path)
#         for ext in ['md', 'rst', 'html']:
#             if basename.endswith(ext):
#                 self.markup = ext
#                 self.slug = basename[:len(basename)-len(ext)-1]
#                 break
#         else:
#             raise ScribblerError("Unrecognized extension for file '{}'".format(basename))
#         self.src_path = src_path
#         self.html_path = None
#         self.pdf_path = None
#         self.update()
#     
#     def _pdf_path(self):
#         """
#         Returns the path where a PDF file is expected to be, relative to
#         the notebook root.
#         """
#         return os.path.join(self.notebook.PDF_DIR, str(self.slug) + '.pdf')
#     
#     def _html_path(self):
#         """
#         Returns the path where an HTML file is expected to be, relative to
#         the notebook root.
#         """
#         if os.path.basename(os.path.dirname(self.src_path)) == self.notebook.NOTE_DIR:
#             return os.path.join(self.notebook.HTML_DIR, self.notebook.NOTE_DIR, str(self.slug) + '.html')
#         else:
#             return os.path.join(self.notebook.HTML_DIR, 'pages', str(self.slug) + '.html')
#     
#     def update(self):
#         """
#         Updates information about the content.
#         """
#         if not os.path.isfile(os.path.join(self.notebook.location, self.src_path)):
#             raise ScribblerError("Note with path '{}' does not exist".format(self.src_path))
#         self.src_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                          self.src_path))
#         if os.path.isfile(os.path.join(self.notebook.location, self._html_path())):
#             self.html_path = self._html_path()
#         else:
#             self.html_path = None
#         if os.path.isfile(os.path.join(self.notebook.location, self._pdf_path())):
#             self.pdf_path = self._pdf_path()
#             self.pdf_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                              self.pdf_path))
#         else:
#             self.pdf_path = None
#             self.pdf_date = 0
#         
#     def make_pdf(self):
#         """
#         Produces a PDF version of the content from its HTML version, if
#         it requires updating or does not already exist.
#         """
#         src = os.path.join(self.notebook.location, self.html_path)
#         dest = os.path.join(self.notebook.location, self._pdf_path())
#         pdfkit.from_file(src, dest, options=self.notebook.pdf_settings)


import os.path
import subprocess
import shutil
import yaml
import pdfkit
from copy import copy
from datetime import date, datetime
from pickle import dump, load
from glob import glob
from pelican.utils import slugify
from scribbler.PyPDF2 import PdfFileMerger
from .errors import ScribblerWarning, ScribblerError
from .content import ScribblerContent
        for key, val in settings.iteritems():
            if key in self.DEFAULT_SETTINGS and not isinstance(val,type(self.DEFAULT_SETTINGS[key])):
                raise TypeError('Key "{}" in settings has value of type {}'.format(key,type(val).__name__))
        tmp = settings['filetypes']
        settings['filetypes'] = copy(self.FILETYPES)
        settings['filetypes'].update(tmp)
        settings['markdown extensions'].extend(self.MARKDOWN_PLUGINS)
        pplugins = copy(self.PELICAN_PLUGINS)
        pplugins[-1] = pplugins[-1].format(self.location)
        settings['plugins'] = pplugins + settings['plugins']
        settings['bibfile'] = os.path.join(self.location, settings['bibfile'])
        self._settings = settings
        self.settings_mod_time = yaml_time
        return settings

    @property
    def pelican_settings(self):
        '''
        Returns a dictionary with the settings to be provided for Pelican.
        '''
        self.settings # Called so that self.settings_mod_time will be updated
        if self._pelican_settings and self.settings_mod_time <= self.psettings_mod_time:
            return self._pelican_settings
        psettings = copy(self.DEFAULT_PELICAN_SETTINGS)
        psettings['OUTPUT_PATH'] = os.path.join(self.location,psettings['OUTPUT_PATH'])
        psettings['PATH'] = os.path.join(self.location,psettings['PATH'])
        for key, val in self.settings.iteritems():
            if key in self.PELICAN_MAPPING:
                psettings[self.PELICAN_MAPPING[key]] = self.settings[key]
            elif key not in self.NO_MAPPING:

# Path: scribbler/errors.py
# class ScribblerWarning(Warning):
#     pass
# 
# class ScribblerError(Exception):
#     pass
# 
# Path: scribbler/content.py
# class ScribblerContent(object):
#     """
#     Class representing Note and Appendix objects. Must pass the name of
#     the note/appendix, the date it is for, the path to its source file,
#     relative to notebook's notes directory, and the notebook object which
#     contains it.
#     """
#     def __init__(self, name, date, src_path, notebook):
#         self.notebook = notebook
#         self.name = name
#         self.date = date
#         basename = os.path.basename(src_path)
#         for ext in ['md', 'rst', 'html']:
#             if basename.endswith(ext):
#                 self.markup = ext
#                 self.slug = basename[:len(basename)-len(ext)-1]
#                 break
#         else:
#             raise ScribblerError("Unrecognized extension for file '{}'".format(basename))
#         self.src_path = src_path
#         self.html_path = None
#         self.pdf_path = None
#         self.update()
#     
#     def _pdf_path(self):
#         """
#         Returns the path where a PDF file is expected to be, relative to
#         the notebook root.
#         """
#         return os.path.join(self.notebook.PDF_DIR, str(self.slug) + '.pdf')
#     
#     def _html_path(self):
#         """
#         Returns the path where an HTML file is expected to be, relative to
#         the notebook root.
#         """
#         if os.path.basename(os.path.dirname(self.src_path)) == self.notebook.NOTE_DIR:
#             return os.path.join(self.notebook.HTML_DIR, self.notebook.NOTE_DIR, str(self.slug) + '.html')
#         else:
#             return os.path.join(self.notebook.HTML_DIR, 'pages', str(self.slug) + '.html')
#     
#     def update(self):
#         """
#         Updates information about the content.
#         """
#         if not os.path.isfile(os.path.join(self.notebook.location, self.src_path)):
#             raise ScribblerError("Note with path '{}' does not exist".format(self.src_path))
#         self.src_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                          self.src_path))
#         if os.path.isfile(os.path.join(self.notebook.location, self._html_path())):
#             self.html_path = self._html_path()
#         else:
#             self.html_path = None
#         if os.path.isfile(os.path.join(self.notebook.location, self._pdf_path())):
#             self.pdf_path = self._pdf_path()
#             self.pdf_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                              self.pdf_path))
#         else:
#             self.pdf_path = None
#             self.pdf_date = 0
#         
#     def make_pdf(self):
#         """
#         Produces a PDF version of the content from its HTML version, if
#         it requires updating or does not already exist.
#         """
#         src = os.path.join(self.notebook.location, self.html_path)
#         dest = os.path.join(self.notebook.location, self._pdf_path())
#         pdfkit.from_file(src, dest, options=self.notebook.pdf_settings)


# Path: scribbler/notebook.py
import os.path
import subprocess
import shutil
import yaml
import pdfkit
from copy import copy
from datetime import date, datetime
from pickle import dump, load
from glob import glob
from pelican.utils import slugify
from scribbler.PyPDF2 import PdfFileMerger
from .errors import ScribblerWarning, ScribblerError
from .content import ScribblerContent

        for key, val in settings.iteritems():
            if key in self.DEFAULT_SETTINGS and not isinstance(val,type(self.DEFAULT_SETTINGS[key])):
                raise TypeError('Key "{}" in settings has value of type {}'.format(key,type(val).__name__))
        tmp = settings['filetypes']
        settings['filetypes'] = copy(self.FILETYPES)
        settings['filetypes'].update(tmp)
        settings['markdown extensions'].extend(self.MARKDOWN_PLUGINS)
        pplugins = copy(self.PELICAN_PLUGINS)
        pplugins[-1] = pplugins[-1].format(self.location)
        settings['plugins'] = pplugins + settings['plugins']
        settings['bibfile'] = os.path.join(self.location, settings['bibfile'])
        self._settings = settings
        self.settings_mod_time = yaml_time
        return settings

    @property
    def pelican_settings(self):
        '''
        Returns a dictionary with the settings to be provided for Pelican.
        '''
        self.settings # Called so that self.settings_mod_time will be updated
        if self._pelican_settings and self.settings_mod_time <= self.psettings_mod_time:
            return self._pelican_settings
        psettings = copy(self.DEFAULT_PELICAN_SETTINGS)
        psettings['OUTPUT_PATH'] = os.path.join(self.location,psettings['OUTPUT_PATH'])
        psettings['PATH'] = os.path.join(self.location,psettings['PATH'])
        for key, val in self.settings.iteritems():
            if key in self.PELICAN_MAPPING:
                psettings[self.PELICAN_MAPPING[key]] = self.settings[key]
            elif key not in self.NO_MAPPING:

                raise ScribblerWarning('Unrecognized setting: `{}`'.format(key))