pep8/pyflakes fixes

This commit is contained in:
Martin A. Brown 2016-03-07 12:10:49 -08:00
parent 517a29b4a8
commit 76fd27d1fa
7 changed files with 76 additions and 71 deletions

View File

@ -37,7 +37,7 @@ 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', g.add_argument('--doctypes', '--formats', '--format',
'--list-doctypes', '--list-formats', '--list-doctypes', '--list-formats',
'-T', '-T',
action='store_true', default=False, action='store_true', default=False,

View File

@ -107,7 +107,7 @@ class BaseDoctype(object):
generates scripts into the directory that would be removed. Thus, the generates scripts into the directory that would be removed. Thus, the
behaviour is different depending on --script mode or --build mode. behaviour is different depending on --script mode or --build mode.
''' '''
logger.debug("%s removing dir %s.", logger.debug("%s removing dir %s.",
self.output.stem, self.output.dirname) self.output.stem, self.output.dirname)
if self.config.script: if self.config.script:
s = 'test -d "{output.dirname}" && rm -rf -- "{output.dirname}"' s = 'test -d "{output.dirname}" && rm -rf -- "{output.dirname}"'
@ -123,7 +123,7 @@ class BaseDoctype(object):
generates scripts into the directory that would be removed. Thus, the generates scripts into the directory that would be removed. Thus, the
behaviour is different depending on --script mode or --build mode. behaviour is different depending on --script mode or --build mode.
''' '''
logger.debug("%s creating dir %s.", logger.debug("%s creating dir %s.",
self.output.stem, self.output.dirname) self.output.stem, self.output.dirname)
if self.config.script: if self.config.script:
s = 'mkdir -p -- "{output.logdir}"' s = 'mkdir -p -- "{output.logdir}"'
@ -135,7 +135,7 @@ class BaseDoctype(object):
def chdir_output(self): def chdir_output(self):
'''chdir to the output directory (or write the script that would)''' '''chdir to the output directory (or write the script that would)'''
logger.debug("%s chdir to dir %s.", logger.debug("%s chdir to dir %s.",
self.output.stem, self.output.dirname) self.output.stem, self.output.dirname)
if self.config.script: if self.config.script:
s = 'cd -- "{output.dirname}"' s = 'cd -- "{output.dirname}"'
@ -144,7 +144,7 @@ class BaseDoctype(object):
return True return True
def copy_static_resources(self): def copy_static_resources(self):
logger.debug("%s copy resources %s.", logger.debug("%s copy resources %s.",
self.output.stem, self.output.dirname) self.output.stem, self.output.dirname)
source = list() source = list()
for d in self.config.resources: for d in self.config.resources:
@ -172,7 +172,7 @@ class BaseDoctype(object):
assert method is not None assert method is not None
if not method(): if not method():
logger.warning("%s %s failed (%s), skipping", logger.warning("%s %s failed (%s), skipping",
stem, methname, classname) stem, methname, classname)
return False return False
return True return True
@ -209,7 +209,8 @@ class BaseDoctype(object):
return True return True
@logtimings(logger.debug) @logtimings(logger.debug)
def execute_shellscript(self, script, preamble=preamble, postamble=postamble): def execute_shellscript(self, script, preamble=preamble,
postamble=postamble):
source = self.source source = self.source
output = self.output output = self.output
config = self.config config = self.config
@ -244,10 +245,10 @@ class BaseDoctype(object):
for name, member in d.items(): for name, member in d.items():
predecessors = getattr(member, 'depends', None) predecessors = getattr(member, 'depends', None)
if predecessors: if predecessors:
for pred in predecessors: for pred in predecessors:
method = d.get(pred, None) method = d.get(pred, None)
assert method is not None assert method is not None
graph.add_edge(method, member) graph.add_edge(method, member)
order = nx.dag.topological_sort(graph) order = nx.dag.topological_sort(graph)
return order return order
@ -258,7 +259,7 @@ class BaseDoctype(object):
logger.debug("%s build order %r", self.source.stem, order) logger.debug("%s build order %r", self.source.stem, order)
for method in order: for method in order:
classname = self.__class__.__name__ classname = self.__class__.__name__
logger.info("%s calling method %s.%s", logger.info("%s calling method %s.%s",
stem, classname, method.__name__) stem, classname, method.__name__)
if not method(): if not method():
logger.error("%s called method %s.%s failed, skipping...", logger.error("%s called method %s.%s failed, skipping...",

View File

@ -156,30 +156,31 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
def argparse(cls, p): def argparse(cls, p):
descrip = 'executables and data files for %s' % (cls.formatname,) descrip = 'executables and data files for %s' % (cls.formatname,)
g = p.add_argument_group(title=cls.__name__, description=descrip) g = p.add_argument_group(title=cls.__name__, description=descrip)
g.add_argument('--docbook4xml-xslchunk', type=arg_isreadablefile, gadd = g.add_argument
default=xslchunk_finder(), gadd('--docbook4xml-xslchunk', type=arg_isreadablefile,
help='full path to LDP HTML chunker XSL [%(default)s]') default=xslchunk_finder(),
g.add_argument('--docbook4xml-xslsingle', type=arg_isreadablefile, help='full path to LDP HTML chunker XSL [%(default)s]')
default=xslsingle_finder(), gadd('--docbook4xml-xslsingle', type=arg_isreadablefile,
help='full path to LDP HTML single-page XSL [%(default)s]') default=xslsingle_finder(),
g.add_argument('--docbook4xml-xslprint', type=arg_isreadablefile, help='full path to LDP HTML single-page XSL [%(default)s]')
default=xslprint_finder(), gadd('--docbook4xml-xslprint', type=arg_isreadablefile,
help='full path to LDP FO print XSL [%(default)s]') default=xslprint_finder(),
g.add_argument('--docbook4xml-xmllint', type=arg_isexecutable, help='full path to LDP FO print XSL [%(default)s]')
default=which('xmllint'), gadd('--docbook4xml-xmllint', type=arg_isexecutable,
help='full path to xmllint [%(default)s]') default=which('xmllint'),
g.add_argument('--docbook4xml-xsltproc', type=arg_isexecutable, help='full path to xmllint [%(default)s]')
default=which('xsltproc'), gadd('--docbook4xml-xsltproc', type=arg_isexecutable,
help='full path to xsltproc [%(default)s]') default=which('xsltproc'),
g.add_argument('--docbook4xml-html2text', type=arg_isexecutable, help='full path to xsltproc [%(default)s]')
default=which('html2text'), gadd('--docbook4xml-html2text', type=arg_isexecutable,
help='full path to html2text [%(default)s]') default=which('html2text'),
g.add_argument('--docbook4xml-fop', type=arg_isexecutable, help='full path to html2text [%(default)s]')
default=which('fop'), gadd('--docbook4xml-fop', type=arg_isexecutable,
help='full path to fop [%(default)s]') default=which('fop'),
g.add_argument('--docbook4xml-dblatex', type=arg_isexecutable, help='full path to fop [%(default)s]')
default=which('dblatex'), gadd('--docbook4xml-dblatex', type=arg_isexecutable,
help='full path to dblatex [%(default)s]') default=which('dblatex'),
help='full path to dblatex [%(default)s]')
# #
# -- end of file # -- end of file

View File

@ -175,37 +175,38 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
def argparse(cls, p): def argparse(cls, p):
descrip = 'executables for %s' % (cls.formatname,) descrip = 'executables for %s' % (cls.formatname,)
g = p.add_argument_group(title=cls.__name__, description=descrip) g = p.add_argument_group(title=cls.__name__, description=descrip)
g.add_argument('--docbook5xml-xslchunk', type=arg_isreadablefile, gadd = g.add_argument
default=xslchunk_finder(), gadd('--docbook5xml-xslchunk', type=arg_isreadablefile,
help='full path to LDP HTML chunker XSL [%(default)s]') default=xslchunk_finder(),
g.add_argument('--docbook5xml-xslsingle', type=arg_isreadablefile, help='full path to LDP HTML chunker XSL [%(default)s]')
default=xslsingle_finder(), gadd('--docbook5xml-xslsingle', type=arg_isreadablefile,
help='full path to LDP HTML single-page XSL [%(default)s]') default=xslsingle_finder(),
g.add_argument('--docbook5xml-xslprint', type=arg_isreadablefile, help='full path to LDP HTML single-page XSL [%(default)s]')
default=xslprint_finder(), gadd('--docbook5xml-xslprint', type=arg_isreadablefile,
help='full path to LDP FO print XSL [%(default)s]') default=xslprint_finder(),
help='full path to LDP FO print XSL [%(default)s]')
g.add_argument('--docbook5xml-rngfile', type=arg_isreadablefile, gadd('--docbook5xml-rngfile', type=arg_isreadablefile,
default=rngfile_finder(), default=rngfile_finder(),
help='full path to docbook.rng [%(default)s]') help='full path to docbook.rng [%(default)s]')
g.add_argument('--docbook5xml-xmllint', type=arg_isexecutable, gadd('--docbook5xml-xmllint', type=arg_isexecutable,
default=which('xmllint'), default=which('xmllint'),
help='full path to xmllint [%(default)s]') help='full path to xmllint [%(default)s]')
g.add_argument('--docbook5xml-xsltproc', type=arg_isexecutable, gadd('--docbook5xml-xsltproc', type=arg_isexecutable,
default=which('xsltproc'), default=which('xsltproc'),
help='full path to xsltproc [%(default)s]') help='full path to xsltproc [%(default)s]')
g.add_argument('--docbook5xml-html2text', type=arg_isexecutable, gadd('--docbook5xml-html2text', type=arg_isexecutable,
default=which('html2text'), default=which('html2text'),
help='full path to html2text [%(default)s]') help='full path to html2text [%(default)s]')
g.add_argument('--docbook5xml-fop', type=arg_isexecutable, gadd('--docbook5xml-fop', type=arg_isexecutable,
default=which('fop'), default=which('fop'),
help='full path to fop [%(default)s]') help='full path to fop [%(default)s]')
g.add_argument('--docbook5xml-dblatex', type=arg_isexecutable, gadd('--docbook5xml-dblatex', type=arg_isexecutable,
default=which('dblatex'), default=which('dblatex'),
help='full path to dblatex [%(default)s]') help='full path to dblatex [%(default)s]')
g.add_argument('--docbook5xml-jing', type=arg_isexecutable, gadd('--docbook5xml-jing', type=arg_isexecutable,
default=which('jing'), default=which('jing'),
help='full path to jing [%(default)s]') help='full path to jing [%(default)s]')
# #

View File

@ -17,7 +17,8 @@ from tldp.config import collectconfiguration
from tldp.utils import arg_isloglevel, arg_isdirectory from tldp.utils import arg_isloglevel, arg_isdirectory
from tldp.doctypes.common import preamble, postamble from tldp.doctypes.common import preamble, postamble
logformat = '%(levelname)-9s %(name)s %(filename)s#%(lineno)s %(funcName)s %(message)s' logformat = '%(levelname)-9s %(name)s %(filename)s#%(lineno)s ' \
+ '%(funcName)s %(message)s'
logging.basicConfig(stream=sys.stderr, format=logformat, level=logging.ERROR) logging.basicConfig(stream=sys.stderr, format=logformat, level=logging.ERROR)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -40,9 +41,10 @@ def show_doctypes(config, **kwargs):
print(file=file) print(file=file)
return os.EX_OK return os.EX_OK
def show_statustypes(config, **kwargs): def show_statustypes(config, **kwargs):
file = kwargs.get('file', sys.stdout) file = kwargs.get('file', sys.stdout)
width = 2 + max([len(x) for x in status_types]) width = 2 + max([len(x) for x in status_types])
print("Basic status types:", file=file) print("Basic status types:", file=file)
print(file=file) print(file=file)
for status, descrip in stypes.items(): for status, descrip in stypes.items():
@ -60,6 +62,7 @@ def show_statustypes(config, **kwargs):
print(file=file) print(file=file)
return os.EX_OK return os.EX_OK
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)
@ -230,7 +233,7 @@ def extractExplicitDocumentArgs(config, args):
def sameFilesystem(d0, d1): def sameFilesystem(d0, d1):
return os.stat(d0).st_dev == os.stat(d1).st_dev return os.stat(d0).st_dev == os.stat(d1).st_dev
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

View File

@ -6,7 +6,6 @@ from __future__ import absolute_import, division, print_function
import os import os
import sys import sys
import errno import errno
import shutil
import logging import logging
from tldp.ldpcollection import LDPDocumentCollection from tldp.ldpcollection import LDPDocumentCollection

View File

@ -203,7 +203,7 @@ class SourceDocument(object):
print(' doctype {}'.format(self.doctype), file=file) print(' doctype {}'.format(self.doctype), file=file)
print(' source file {}'.format(self.filename), file=file) print(' source file {}'.format(self.filename), file=file)
if self.output: if self.output:
print(' output dir {}'.format(self.output.dirname), print(' output dir {}'.format(self.output.dirname),
file=file) file=file)
for f in sorted(self.newer): for f in sorted(self.newer):
fname = os.path.join(self.dirname, f) fname = os.path.join(self.dirname, f)