mirror of https://github.com/tLDP/python-tldp
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:
parent
08ef4c35bf
commit
76d5886e54
|
@ -19,7 +19,8 @@ from tldptesttools import TestToolsFilesystem
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# -- SUT
|
# -- 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')
|
sampledocs = os.path.join(os.path.dirname(__file__), 'sample-documents')
|
||||||
|
|
||||||
|
@ -139,6 +140,11 @@ class TestSourceDocument(unittest.TestCase):
|
||||||
doc = SourceDocument(dirname)
|
doc = SourceDocument(dirname)
|
||||||
self.assertIsInstance(doc, SourceDocument)
|
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):
|
def test_detail(self):
|
||||||
ex = example.ex_linuxdoc_dir
|
ex = example.ex_linuxdoc_dir
|
||||||
s = SourceDocument(ex.filename)
|
s = SourceDocument(ex.filename)
|
||||||
|
|
|
@ -87,18 +87,19 @@ def arg_issourcedoc(filename):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def sourcedoc_fromdir(dirname):
|
def sourcedoc_fromdir(name):
|
||||||
candidates = list()
|
candidates = list()
|
||||||
stem, _ = stem_and_ext(dirname)
|
if not os.path.isdir(name):
|
||||||
parentdir = os.path.dirname(dirname)
|
return None
|
||||||
|
stem = os.path.basename(name)
|
||||||
for ext in knownextensions:
|
for ext in knownextensions:
|
||||||
possible = os.path.join(parentdir, stem, stem + ext)
|
possible = os.path.join(name, stem + ext)
|
||||||
if os.path.isfile(possible):
|
if os.path.isfile(possible):
|
||||||
candidates.append(possible)
|
candidates.append(possible)
|
||||||
if len(candidates) > 1:
|
if len(candidates) > 1:
|
||||||
logger.warning("%s multiple document choices in dir %s, bailing....",
|
logger.warning("%s multiple document choices in dir %s, bailing....",
|
||||||
stem, dirname)
|
stem, name)
|
||||||
raise Exception("multiple document choices in " + dirname)
|
raise Exception("multiple document choices in " + name)
|
||||||
elif len(candidates) == 0:
|
elif len(candidates) == 0:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue