mirror of https://github.com/tLDP/python-tldp
changing names to sourcedir and outputdir
This commit is contained in:
parent
8670927ac6
commit
6de9aee212
|
@ -9,31 +9,31 @@ from .utils import logger
|
|||
|
||||
class OutputDir(object):
|
||||
|
||||
def __init__(self, dirname):
|
||||
self.dirname = os.path.abspath(dirname)
|
||||
self.stem = os.path.basename(dirname)
|
||||
self.members = list()
|
||||
def __init__(self, outputdir):
|
||||
self.outputdir = os.path.abspath(outputdir)
|
||||
self.stem = os.path.basename(outputdir)
|
||||
self.parent = os.path.dirname(self.outputdir)
|
||||
|
||||
def mkdir(self):
|
||||
if not os.path.exists(self.parent):
|
||||
raise OSError("Missing parent directory: " + self.parent)
|
||||
os.mkdir(self.dirname)
|
||||
os.mkdir(self.outputdir)
|
||||
|
||||
@property
|
||||
def txt_name(self):
|
||||
return os.path.join(self.dirname, self.stem, '.txt')
|
||||
return os.path.join(self.outputdir, self.stem, '.txt')
|
||||
|
||||
@property
|
||||
def pdf_name(self):
|
||||
return os.path.join(self.dirname, self.stem, '.pdf')
|
||||
return os.path.join(self.outputdir, self.stem, '.pdf')
|
||||
|
||||
@property
|
||||
def html_name(self):
|
||||
return os.path.join(self.dirname, self.stem, '.html')
|
||||
return os.path.join(self.outputdir, self.stem, '.html')
|
||||
|
||||
@property
|
||||
def htmls_name(self):
|
||||
return os.path.join(self.dirname, self.stem, '-single.html')
|
||||
return os.path.join(self.outputdir, self.stem, '-single.html')
|
||||
|
||||
|
||||
# -- end of file
|
||||
|
|
|
@ -14,28 +14,28 @@ class SourceDir(object):
|
|||
|
||||
def __repr__(self):
|
||||
return '<%s:%s (%s docs)>' % \
|
||||
(self.__class__.__name__, self.dirname, len(self.docs))
|
||||
(self.__class__.__name__, self.sourcedir, len(self.docs))
|
||||
|
||||
def __init__(self, dirname):
|
||||
self.dirname = os.path.abspath(dirname)
|
||||
def __init__(self, sourcedir):
|
||||
self.sourcedir = os.path.abspath(sourcedir)
|
||||
self.docs = list()
|
||||
if not os.path.exists(dirname):
|
||||
raise OSError("[Errno 2] No such file or directory: " + dirname)
|
||||
if not os.path.exists(sourcedir):
|
||||
raise OSError("[Errno 2] No such file or directory: " + sourcedir)
|
||||
self.enumerateDocuments()
|
||||
|
||||
def enumerateDocuments(self):
|
||||
for fname in os.listdir(self.dirname):
|
||||
possible = os.path.join(self.dirname, fname)
|
||||
for fname in os.listdir(self.sourcedir):
|
||||
possible = os.path.join(self.sourcedir, fname)
|
||||
if os.path.isfile(possible):
|
||||
self.docs.append(SourceDocument(possible))
|
||||
elif os.path.isdir(fname):
|
||||
stem = os.path.basename(fname)
|
||||
for ext in knownextensions:
|
||||
possible = os.path.join(self.dirname, fname, stem + ext)
|
||||
possible = os.path.join(self.sourcedir, fname, stem + ext)
|
||||
if os.path.isfile(possible):
|
||||
self.docs.append(SourceDocument(possible))
|
||||
logger.info("Discovered %s documents in %s",
|
||||
len(self.docs), self.dirname)
|
||||
len(self.docs), self.sourcedir)
|
||||
|
||||
|
||||
class SourceDocument(object):
|
||||
|
@ -51,17 +51,17 @@ class SourceDocument(object):
|
|||
raise OSError("Missing source document: " + self.filename)
|
||||
|
||||
logger.debug("Found existing %s", self.filename)
|
||||
self.dirname, self.basename = os.path.split(self.filename)
|
||||
self.sourcedir, self.basename = os.path.split(self.filename)
|
||||
self.stem, self.ext = os.path.splitext(self.basename)
|
||||
self.stat = os.stat(self.filename)
|
||||
|
||||
self.resources = False # -- assume no ./images/, ./resources/
|
||||
self.singlefile = True # -- assume only one file
|
||||
parentdir = os.path.basename(self.dirname)
|
||||
parentdir = os.path.basename(self.sourcedir)
|
||||
if parentdir == self.stem:
|
||||
self.singlefile = False
|
||||
for rdir in ('resources', 'images'):
|
||||
if os.path.exists(os.path.join(self.dirname, rdir)):
|
||||
if os.path.exists(os.path.join(self.sourcedir, rdir)):
|
||||
self.resources = True
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue