restore driver.py to functionality

after refactoring into a bunch of separate functions, the tests finally pass
again
This commit is contained in:
Martin A. Brown 2016-03-01 14:10:51 -08:00
parent ae89d6814a
commit dfa729b9e5
1 changed files with 34 additions and 20 deletions

View File

@ -125,7 +125,7 @@ def getDocumentClasses(args):
return sought, remainder return sought, remainder
def getDocumentsByStemNames(docs, args): def getDocumentsByStems(docs, args):
sought = set() sought = set()
for doc in docs: for doc in docs:
if doc.stem in args: if doc.stem in args:
@ -144,8 +144,8 @@ def getDocumentsByStatus(docs, stati):
def processSkips(config, docs): def processSkips(config, docs):
included = list() included = set()
excluded = list() excluded = set()
skip_stati, remainder = getStatusNames(config.skip) skip_stati, remainder = getStatusNames(config.skip)
skip_doctypes, skip_stems = getDocumentClasses(remainder) skip_doctypes, skip_stems = getDocumentClasses(remainder)
for doc in docs: for doc in docs:
@ -153,27 +153,27 @@ def processSkips(config, docs):
if hasattr(doc, 'doctype'): if hasattr(doc, 'doctype'):
if doc.doctype in skip_doctypes: if doc.doctype in skip_doctypes:
logger.info("%s skipping doctype %s", stem, doc.doctype) logger.info("%s skipping doctype %s", stem, doc.doctype)
excluded.append(doc) excluded.add(doc)
continue continue
if doc.status in skip_stati: if doc.status in skip_stati:
logger.info("%s skipping status %s", stem, doc.status) logger.info("%s skipping status %s", stem, doc.status)
excluded.append(doc) excluded.add(doc)
continue continue
if doc.stem in skip_stems: if doc.stem in skip_stems:
logger.info("%s skipping stem %s", stem, stem) logger.info("%s skipping stem %s", stem, stem)
excluded.append(doc) excluded.add(doc)
continue continue
included.append(doc) included.add(doc)
return included, excluded return included, excluded
def extractExplicitDocumentArgs(config, args): def extractExplicitDocumentArgs(config, args):
docs = list() docs = set()
rawdocs, remainder = getDocumentNames(args) rawdocs, remainder = getDocumentNames(args)
logger.debug("args included %d documents in filesystem: %r", logger.debug("args included %d documents in filesystem: %r",
len(rawdocs), rawdocs) len(rawdocs), rawdocs)
for doc in rawdocs: for doc in rawdocs:
docs.append(tldp.sources.SourceDocument(doc)) docs.add(tldp.sources.SourceDocument(doc))
return docs, remainder return docs, remainder
@ -212,14 +212,15 @@ def run(argv):
# -- argument handling logic; try to avoid creating an inventory unless it # -- argument handling logic; try to avoid creating an inventory unless it
# is necessary # is necessary
# #
docs, remainder = extractExplicitDocumentArgs(config, args) workset, remainder = extractExplicitDocumentArgs(config, args)
stati, remainder = getStatusNames(remainder) stati, remainder = getStatusNames(remainder)
logger.debug("args included %d status type args: %r", len(stati), stati) if len(workset):
logger.info("Added %d explicit file paths from args.", len(workset))
need_inventory = False need_inventory = False
if remainder or stati: if remainder or stati:
need_inventory = True need_inventory = True
if not docs: if not workset:
need_inventory = True need_inventory = True
# -- by default, we only --list, --script or --build on work-to-be-done # -- by default, we only --list, --script or --build on work-to-be-done
@ -238,25 +239,38 @@ def run(argv):
if not config.sourcedir: if not config.sourcedir:
return " --sourcedir (and --pubdir) required for inventory." return " --sourcedir (and --pubdir) required for inventory."
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir) inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
docs.extend(inv.work.values())
else: else:
inv = None inv = None
if stati: if stati:
docs.extend(getDocumentsByStatus(docs, stati)) oldsize = len(workset)
for status in stati:
collection = getattr(inv, status)
assert isinstance(collection, tldp.sources.SourceCollection)
workset.update(collection.values())
growth = len(workset) - oldsize
if growth:
logger.info("Added %d docs, found by status class .", growth)
unknownargs = None
if remainder: if remainder:
moredocs, moreargs = getDocumentsByStemNames(docs, remainder) docs, unknownargs = getDocumentsByStems(inv.work.values(), remainder)
docs.extend(moredocs) workset.update(docs)
logger.info("Added %d docs, found by stem name.", len(docs))
if remainder: if unknownargs:
return "Unknown argument (not stem, file nor status_class): " \ return "Unknown argument (not stem, file nor status_class): " \
+ ' '.join(remainder) + ' '.join(remainder)
docs, excluded = processSkips(config, docs) if not workset:
workset.update(inv.work.values())
if docs: workset, excluded = processSkips(config, workset)
docs.sort(key=lambda x: x.stem.lower())
if not workset:
return "No work to do."
docs = sorted(workset, key=lambda x: x.stem.lower())
if config.detail: if config.detail:
return detail(config, docs) return detail(config, docs)