# Path: tldp/sources.py
# class SourceCollection(LDPDocumentCollection):
#     '''a dict-like container for SourceDocument objects
# 
#     The key in the SourceCollection is the stem name of the document, which
#     allows convenient access and guarantees non-collision.
# 
#     The use of the stem as a key works conveniently with the
#     OutputCollection which uses the same strategy on OutputDirectory.
#     '''
#     def __init__(self, dirnames=None):
#         '''construct a SourceCollection
# 
#         delegates most responsibility to function scansourcedirs
#         '''
#         if dirnames is None:
#             return
#         self.update(scansourcedirs(dirnames))
# 
# Path: tldp/outputs.py
# class OutputCollection(LDPDocumentCollection):
#     '''a dict-like container for OutputDirectory objects
# 
#     The key of an OutputCollection is the stem name of the document, which
#     allows convenient access and guaranteed non-collision.
# 
#     The use of the stem as a key works conveniently with the
#     SourceCollection which uses the same strategy on SourceDocuments.
#     '''
#     def __init__(self, dirname=None):
#         '''construct an OutputCollection
# 
#         If dirname is not supplied, OutputCollection is basically, a dict().
#         If dirname is supplied, then OutputCollection scans the filesystem for
#         subdirectories of dirname and creates an OutputDirectory for each
#         subdir.  Each subdir name is used as the stem (or key) for holding the
#         OutputDirectory in the OutputCollection.
# 
#         For example, consider the following directory tree:
# 
#             en
#             ├── Latvian-HOWTO
#             ├── Scanner-HOWTO
#             ├── UUCP-HOWTO
#             └── Wireless-HOWTO
# 
#         If called like OutputCollection("en"), the result in memory would be
#         a structure resembling this:
# 
#             OutputCollection("/path/en") = {
#               "Latvian-HOWTO":  OutputDirectory("/path/en/Latvian-HOWTO")
#               "Scanner-HOWTO":  OutputDirectory("/path/en/Scanner-HOWTO")
#               "UUCP-HOWTO":     OutputDirectory("/path/en/UUCP-HOWTO")
#               "Wireless-HOWTO": OutputDirectory("/path/en/Wireless-HOWTO")
#               }
# 
#         '''
#         if dirname is None:
#             return
#         elif not os.path.isdir(dirname):
#             logger.critical("Output collection dir %s must already exist.",
#                             dirname)
#             raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), dirname)
#         for fname in sorted(os.listdir(dirname), key=lambda x: x.lower()):
#             name = os.path.join(dirname, fname)
#             if not os.path.isdir(name):
#                 logger.info("Skipping non-directory %s (in %s)", name, dirname)
#                 continue
#             logger.debug("Found directory %s (in %s)", name, dirname)
#             o = OutputDirectory(name)
#             assert o.stem not in self
#             self[o.stem] = o


