# 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
            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)
        self.status = 'source'
        self.output = None
        self.working = None
        self.differing = set()
        self.dirname, self.basename = os.path.split(self.filename)
        self.stem, self.ext = stem_and_ext(self.basename)
        parentbase = os.path.basename(self.dirname)
        logger.debug("%s found source %s", self.stem, self.filename)
        if parentbase == self.stem:
            parentdir = os.path.dirname(self.dirname)
            self.md5sums = md5files(self.dirname, relative=parentdir)
        else:

# 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

            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)
        self.status = 'source'
        self.output = None
        self.working = None
        self.differing = set()
        self.dirname, self.basename = os.path.split(self.filename)
        self.stem, self.ext = stem_and_ext(self.basename)
        parentbase = os.path.basename(self.dirname)
        logger.debug("%s found source %s", self.stem, self.filename)
        if parentbase == self.stem:
            parentdir = os.path.dirname(self.dirname)
            self.md5sums = md5files(self.dirname, relative=parentdir)
        else:

            self.md5sums = md5files(self.filename, relative=self.dirname)