mirror of https://github.com/tLDP/python-tldp
create and use general function arg_issourcedoc
a source document is defined as either a file with a known ending (e.g. .xml, .sgml) or a directory name containing a file with the directory name plus a known extension create a small function (arg_issourcedoc), which takes a filename and returns that filename if it is (possibly) a source document or, if it is a directory, finds the main file in the directory which represents the main document
This commit is contained in:
parent
17a60e367a
commit
d807c02173
|
@ -59,13 +59,9 @@ def scansourcedirs(dirnames):
|
||||||
for sdir in sorted(dirs):
|
for sdir in sorted(dirs):
|
||||||
for fname in sorted(os.listdir(sdir)):
|
for fname in sorted(os.listdir(sdir)):
|
||||||
candidates = list()
|
candidates = list()
|
||||||
possible = os.path.join(sdir, fname)
|
possible = arg_issourcedoc(os.path.join(sdir, fname))
|
||||||
if os.path.isfile(possible):
|
if possible:
|
||||||
candidates.append(SourceDocument(possible))
|
candidates.append(SourceDocument(possible))
|
||||||
elif os.path.isdir(possible):
|
|
||||||
possible = sourcedoc_fromdir(possible)
|
|
||||||
if possible:
|
|
||||||
candidates.append(SourceDocument(possible))
|
|
||||||
else:
|
else:
|
||||||
logger.warning("Skipping non-directory, non-plain file %s",
|
logger.warning("Skipping non-directory, non-plain file %s",
|
||||||
possible)
|
possible)
|
||||||
|
@ -81,6 +77,14 @@ def scansourcedirs(dirnames):
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
|
||||||
|
def arg_issourcedoc(filename):
|
||||||
|
if os.path.isfile(filename):
|
||||||
|
return filename
|
||||||
|
elif os.path.isdir(filename):
|
||||||
|
return sourcedoc_fromdir(filename)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def sourcedoc_fromdir(dirname):
|
def sourcedoc_fromdir(dirname):
|
||||||
candidates = list()
|
candidates = list()
|
||||||
stem, _ = stem_and_ext(dirname)
|
stem, _ = stem_and_ext(dirname)
|
||||||
|
|
Loading…
Reference in New Issue