mirror of https://github.com/tLDP/python-tldp
add support for --doctypes and --statustypes
provide CLI-discoverable listing of supported source document types and status types
This commit is contained in:
parent
bfd6c1a0a1
commit
e6b6ea7b40
|
@ -33,6 +33,14 @@ def collectconfiguration(tag, argv):
|
||||||
'-t',
|
'-t',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='dump inventory summary report [%(default)s]')
|
help='dump inventory summary report [%(default)s]')
|
||||||
|
g.add_argument('--doctypes', '--formats', '--format',
|
||||||
|
'--list-doctypes', '--list-formats',
|
||||||
|
'-T',
|
||||||
|
action='store_true', default=False,
|
||||||
|
help='show supported doctypes [%(default)s]')
|
||||||
|
g.add_argument('--statustypes', '--list-statustypes',
|
||||||
|
action='store_true', default=False,
|
||||||
|
help='show status types and classes [%(default)s]')
|
||||||
|
|
||||||
ap.add_argument('--verbose',
|
ap.add_argument('--verbose',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
|
|
|
@ -166,7 +166,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
|
||||||
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'
|
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'
|
||||||
return self.shellscript(s)
|
return self.shellscript(s)
|
||||||
|
|
||||||
@depends(make_name_html)
|
@depends(make_html, make_name_pdf, make_name_htmls)
|
||||||
def remove_validated_source(self):
|
def remove_validated_source(self):
|
||||||
'''create final index.html symlink'''
|
'''create final index.html symlink'''
|
||||||
s = 'rm --verbose -- "{output.validsource}"'
|
s = 'rm --verbose -- "{output.validsource}"'
|
||||||
|
|
|
@ -6,12 +6,13 @@ from __future__ import absolute_import, division, print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import inspect
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
from tldp.typeguesser import knowndoctypes
|
from tldp.typeguesser import knowndoctypes
|
||||||
from tldp.sources import SourceDocument, arg_issourcedoc
|
from tldp.sources import SourceDocument, arg_issourcedoc
|
||||||
from tldp.outputs import OutputDirectory
|
from tldp.outputs import OutputDirectory
|
||||||
from tldp.inventory import Inventory, status_classes, status_types
|
from tldp.inventory import Inventory, status_classes, status_types, stypes
|
||||||
from tldp.config import collectconfiguration
|
from tldp.config import collectconfiguration
|
||||||
from tldp.utils import arg_isloglevel
|
from tldp.utils import arg_isloglevel
|
||||||
from tldp.doctypes.common import preamble, postamble
|
from tldp.doctypes.common import preamble, postamble
|
||||||
|
@ -21,6 +22,44 @@ logging.basicConfig(stream=sys.stderr, format=logformat, level=logging.ERROR)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def show_doctypes(config, **kwargs):
|
||||||
|
file = kwargs.get('file', sys.stdout)
|
||||||
|
print("Supported source document types:", file=file)
|
||||||
|
print(file=file)
|
||||||
|
for doctype in knowndoctypes:
|
||||||
|
classname = doctype.__name__
|
||||||
|
fname = os.path.abspath(inspect.getmodule(doctype).__file__)
|
||||||
|
extensions = ', '.join(doctype.extensions)
|
||||||
|
print('{}'.format(classname), file=file)
|
||||||
|
print(' format name: {}'.format(doctype.formatname), file=file)
|
||||||
|
print(' code location: {}'.format(fname), file=file)
|
||||||
|
print(' file extensions: {}'.format(extensions), file=file)
|
||||||
|
for signature in doctype.signatures:
|
||||||
|
print(' signature: {}'.format(signature), file=file)
|
||||||
|
print(file=file)
|
||||||
|
print(file=file)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def show_statustypes(config, **kwargs):
|
||||||
|
file = kwargs.get('file', sys.stdout)
|
||||||
|
width = 2 + max([len(x) for x in status_types])
|
||||||
|
print("Basic status types:", file=file)
|
||||||
|
print(file=file)
|
||||||
|
for status, descrip in stypes.items():
|
||||||
|
fmt = '{status:>{width}}: {descrip}'
|
||||||
|
text = fmt.format(status=status, descrip=descrip, width=width)
|
||||||
|
print(text, file=file)
|
||||||
|
print(file=file)
|
||||||
|
print("Synonyms and groups:", file=file)
|
||||||
|
print(file=file)
|
||||||
|
for status, descrip in status_classes.items():
|
||||||
|
fmt = '{status:>{width}}: {descrip}'
|
||||||
|
descrip = ', '.join(descrip)
|
||||||
|
text = fmt.format(status=status, descrip=descrip, width=width)
|
||||||
|
print(text, file=file)
|
||||||
|
print(file=file)
|
||||||
|
return 0
|
||||||
|
|
||||||
def summary(config, inv=None, **kwargs):
|
def summary(config, inv=None, **kwargs):
|
||||||
if inv is None:
|
if inv is None:
|
||||||
inv = Inventory(config.pubdir, config.sourcedir)
|
inv = Inventory(config.pubdir, config.sourcedir)
|
||||||
|
@ -213,17 +252,29 @@ def run(argv):
|
||||||
logger.debug(" %s = %r", param, value)
|
logger.debug(" %s = %r", param, value)
|
||||||
logger.debug(" args: %r", args)
|
logger.debug(" args: %r", args)
|
||||||
|
|
||||||
# -- summary does not require any args
|
need_repos_p = "Option --pubdir (and --sourcedir) required "
|
||||||
if config.summary:
|
need_repos_s = "Option --sourcedir (and --pubdir) required "
|
||||||
|
|
||||||
|
# -- --summary, --doctypes, --statustypes do not require any args
|
||||||
|
#
|
||||||
|
if any((config.summary, config.doctypes, config.statustypes)):
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
return "Unknown args received for --summary: " + ' '.join(args)
|
return "Unknown args received: " + ' '.join(args)
|
||||||
if not config.pubdir:
|
|
||||||
return "Option --pubdir (and --sourcedir) required for --summary."
|
|
||||||
if not config.sourcedir:
|
|
||||||
return "Option --sourcedir (and --pubdir) required for --summary."
|
|
||||||
|
|
||||||
return summary(config)
|
if config.doctypes:
|
||||||
|
return show_doctypes(config)
|
||||||
|
|
||||||
|
if config.statustypes:
|
||||||
|
return show_statustypes(config)
|
||||||
|
|
||||||
|
if config.summary:
|
||||||
|
if not config.pubdir:
|
||||||
|
return need_repos_p + "for --summary"
|
||||||
|
if not config.sourcedir:
|
||||||
|
return need_repos_s + "for --summary"
|
||||||
|
|
||||||
|
return summary(config)
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# -- argument handling logic; try to avoid creating an inventory unless it
|
# -- argument handling logic; try to avoid creating an inventory unless it
|
||||||
|
@ -252,9 +303,9 @@ def run(argv):
|
||||||
#
|
#
|
||||||
if need_inventory:
|
if need_inventory:
|
||||||
if not config.pubdir:
|
if not config.pubdir:
|
||||||
return " --pubdir (and --sourcedir) required for inventory."
|
return need_repos_p + "for inventory"
|
||||||
if not config.sourcedir:
|
if not config.sourcedir:
|
||||||
return " --sourcedir (and --pubdir) required for inventory."
|
return need_repos_s + "for inventory"
|
||||||
inv = Inventory(config.pubdir, config.sourcedir)
|
inv = Inventory(config.pubdir, config.sourcedir)
|
||||||
logger.info("Collected inventory containing %s documents.",
|
logger.info("Collected inventory containing %s documents.",
|
||||||
len(inv.all.keys()))
|
len(inv.all.keys()))
|
||||||
|
@ -312,7 +363,7 @@ def run(argv):
|
||||||
config.build = True
|
config.build = True
|
||||||
|
|
||||||
if not config.pubdir:
|
if not config.pubdir:
|
||||||
return " --pubdir required to --build."
|
return need_repos_p + "to --build"
|
||||||
return build(config, docs)
|
return build(config, docs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
from tldp.utils import max_mtime, mtime_gt
|
from tldp.utils import max_mtime, mtime_gt
|
||||||
|
|
||||||
|
@ -16,28 +17,29 @@ logger = logging.getLogger(__name__)
|
||||||
# -- any individual document (source or output) will have a status
|
# -- any individual document (source or output) will have a status
|
||||||
# from the following list of status_types
|
# from the following list of status_types
|
||||||
#
|
#
|
||||||
status_types = [
|
stypes = OrderedDict()
|
||||||
'source',
|
stypes['source'] = 'found in source repository'
|
||||||
'output',
|
stypes['output'] = 'found in output repository'
|
||||||
'published',
|
stypes['published'] = 'matching stem in source/output; doc is up to date'
|
||||||
'new',
|
stypes['stale'] = 'matching stem in source/output; but source is newer'
|
||||||
'orphan',
|
stypes['orphan'] = 'stem located in output, but no source found (i.e. old?)'
|
||||||
'broken',
|
stypes['broken'] = 'output is missing an expected output format (e.g. PDF)'
|
||||||
'stale',
|
stypes['new'] = 'stem located in source, but missing in output; unpublished'
|
||||||
]
|
|
||||||
|
status_types = stypes.keys()
|
||||||
|
|
||||||
# -- the user probably doesn't usually care (too much) about listing
|
# -- the user probably doesn't usually care (too much) about listing
|
||||||
# every single published document and source document, but is probably
|
# every single published document and source document, but is probably
|
||||||
# mostly interested in specific documents grouped by status; so the
|
# mostly interested in specific documents grouped by status; so the
|
||||||
# status_classes are just sets of status_types
|
# status_classes are just sets of status_types
|
||||||
#
|
#
|
||||||
status_classes = dict(zip(status_types, [[x] for x in status_types]))
|
status_classes = OrderedDict(zip(status_types, [[x] for x in status_types]))
|
||||||
status_classes['outputs'] = ['output']
|
status_classes['outputs'] = ['output']
|
||||||
status_classes['sources'] = ['source']
|
status_classes['sources'] = ['source']
|
||||||
status_classes['problems'] = ['orphan', 'broken', 'stale']
|
|
||||||
status_classes['work'] = ['new', 'orphan', 'broken', 'stale']
|
|
||||||
status_classes['orphans'] = ['orphan']
|
status_classes['orphans'] = ['orphan']
|
||||||
status_classes['orphaned'] = ['orphan']
|
status_classes['orphaned'] = ['orphan']
|
||||||
|
status_classes['problems'] = ['orphan', 'broken', 'stale']
|
||||||
|
status_classes['work'] = ['new', 'orphan', 'broken', 'stale']
|
||||||
status_classes['all'] = ['published', 'new', 'orphan', 'broken', 'stale']
|
status_classes['all'] = ['published', 'new', 'orphan', 'broken', 'stale']
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue