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 fname in sorted(os.listdir(sdir)):
|
||||
candidates = list()
|
||||
possible = os.path.join(sdir, fname)
|
||||
if os.path.isfile(possible):
|
||||
possible = arg_issourcedoc(os.path.join(sdir, fname))
|
||||
if possible:
|
||||
candidates.append(SourceDocument(possible))
|
||||
elif os.path.isdir(possible):
|
||||
possible = sourcedoc_fromdir(possible)
|
||||
if possible:
|
||||
candidates.append(SourceDocument(possible))
|
||||
else:
|
||||
logger.warning("Skipping non-directory, non-plain file %s",
|
||||
possible)
|
||||
|
@ -81,6 +77,14 @@ def scansourcedirs(dirnames):
|
|||
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):
|
||||
candidates = list()
|
||||
stem, _ = stem_and_ext(dirname)
|
||||
|
|
Loading…
Reference in New Issue