# 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
        self.new = SourceCollection()
        for doc in sset.difference(oset):
            self.new[doc] = s[doc]
            del s[doc]
            self.new[doc].status = 'new'
        logger.debug("Identified %d new documents: %r.", len(self.new),
                     self.new.keys())

        # -- published identification; source and output should be same size
        assert len(s) == len(o)
        for stem, odoc in o.items():
            sdoc = s[stem]
            sdoc.output = odoc
            odoc.source = sdoc
            sdoc.status = sdoc.output.status = 'published'
        self.published = s
        logger.debug("Identified %d published documents.", len(self.published))

        # -- broken identification
        #
        self.broken = SourceCollection()
        for stem, sdoc in s.items():
            if not sdoc.output.iscomplete:
                self.broken[stem] = sdoc
                sdoc.status = sdoc.output.status = 'broken'
        logger.debug("Identified %d broken documents: %r.", len(self.broken),
                     self.broken.keys())

        # -- stale 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

        self.new = SourceCollection()
        for doc in sset.difference(oset):
            self.new[doc] = s[doc]
            del s[doc]
            self.new[doc].status = 'new'
        logger.debug("Identified %d new documents: %r.", len(self.new),
                     self.new.keys())

        # -- published identification; source and output should be same size
        assert len(s) == len(o)
        for stem, odoc in o.items():
            sdoc = s[stem]
            sdoc.output = odoc
            odoc.source = sdoc
            sdoc.status = sdoc.output.status = 'published'
        self.published = s
        logger.debug("Identified %d published documents.", len(self.published))

        # -- broken identification
        #
        self.broken = SourceCollection()
        for stem, sdoc in s.items():
            if not sdoc.output.iscomplete:
                self.broken[stem] = sdoc
                sdoc.status = sdoc.output.status = 'broken'
        logger.debug("Identified %d broken documents: %r.", len(self.broken),
                     self.broken.keys())

        # -- stale identification
        #

        self.stale = SourceCollection()