mirror of https://github.com/tLDP/python-tldp
improve the handling of --skip
This commit is contained in:
parent
4b52db51a7
commit
aff926bb58
|
@ -9,6 +9,7 @@ import logging
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
import tldp
|
import tldp
|
||||||
|
import tldp.typeguesser
|
||||||
|
|
||||||
from tldp.inventory import status_classes, status_types
|
from tldp.inventory import status_classes, status_types
|
||||||
from tldp.utils import arg_isloglevel
|
from tldp.utils import arg_isloglevel
|
||||||
|
@ -77,9 +78,6 @@ def build(config, docs, inv, **kwargs):
|
||||||
if not source.output:
|
if not source.output:
|
||||||
dirname = os.path.join(config.pubdir, source.stem)
|
dirname = os.path.join(config.pubdir, source.stem)
|
||||||
source.output = tldp.outputs.OutputDirectory(dirname)
|
source.output = tldp.outputs.OutputDirectory(dirname)
|
||||||
if source.stem in config.skip:
|
|
||||||
logger.info("%s skipping, per user request", source.stem)
|
|
||||||
continue
|
|
||||||
if not source.doctype:
|
if not source.doctype:
|
||||||
logger.warning("%s skipping document of unknown doctype",
|
logger.warning("%s skipping document of unknown doctype",
|
||||||
source.stem)
|
source.stem)
|
||||||
|
@ -116,6 +114,15 @@ def getStatusNames(args):
|
||||||
return sought, remainder
|
return sought, remainder
|
||||||
|
|
||||||
|
|
||||||
|
def getDocumentClasses(args):
|
||||||
|
sought = set()
|
||||||
|
for cls in tldp.typeguesser.knowndoctypes:
|
||||||
|
if cls.__name__.lower() in args:
|
||||||
|
sought.add(cls)
|
||||||
|
remainder = set(args).difference(sought)
|
||||||
|
return sought, remainder
|
||||||
|
|
||||||
|
|
||||||
def getStemNames(config, stati, args, inv=None):
|
def getStemNames(config, stati, args, inv=None):
|
||||||
if inv is None:
|
if inv is None:
|
||||||
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
||||||
|
@ -130,6 +137,33 @@ def getStemNames(config, stati, args, inv=None):
|
||||||
return sought, remainder, inv
|
return sought, remainder, inv
|
||||||
|
|
||||||
|
|
||||||
|
def skipDocuments(config, docs, inv):
|
||||||
|
if not docs:
|
||||||
|
if inv is None:
|
||||||
|
inv = tldp.inventory.Inventory(config.pubdir, config.sourcedir)
|
||||||
|
docs = inv.all.values()
|
||||||
|
included = list()
|
||||||
|
excluded = list()
|
||||||
|
skip_stati, remainder = getStatusNames(config.skip)
|
||||||
|
skip_doctypes, skip_stems = getDocumentClasses(remainder)
|
||||||
|
for doc in docs:
|
||||||
|
stem = doc.stem
|
||||||
|
if hasattr(doc, 'doctype'):
|
||||||
|
if doc.doctype in skip_doctypes:
|
||||||
|
logger.info("%s skipping doctype %s", stem, doc.doctype)
|
||||||
|
excluded.append(doc)
|
||||||
|
continue
|
||||||
|
if doc.status in skip_stati:
|
||||||
|
logger.info("%s skipping status %s", stem, doc.status)
|
||||||
|
excluded.append(doc)
|
||||||
|
continue
|
||||||
|
if doc.stem in skip_stems:
|
||||||
|
logger.info("%s skipping stem %s", stem, stem)
|
||||||
|
excluded.append(doc)
|
||||||
|
continue
|
||||||
|
included.append(doc)
|
||||||
|
return included, excluded
|
||||||
|
|
||||||
def run(argv):
|
def run(argv):
|
||||||
# -- may want to see option parsing, so set --loglevel as
|
# -- may want to see option parsing, so set --loglevel as
|
||||||
# soon as possible
|
# soon as possible
|
||||||
|
@ -193,6 +227,18 @@ def run(argv):
|
||||||
return "Unknown argument (not stem, file nor status_class): " \
|
return "Unknown argument (not stem, file nor status_class): " \
|
||||||
+ ' '.join(remainder)
|
+ ' '.join(remainder)
|
||||||
|
|
||||||
|
if config.skip:
|
||||||
|
docs, excluded = skipDocuments(config, docs, inv)
|
||||||
|
|
||||||
|
# -- one last check to see that config.pubdir and config.sourcedir are set
|
||||||
|
# appropriately; before we try to use them
|
||||||
|
#
|
||||||
|
if not inv:
|
||||||
|
if not config.pubdir:
|
||||||
|
return " --pubdir (and --sourcedir) required for inventory."
|
||||||
|
if not config.sourcedir:
|
||||||
|
return " --sourcedir (and --pubdir) required for inventory."
|
||||||
|
|
||||||
if config.detail:
|
if config.detail:
|
||||||
return detail(config, docs, inv)
|
return detail(config, docs, inv)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue