# Path: tldp/outputs.py
# class OutputNamingConvention(object):
#     '''A base class inherited by OutputDirectory to ensure consistent
#     naming of files across the output collection of documents,
#     regardless of the source document type and processing toolchain
#     choice.
# 
#     Sets a list of names for documents that are expected to be present
#     in order to report that the directory iscomplete.
#     '''
#     expected = ['name_txt', 'name_pdf', 'name_htmls', 'name_html',
#                 'name_indexhtml']
# 
#     def __init__(self, dirname, stem):
#         self.dirname = dirname
#         self.stem = stem
# 
#     @property
#     def MD5SUMS(self):
#         return os.path.join(self.dirname, '.LDP-source-MD5SUMS')
# 
#     @property
#     def name_txt(self):
#         return os.path.join(self.dirname, self.stem + '.txt')
# 
#     @property
#     def name_fo(self):
#         return os.path.join(self.dirname, self.stem + '.fo')
# 
#     @property
#     def name_pdf(self):
#         return os.path.join(self.dirname, self.stem + '.pdf')
# 
#     @property
#     def name_html(self):
#         return os.path.join(self.dirname, self.stem + '.html')
# 
#     @property
#     def name_htmls(self):
#         return os.path.join(self.dirname, self.stem + '-single.html')
# 
#     @property
#     def name_epub(self):
#         return os.path.join(self.dirname, self.stem + '.epub')
# 
#     @property
#     def name_indexhtml(self):
#         return os.path.join(self.dirname, 'index.html')
# 
#     @property
#     def validsource(self):
#         return os.path.join(self.dirname, self.stem + '.xml')  # -- burp
# 
#     @property
#     def iscomplete(self):
#         '''True if the output directory contains all expected documents'''
#         present = list()
#         for prop in self.expected:
#             name = getattr(self, prop, None)
#             assert name is not None
#             present.append(os.path.exists(name))
#         return all(present)
# 
#     @property
#     def missing(self):
#         '''returns a set of missing files'''
#         missing = set()
#         for prop in self.expected:
#             name = getattr(self, prop, None)
#             assert name is not None
#             if not os.path.isfile(name):
#                 missing.add(name)
#         return missing
# 
#     @property
#     def md5sums(self):
#         d = dict()
#         try:
#             with codecs.open(self.MD5SUMS, encoding='utf-8') as f:
#                 for line in f:
#                     if line.startswith('#'):
#                         continue
#                     hashval, fname = line.strip().split()
#                     d[fname] = hashval
#         except IOError as e:
#             if e.errno != errno.ENOENT:
#                 raise
#         return d
# 
# Path: tldp/utils.py
# def writemd5sums(fname, md5s, header=None):
#     '''write an MD5SUM file from [(filename, MD5), ...]'''
#     with codecs.open(fname, 'w', encoding='utf-8') as file:
#         if header:
#             print(header, file=file)
#         for fname, hashval in sorted(md5s.items()):
#             print(hashval + '  ' + fname, file=file)
# 
# def md5file(name):
#     '''return MD5 hash for a single file name'''
#     with open(name, 'rb') as f:
#         bs = f.read()
#     md5 = hashlib.md5(bs).hexdigest()
#     try:
#         md5 = unicode(md5)
#     except NameError:
#         pass  # -- python3
#     return md5


import os
import codecs
import random
import shutil
import unittest
import tldp.config
from tempfile import mkdtemp
from tempfile import NamedTemporaryFile as ntf
from tldp.outputs import OutputNamingConvention
from tldp.utils import writemd5sums, md5file
        tldp.config.DEFAULT_CONFIGFILE = None
        self.config, _ = tldp.config.collectconfiguration('ldptool', [])
        c = self.config
        c.pubdir = os.path.join(self.tempdir, 'outputs')
        c.builddir = os.path.join(self.tempdir, 'builddir')
        c.sourcedir = os.path.join(self.tempdir, 'sources')
        argv = list()
        argv.extend(['--builddir', c.builddir])
        argv.extend(['--pubdir', c.pubdir])
        argv.extend(['--sourcedir', c.sourcedir])
        self.argv = argv
        # -- and make some directories
        for d in (c.sourcedir, c.pubdir, c.builddir):
            if not os.path.isdir(d):
                os.mkdir(d)
        c.sourcedir = [c.sourcedir]

    def tearDown(self):
        self.removeTempdir()

    def makeTempdir(self):
        self.tempdir = mkdtemp(prefix='tldp-test-')

    def removeTempdir(self):
        shutil.rmtree(self.tempdir)

    def add_stale(self, stem, ex):
        c = self.config
        mysource = TestSourceDocSkeleton(c.sourcedir)
        fname = stem + ex.ext

# Path: tldp/outputs.py
# class OutputNamingConvention(object):
#     '''A base class inherited by OutputDirectory to ensure consistent
#     naming of files across the output collection of documents,
#     regardless of the source document type and processing toolchain
#     choice.
# 
#     Sets a list of names for documents that are expected to be present
#     in order to report that the directory iscomplete.
#     '''
#     expected = ['name_txt', 'name_pdf', 'name_htmls', 'name_html',
#                 'name_indexhtml']
# 
#     def __init__(self, dirname, stem):
#         self.dirname = dirname
#         self.stem = stem
# 
#     @property
#     def MD5SUMS(self):
#         return os.path.join(self.dirname, '.LDP-source-MD5SUMS')
# 
#     @property
#     def name_txt(self):
#         return os.path.join(self.dirname, self.stem + '.txt')
# 
#     @property
#     def name_fo(self):
#         return os.path.join(self.dirname, self.stem + '.fo')
# 
#     @property
#     def name_pdf(self):
#         return os.path.join(self.dirname, self.stem + '.pdf')
# 
#     @property
#     def name_html(self):
#         return os.path.join(self.dirname, self.stem + '.html')
# 
#     @property
#     def name_htmls(self):
#         return os.path.join(self.dirname, self.stem + '-single.html')
# 
#     @property
#     def name_epub(self):
#         return os.path.join(self.dirname, self.stem + '.epub')
# 
#     @property
#     def name_indexhtml(self):
#         return os.path.join(self.dirname, 'index.html')
# 
#     @property
#     def validsource(self):
#         return os.path.join(self.dirname, self.stem + '.xml')  # -- burp
# 
#     @property
#     def iscomplete(self):
#         '''True if the output directory contains all expected documents'''
#         present = list()
#         for prop in self.expected:
#             name = getattr(self, prop, None)
#             assert name is not None
#             present.append(os.path.exists(name))
#         return all(present)
# 
#     @property
#     def missing(self):
#         '''returns a set of missing files'''
#         missing = set()
#         for prop in self.expected:
#             name = getattr(self, prop, None)
#             assert name is not None
#             if not os.path.isfile(name):
#                 missing.add(name)
#         return missing
# 
#     @property
#     def md5sums(self):
#         d = dict()
#         try:
#             with codecs.open(self.MD5SUMS, encoding='utf-8') as f:
#                 for line in f:
#                     if line.startswith('#'):
#                         continue
#                     hashval, fname = line.strip().split()
#                     d[fname] = hashval
#         except IOError as e:
#             if e.errno != errno.ENOENT:
#                 raise
#         return d
# 
# Path: tldp/utils.py
# def writemd5sums(fname, md5s, header=None):
#     '''write an MD5SUM file from [(filename, MD5), ...]'''
#     with codecs.open(fname, 'w', encoding='utf-8') as file:
#         if header:
#             print(header, file=file)
#         for fname, hashval in sorted(md5s.items()):
#             print(hashval + '  ' + fname, file=file)
# 
# def md5file(name):
#     '''return MD5 hash for a single file name'''
#     with open(name, 'rb') as f:
#         bs = f.read()
#     md5 = hashlib.md5(bs).hexdigest()
#     try:
#         md5 = unicode(md5)
#     except NameError:
#         pass  # -- python3
#     return md5


# Path: tests/tldptesttools.py
import os
import codecs
import random
import shutil
import unittest
import tldp.config
from tempfile import mkdtemp
from tempfile import NamedTemporaryFile as ntf
from tldp.outputs import OutputNamingConvention
from tldp.utils import writemd5sums, md5file

        tldp.config.DEFAULT_CONFIGFILE = None
        self.config, _ = tldp.config.collectconfiguration('ldptool', [])
        c = self.config
        c.pubdir = os.path.join(self.tempdir, 'outputs')
        c.builddir = os.path.join(self.tempdir, 'builddir')
        c.sourcedir = os.path.join(self.tempdir, 'sources')
        argv = list()
        argv.extend(['--builddir', c.builddir])
        argv.extend(['--pubdir', c.pubdir])
        argv.extend(['--sourcedir', c.sourcedir])
        self.argv = argv
        # -- and make some directories
        for d in (c.sourcedir, c.pubdir, c.builddir):
            if not os.path.isdir(d):
                os.mkdir(d)
        c.sourcedir = [c.sourcedir]

    def tearDown(self):
        self.removeTempdir()

    def makeTempdir(self):
        self.tempdir = mkdtemp(prefix='tldp-test-')

    def removeTempdir(self):
        shutil.rmtree(self.tempdir)

    def add_stale(self, stem, ex):
        c = self.config
        mysource = TestSourceDocSkeleton(c.sourcedir)
        fname = stem + ex.ext

        mysource.addsourcefile(fname, ex.filename)