# Path: tldp/ldpcollection.py
# class LDPDocumentCollection(collections.MutableMapping):
#     '''a dict-like container for DocumentCollection objects
# 
#     Intended to be subclassed.
# 
#     Implements all the usual dictionary stuff, but also provides sorted
#     lists of documents in the collection.
#     '''
#     def __repr__(self):
#         return '<%s:(%s docs)>' % (self.__class__.__name__, len(self))
# 
#     def __delitem__(self, key):
#         del self.__dict__[key]
# 
#     def __getitem__(self, key):
#         return self.__dict__[key]
# 
#     def __setitem__(self, key, value):
#         self.__dict__[key] = value
# 
#     def __iter__(self):
#         return iter(self.__dict__)
# 
#     def __len__(self):
#         return len(self.__dict__)
# 
#     def iterkeys(self):
#         return iter(self.keys)
# 
#     def itervalues(self):
#         for key in sorted(self, key=lambda x: x.lower()):
#             yield self[key]
# 
#     def iteritems(self):
#         for key in self.keys:
#             yield (key, self[key])
# 
#     def keys(self):
#         return sorted(self, key=lambda x: x.lower())
# 
#     def items(self):
#         return [(key, self[key]) for key in self.keys()]
# 
#     def values(self):
#         return [self[key] for key in self.keys()]
# 
# Path: tldp/utils.py
# def md5files(name, relative=None):
#     '''get all of the MD5s for files from here downtree'''
#     return fileinfo(name, relative=relative, func=md5file)
# 
# def stem_and_ext(name):
#     '''return (stem, ext) for any relative or absolute filename'''
#     return os.path.splitext(os.path.basename(os.path.normpath(name)))
# 
# Path: tldp/typeguesser.py
# def getDoctypeMembers(membertype):
# def getDoctypeClasses():
# def guess(fname):


import os
import sys
import errno
import logging
from tldp.ldpcollection import LDPDocumentCollection
from tldp.utils import md5files, stem_and_ext
from tldp.typeguesser import guess, knownextensions

        There are two important attributes.  First, the document type guesser
        will try to infer the doctype (from file extension and signature).
        Note that it is not a fatal error if document type cannot be guessed,
        but the document will not be able to be processed.  Second, it is
        useful during the decision-making process to know if any of the source
        files are newer than the output files. Thus, the stat() information
        for every file in the source document directory (or just the single
        source document file) will be collected.
        '''
        self.filename = os.path.abspath(filename)

        if not os.path.exists(self.filename):
            fn = self.filename
            logger.critical("Missing source document: %s", fn)
            raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), fn)

        if os.path.isdir(self.filename):
            self.filename = sourcedoc_fromdir(self.filename)
        elif os.path.isfile(self.filename):
            pass
        else:
            # -- we did not receive a useable document file or directory name
            self.filename = None

        if self.filename is None:
            fn = filename
            logger.critical("Source document is not a plain file: %s", fn)
            raise ValueError(fn + " not identifiable as a document")


# Path: tldp/ldpcollection.py
# class LDPDocumentCollection(collections.MutableMapping):
#     '''a dict-like container for DocumentCollection objects
# 
#     Intended to be subclassed.
# 
#     Implements all the usual dictionary stuff, but also provides sorted
#     lists of documents in the collection.
#     '''
#     def __repr__(self):
#         return '<%s:(%s docs)>' % (self.__class__.__name__, len(self))
# 
#     def __delitem__(self, key):
#         del self.__dict__[key]
# 
#     def __getitem__(self, key):
#         return self.__dict__[key]
# 
#     def __setitem__(self, key, value):
#         self.__dict__[key] = value
# 
#     def __iter__(self):
#         return iter(self.__dict__)
# 
#     def __len__(self):
#         return len(self.__dict__)
# 
#     def iterkeys(self):
#         return iter(self.keys)
# 
#     def itervalues(self):
#         for key in sorted(self, key=lambda x: x.lower()):
#             yield self[key]
# 
#     def iteritems(self):
#         for key in self.keys:
#             yield (key, self[key])
# 
#     def keys(self):
#         return sorted(self, key=lambda x: x.lower())
# 
#     def items(self):
#         return [(key, self[key]) for key in self.keys()]
# 
#     def values(self):
#         return [self[key] for key in self.keys()]
# 
# Path: tldp/utils.py
# def md5files(name, relative=None):
#     '''get all of the MD5s for files from here downtree'''
#     return fileinfo(name, relative=relative, func=md5file)
# 
# def stem_and_ext(name):
#     '''return (stem, ext) for any relative or absolute filename'''
#     return os.path.splitext(os.path.basename(os.path.normpath(name)))
# 
# Path: tldp/typeguesser.py
# def getDoctypeMembers(membertype):
# def getDoctypeClasses():
# def guess(fname):


# Path: tldp/sources.py
import os
import sys
import errno
import logging
from tldp.ldpcollection import LDPDocumentCollection
from tldp.utils import md5files, stem_and_ext
from tldp.typeguesser import guess, knownextensions


        There are two important attributes.  First, the document type guesser
        will try to infer the doctype (from file extension and signature).
        Note that it is not a fatal error if document type cannot be guessed,
        but the document will not be able to be processed.  Second, it is
        useful during the decision-making process to know if any of the source
        files are newer than the output files. Thus, the stat() information
        for every file in the source document directory (or just the single
        source document file) will be collected.
        '''
        self.filename = os.path.abspath(filename)

        if not os.path.exists(self.filename):
            fn = self.filename
            logger.critical("Missing source document: %s", fn)
            raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), fn)

        if os.path.isdir(self.filename):
            self.filename = sourcedoc_fromdir(self.filename)
        elif os.path.isfile(self.filename):
            pass
        else:
            # -- we did not receive a useable document file or directory name
            self.filename = None

        if self.filename is None:
            fn = filename
            logger.critical("Source document is not a plain file: %s", fn)
            raise ValueError(fn + " not identifiable as a document")


        self.doctype = guess(self.filename)