# 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
                                     '.' + ext)
        basename = name + '.' + markup
        path = os.path.join(self.location, self.APPE_DIR, basename)
        out = open(path, 'w')
        try:
            out.write(MARKUP_OPTIONS[markup].format(title))
            out.close()
        except KeyError as e:
            out.close()
            os.remove(path)
            raise e
        self.appendices[basename] = ScribblerContent(title, '????-??-??',
                                                     os.path.join(self.APPE_DIR,
                                                     basename), self)
        self.save(self.storage_file)
        return path

    def addnote(self, date, title, path, overwrite=False):
        """
        Add a record of a note in an existing file (PATH), not previously
        registered with Scribbler. Note has TITLE and DATE specified.
        """
        try:
            datetime.strptime(date, '%Y-%m-%d')
        except:
            raise ScribblerError('Incorrectly formatted date; date format '
                             'should be YYYY-MM-DD')
        basename = os.path.relpath(os.path.abspath(path), os.path.join(self.location, self.NOTE_DIR))
        if basename in self.notes and not overwrite:
            raise ScribblerError('Note with file `{}` already exists.'.format(basename))

# 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

                                     '.' + ext)
        basename = name + '.' + markup
        path = os.path.join(self.location, self.APPE_DIR, basename)
        out = open(path, 'w')
        try:
            out.write(MARKUP_OPTIONS[markup].format(title))
            out.close()
        except KeyError as e:
            out.close()
            os.remove(path)
            raise e
        self.appendices[basename] = ScribblerContent(title, '????-??-??',
                                                     os.path.join(self.APPE_DIR,
                                                     basename), self)
        self.save(self.storage_file)
        return path

    def addnote(self, date, title, path, overwrite=False):
        """
        Add a record of a note in an existing file (PATH), not previously
        registered with Scribbler. Note has TITLE and DATE specified.
        """
        try:
            datetime.strptime(date, '%Y-%m-%d')
        except:
            raise ScribblerError('Incorrectly formatted date; date format '
                             'should be YYYY-MM-DD')
        basename = os.path.relpath(os.path.abspath(path), os.path.join(self.location, self.NOTE_DIR))
        if basename in self.notes and not overwrite:
            raise ScribblerError('Note with file `{}` already exists.'.format(basename))

        self.notes[basename] = ScribblerContent(title, date,