fix skipping SCSI-2.4-HOWTO (bad stem/ext handling)

source document identification was skipping any documents which lived in their
own directory AND whose names had a dot; fixed and test support added
This commit is contained in:
Martin A. Brown 2016-03-01 19:49:28 -08:00
parent 08ef4c35bf
commit 76d5886e54
2 changed files with 14 additions and 7 deletions

View File

@ -19,7 +19,8 @@ from tldptesttools import TestToolsFilesystem
import example
# -- SUT
from tldp.sources import SourceCollection, SourceDocument, scansourcedirs
from tldp.sources import SourceCollection, SourceDocument
from tldp.sources import scansourcedirs, sourcedoc_fromdir
sampledocs = os.path.join(os.path.dirname(__file__), 'sample-documents')
@ -139,6 +140,11 @@ class TestSourceDocument(unittest.TestCase):
doc = SourceDocument(dirname)
self.assertIsInstance(doc, SourceDocument)
def test_sourcedoc_fromdir_withdots(self):
dirname = os.path.dirname(example.ex_docbook4xml_dir.filename)
doc = sourcedoc_fromdir(dirname)
self.assertIsNotNone(doc)
def test_detail(self):
ex = example.ex_linuxdoc_dir
s = SourceDocument(ex.filename)

View File

@ -87,18 +87,19 @@ def arg_issourcedoc(filename):
return None
def sourcedoc_fromdir(dirname):
def sourcedoc_fromdir(name):
candidates = list()
stem, _ = stem_and_ext(dirname)
parentdir = os.path.dirname(dirname)
if not os.path.isdir(name):
return None
stem = os.path.basename(name)
for ext in knownextensions:
possible = os.path.join(parentdir, stem, stem + ext)
possible = os.path.join(name, stem + ext)
if os.path.isfile(possible):
candidates.append(possible)
if len(candidates) > 1:
logger.warning("%s multiple document choices in dir %s, bailing....",
stem, dirname)
raise Exception("multiple document choices in " + dirname)
stem, name)
raise Exception("multiple document choices in " + name)
elif len(candidates) == 0:
return None
else: