From d807c0217350b98ec754558cccbca9123e1effa2 Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Mon, 29 Feb 2016 17:59:49 -0800 Subject: [PATCH] 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 --- tldp/sources.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tldp/sources.py b/tldp/sources.py index 5016268..cfca999 100644 --- a/tldp/sources.py +++ b/tldp/sources.py @@ -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)