import copy
import logging
from collections import OrderedDict
from tldp.sources import SourceCollection
from tldp.outputs import OutputCollection
    documents.
    '''
    def __repr__(self):
        return '<%s: %d published, %d orphan, %d new, %d stale, %d broken>' % (
               self.__class__.__name__,
               len(self.published),
               len(self.orphan),
               len(self.new),
               len(self.stale),
               len(self.broken),)

    def __init__(self, pubdir, sourcedirs):
        '''construct an Inventory

        pubdir: path to the OutputCollection

        sourcedirs: a list of directories which could be passed to the
          SourceCollection object; essentially a directory containing
          SourceDocuments; for example LDP/LDP/howto/linuxdoc and
          LDP/LDP/guide/docbook
        '''
        self.output = OutputCollection(pubdir)
        self.source = SourceCollection(sourcedirs)
        s = copy.deepcopy(self.source)
        o = copy.deepcopy(self.output)
        sset = set(s.keys())
        oset = set(o.keys())

        # -- orphan identification
        #

# Path: tldp/sources.py
# class SourceCollection(LDPDocumentCollection):
#     '''a dict-like container for SourceDocument objects
# 
#     The key in the SourceCollection is the stem name of the document, which
#     allows convenient access and guarantees non-collision.
# 
#     The use of the stem as a key works conveniently with the
#     OutputCollection which uses the same strategy on OutputDirectory.
#     '''
#     def __init__(self, dirnames=None):
#         '''construct a SourceCollection
# 
#         delegates most responsibility to function scansourcedirs
#         '''
#         if dirnames is None:
#             return
#         self.update(scansourcedirs(dirnames))
# 
# Path: tldp/outputs.py
# class OutputCollection(LDPDocumentCollection):
#     '''a dict-like container for OutputDirectory objects
# 
#     The key of an OutputCollection is the stem name of the document, which
#     allows convenient access and guaranteed non-collision.
# 
#     The use of the stem as a key works conveniently with the
#     SourceCollection which uses the same strategy on SourceDocuments.
#     '''
#     def __init__(self, dirname=None):
#         '''construct an OutputCollection
# 
#         If dirname is not supplied, OutputCollection is basically, a dict().
#         If dirname is supplied, then OutputCollection scans the filesystem for
#         subdirectories of dirname and creates an OutputDirectory for each
#         subdir.  Each subdir name is used as the stem (or key) for holding the
#         OutputDirectory in the OutputCollection.
# 
#         For example, consider the following directory tree:
# 
#             en
#             ├── Latvian-HOWTO
#             ├── Scanner-HOWTO
#             ├── UUCP-HOWTO
#             └── Wireless-HOWTO
# 
#         If called like OutputCollection("en"), the result in memory would be
#         a structure resembling this:
# 
#             OutputCollection("/path/en") = {
#               "Latvian-HOWTO":  OutputDirectory("/path/en/Latvian-HOWTO")
#               "Scanner-HOWTO":  OutputDirectory("/path/en/Scanner-HOWTO")
#               "UUCP-HOWTO":     OutputDirectory("/path/en/UUCP-HOWTO")
#               "Wireless-HOWTO": OutputDirectory("/path/en/Wireless-HOWTO")
#               }
# 
#         '''
#         if dirname is None:
#             return
#         elif not os.path.isdir(dirname):
#             logger.critical("Output collection dir %s must already exist.",
#                             dirname)
#             raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), dirname)
#         for fname in sorted(os.listdir(dirname), key=lambda x: x.lower()):
#             name = os.path.join(dirname, fname)
#             if not os.path.isdir(name):
#                 logger.info("Skipping non-directory %s (in %s)", name, dirname)
#                 continue
#             logger.debug("Found directory %s (in %s)", name, dirname)
#             o = OutputDirectory(name)
#             assert o.stem not in self
#             self[o.stem] = o


# Path: tldp/inventory.py
import copy
import logging
from collections import OrderedDict
from tldp.sources import SourceCollection
from tldp.outputs import OutputCollection

    documents.
    '''
    def __repr__(self):
        return '<%s: %d published, %d orphan, %d new, %d stale, %d broken>' % (
               self.__class__.__name__,
               len(self.published),
               len(self.orphan),
               len(self.new),
               len(self.stale),
               len(self.broken),)

    def __init__(self, pubdir, sourcedirs):
        '''construct an Inventory

        pubdir: path to the OutputCollection

        sourcedirs: a list of directories which could be passed to the
          SourceCollection object; essentially a directory containing
          SourceDocuments; for example LDP/LDP/howto/linuxdoc and
          LDP/LDP/guide/docbook
        '''
        self.output = OutputCollection(pubdir)
        self.source = SourceCollection(sourcedirs)
        s = copy.deepcopy(self.source)
        o = copy.deepcopy(self.output)
        sset = set(s.keys())
        oset = set(o.keys())

        # -- orphan identification
        #

        self.orphan = OutputCollection()