# 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 logtimings(logmethod):
#     def anon(f):
#         def timing(*args, **kwargs):
# def firstfoundfile(locations):
# def arg_isloglevel(l, defaultlevel=logging.ERROR):
# def arg_isstr(s):
# def arg_isreadablefile(f):
# def arg_isdirectory(d):
# def arg_isexecutable(f):
# def sameFilesystem(d0, d1):
# def stem_and_ext(name):
# def swapdirs(a, b):
# def logfilecontents(logmethod, prefix, fname):
# def conditionallogging(result, prefix, fname):
# def execute(cmd, stdin=None, stdout=None, stderr=None,
#             logdir=None, env=os.environ):
# def isexecutable(f):
# def isreadablefile(f):
# def isstr(s):
# def which(program):
# def writemd5sums(fname, md5s, header=None):
# def md5file(name):
# def statfile(name):
# def md5files(name, relative=None):
# def statfiles(name, relative=None):
# def fileinfo(name, relative=None, func=statfile):


import os
import sys
import errno
import codecs
import logging
from tldp.ldpcollection import LDPDocumentCollection
from tldp.utils import logdir
        '''constructor
        :param dirname: directory name for all output documents

        This directory name is expected to end with the document stem name,
        for example '/path/to/the/collection/Unicode-HOWTO'.  The parent
        directory (e.g. '/path/to/the/collection' must exist already.  The
        output directory itself will be created, or emptied and cleared if
        the document needs to be rebuilt.
        '''
        self.dirname = os.path.abspath(dirname)
        self.stem = os.path.basename(self.dirname)
        super(OutputDirectory, self).__init__(self.dirname, self.stem)
        parent = os.path.dirname(self.dirname)
        if not os.path.isdir(parent):
            logger.critical("Missing output collection directory %s.", parent)
            raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), parent)
        self.status = 'output'
        self.source = source
        self.logdir = os.path.join(self.dirname, logdir)

    def detail(self, widths, verbose, file=sys.stdout):
        template = ' '.join(('{s.status:{w.status}}',
                             '{u:{w.doctype}}',
                             '{s.stem:{w.stem}}'))
        outstr = template.format(s=self, w=widths, u="<unknown>")
        print(outstr, file=file)
        if verbose:
            print('  missing source', file=file)



# 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 logtimings(logmethod):
#     def anon(f):
#         def timing(*args, **kwargs):
# def firstfoundfile(locations):
# def arg_isloglevel(l, defaultlevel=logging.ERROR):
# def arg_isstr(s):
# def arg_isreadablefile(f):
# def arg_isdirectory(d):
# def arg_isexecutable(f):
# def sameFilesystem(d0, d1):
# def stem_and_ext(name):
# def swapdirs(a, b):
# def logfilecontents(logmethod, prefix, fname):
# def conditionallogging(result, prefix, fname):
# def execute(cmd, stdin=None, stdout=None, stderr=None,
#             logdir=None, env=os.environ):
# def isexecutable(f):
# def isreadablefile(f):
# def isstr(s):
# def which(program):
# def writemd5sums(fname, md5s, header=None):
# def md5file(name):
# def statfile(name):
# def md5files(name, relative=None):
# def statfiles(name, relative=None):
# def fileinfo(name, relative=None, func=statfile):


# Path: tldp/outputs.py
import os
import sys
import errno
import codecs
import logging
from tldp.ldpcollection import LDPDocumentCollection
from tldp.utils import logdir

        '''constructor
        :param dirname: directory name for all output documents

        This directory name is expected to end with the document stem name,
        for example '/path/to/the/collection/Unicode-HOWTO'.  The parent
        directory (e.g. '/path/to/the/collection' must exist already.  The
        output directory itself will be created, or emptied and cleared if
        the document needs to be rebuilt.
        '''
        self.dirname = os.path.abspath(dirname)
        self.stem = os.path.basename(self.dirname)
        super(OutputDirectory, self).__init__(self.dirname, self.stem)
        parent = os.path.dirname(self.dirname)
        if not os.path.isdir(parent):
            logger.critical("Missing output collection directory %s.", parent)
            raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), parent)
        self.status = 'output'
        self.source = source
        self.logdir = os.path.join(self.dirname, logdir)

    def detail(self, widths, verbose, file=sys.stdout):
        template = ' '.join(('{s.status:{w.status}}',
                             '{u:{w.doctype}}',
                             '{s.stem:{w.stem}}'))
        outstr = template.format(s=self, w=widths, u="<unknown>")
        print(outstr, file=file)
        if verbose:
            print('  missing source', file=file)



class OutputCollection(LDPDocumentCollection):