# Path: tldp/sources.py
# class SourceDocument(object):
#     '''a class providing a container for each set of source documents
#     '''
#     def __repr__(self):
#         return '<%s:%s (%s)>' % \
#                (self.__class__.__name__, self.filename, self.doctype)
# 
#     def __init__(self, filename):
#         '''construct a SourceDocument
# 
#         filename is a required parameter
# 
#         The filename is the main (and sometimes sole) document representing
#         the source of the LDP HOWTO or Guide.  It is the document that is
#         passed by name to be handled by any document processing toolchains
#         (see also tldp.doctypes).
# 
#         Each instantiation will raise an IOERror if the supplied filename does
#         not exist or if the filename isn't a file (symlink is fine, directory
#         or fifo is not).
# 
#         The remainder of the instantiation will set attributes that are useful
#         later in the processing phase, for example, stem, status, enclosing
#         directory name and file extension.
# 
#         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)
#         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)
# 
#     def detail(self, widths, verbose, file=sys.stdout):
#         '''produce a small tabular output about the document'''
#         template = ' '.join(('{s.status:{w.status}}',
#                              '{s.doctype.__name__:{w.doctype}}',
#                              '{s.stem:{w.stem}}'))
#         outstr = template.format(s=self, w=widths)
#         print(outstr, file=file)
#         if verbose:
#             print('         doctype {}'.format(self.doctype), file=file)
#             if self.output:
#                 print('      output dir {}'.format(self.output.dirname),
#                       file=file)
#             print('     source file {}'.format(self.filename), file=file)
#             for why, f in sorted(self.differing):
#                 fname = os.path.join(self.dirname, f)
#                 print('  {:>7} source {}'.format(why, fname), file=file)
#             if self.output:
#                 for f in sorted(self.output.missing):
#                     print('  missing output {}'.format(f), file=file)


import os
import example
import tldp.driver
from tldptesttools import TestInventoryBase
from tldp.sources import SourceDocument
    def test_publish_linuxdoc(self):
        c = self.config
        c.publish = True
        self.add_new('Frobnitz-Linuxdoc-HOWTO', example.ex_linuxdoc)
        inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
        self.assertEqual(1, len(inv.all.keys()))
        docs = inv.all.values()
        c.skip = []
        exitcode = tldp.driver.publish(c, docs)
        self.assertEqual(exitcode, os.EX_OK)
        doc = docs.pop(0)
        self.assertTrue(doc.output.iscomplete)

    def test_publish_docbooksgml(self):
        self.add_docbooksgml_support_to_config()
        c = self.config
        c.publish = True
        self.add_new('Frobnitz-DocBookSGML-HOWTO', example.ex_docbooksgml)
        inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
        self.assertEqual(1, len(inv.all.keys()))
        docs = inv.all.values()
        exitcode = tldp.driver.publish(c, docs)
        self.assertEqual(exitcode, os.EX_OK)
        doc = docs.pop(0)
        self.assertTrue(doc.output.iscomplete)

    def test_publish_docbooksgml_larger(self):
        self.add_docbooksgml_support_to_config()
        c = self.config
        c.publish = True

# Path: tldp/sources.py
# class SourceDocument(object):
#     '''a class providing a container for each set of source documents
#     '''
#     def __repr__(self):
#         return '<%s:%s (%s)>' % \
#                (self.__class__.__name__, self.filename, self.doctype)
# 
#     def __init__(self, filename):
#         '''construct a SourceDocument
# 
#         filename is a required parameter
# 
#         The filename is the main (and sometimes sole) document representing
#         the source of the LDP HOWTO or Guide.  It is the document that is
#         passed by name to be handled by any document processing toolchains
#         (see also tldp.doctypes).
# 
#         Each instantiation will raise an IOERror if the supplied filename does
#         not exist or if the filename isn't a file (symlink is fine, directory
#         or fifo is not).
# 
#         The remainder of the instantiation will set attributes that are useful
#         later in the processing phase, for example, stem, status, enclosing
#         directory name and file extension.
# 
#         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)
#         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)
# 
#     def detail(self, widths, verbose, file=sys.stdout):
#         '''produce a small tabular output about the document'''
#         template = ' '.join(('{s.status:{w.status}}',
#                              '{s.doctype.__name__:{w.doctype}}',
#                              '{s.stem:{w.stem}}'))
#         outstr = template.format(s=self, w=widths)
#         print(outstr, file=file)
#         if verbose:
#             print('         doctype {}'.format(self.doctype), file=file)
#             if self.output:
#                 print('      output dir {}'.format(self.output.dirname),
#                       file=file)
#             print('     source file {}'.format(self.filename), file=file)
#             for why, f in sorted(self.differing):
#                 fname = os.path.join(self.dirname, f)
#                 print('  {:>7} source {}'.format(why, fname), file=file)
#             if self.output:
#                 for f in sorted(self.output.missing):
#                     print('  missing output {}'.format(f), file=file)


# Path: tests/long_driver.py
import os
import example
import tldp.driver
from tldptesttools import TestInventoryBase
from tldp.sources import SourceDocument

    def test_publish_linuxdoc(self):
        c = self.config
        c.publish = True
        self.add_new('Frobnitz-Linuxdoc-HOWTO', example.ex_linuxdoc)
        inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
        self.assertEqual(1, len(inv.all.keys()))
        docs = inv.all.values()
        c.skip = []
        exitcode = tldp.driver.publish(c, docs)
        self.assertEqual(exitcode, os.EX_OK)
        doc = docs.pop(0)
        self.assertTrue(doc.output.iscomplete)

    def test_publish_docbooksgml(self):
        self.add_docbooksgml_support_to_config()
        c = self.config
        c.publish = True
        self.add_new('Frobnitz-DocBookSGML-HOWTO', example.ex_docbooksgml)
        inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
        self.assertEqual(1, len(inv.all.keys()))
        docs = inv.all.values()
        exitcode = tldp.driver.publish(c, docs)
        self.assertEqual(exitcode, os.EX_OK)
        doc = docs.pop(0)
        self.assertTrue(doc.output.iscomplete)

    def test_publish_docbooksgml_larger(self):
        self.add_docbooksgml_support_to_config()
        c = self.config
        c.publish = True

        doc = SourceDocument(example.ex_docbooksgml_dir.filename)