mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-04 00:30:53 +00:00
figleaf_htmlizer: rewrite with twisted.python.usage, remove logging: should behave the same as before
This commit is contained in:
parent
f3ed579e74
commit
6db747b1f0
@ -4,12 +4,24 @@ import figleaf
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from optparse import OptionParser
|
from twisted.python import usage
|
||||||
|
|
||||||
import logging
|
class RenderOptions(usage.Options):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
optParameters = [
|
||||||
|
("exclude-patterns", "x", None, "file containing regexp patterns to exclude"),
|
||||||
|
("output-directory", "d", "html", "Directory for HTML output"),
|
||||||
|
("root", "r", None, "only pay attention to modules under this directory"),
|
||||||
|
]
|
||||||
|
|
||||||
logger = logging.getLogger('figleaf.htmlizer')
|
def opt_root(self, value):
|
||||||
|
self["root"] = os.path.abspath(value)
|
||||||
|
if not self["root"].endswith("/"):
|
||||||
|
self["root"] += "/"
|
||||||
|
|
||||||
|
def parseArgs(self, *filenames):
|
||||||
|
self.filenames = [".figleaf"]
|
||||||
|
if filenames:
|
||||||
|
self.filenames = list(filenames)
|
||||||
|
|
||||||
def read_exclude_patterns(f):
|
def read_exclude_patterns(f):
|
||||||
if not f:
|
if not f:
|
||||||
@ -34,7 +46,6 @@ def report_as_html(coverage, directory, exclude_patterns=[], root=None):
|
|||||||
skip = False
|
skip = False
|
||||||
for pattern in exclude_patterns:
|
for pattern in exclude_patterns:
|
||||||
if pattern.search(k):
|
if pattern.search(k):
|
||||||
logger.debug('SKIPPING %s -- matches exclusion pattern' % k)
|
|
||||||
skip = True
|
skip = True
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -61,7 +72,6 @@ def report_as_html(coverage, directory, exclude_patterns=[], root=None):
|
|||||||
pyfile = open(k)
|
pyfile = open(k)
|
||||||
#print 'opened', k
|
#print 'opened', k
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.warning('CANNOT OPEN: %s' % k)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -70,7 +80,6 @@ def report_as_html(coverage, directory, exclude_patterns=[], root=None):
|
|||||||
raise
|
raise
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
pyfile.close()
|
pyfile.close()
|
||||||
logger.warning('ERROR: %s %s' % (k, str(e)))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# ok, got all the info. now annotate file ==> html.
|
# ok, got all the info. now annotate file ==> html.
|
||||||
@ -208,7 +217,6 @@ def report_as_html(coverage, directory, exclude_patterns=[], root=None):
|
|||||||
|
|
||||||
index_fp.close()
|
index_fp.close()
|
||||||
|
|
||||||
logger.info('reported on %d file(s) total\n' % len(info_dict))
|
|
||||||
return len(info_dict)
|
return len(info_dict)
|
||||||
|
|
||||||
def prepare_reportdir(dirname='html'):
|
def prepare_reportdir(dirname='html'):
|
||||||
@ -228,54 +236,21 @@ def escape_html(s):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
###
|
opts = RenderOptions()
|
||||||
|
opts.parseOptions()
|
||||||
option_parser = OptionParser()
|
|
||||||
|
|
||||||
option_parser.add_option('-x', '--exclude-patterns', action="store",
|
|
||||||
dest="exclude_patterns_file",
|
|
||||||
help="file containing regexp patterns to exclude")
|
|
||||||
|
|
||||||
option_parser.add_option('-d', '--output-directory', action='store',
|
|
||||||
dest="output_dir",
|
|
||||||
default = "html",
|
|
||||||
help="directory for HTML output")
|
|
||||||
option_parser.add_option('-r', '--root', action="store",
|
|
||||||
dest="root",
|
|
||||||
default=None,
|
|
||||||
help="only pay attention to modules under this directory")
|
|
||||||
|
|
||||||
option_parser.add_option('-q', '--quiet', action='store_true',
|
|
||||||
dest='quiet',
|
|
||||||
help='Suppress all but error messages')
|
|
||||||
|
|
||||||
(options, args) = option_parser.parse_args()
|
|
||||||
|
|
||||||
if options.quiet:
|
|
||||||
logging.disable(logging.DEBUG)
|
|
||||||
|
|
||||||
if options.root:
|
|
||||||
options.root = os.path.abspath(options.root)
|
|
||||||
if options.root[-1] != "/":
|
|
||||||
options.root = options.root + "/"
|
|
||||||
|
|
||||||
### load
|
### load
|
||||||
|
|
||||||
if not args:
|
|
||||||
args = ['.figleaf']
|
|
||||||
|
|
||||||
coverage = {}
|
coverage = {}
|
||||||
for filename in args:
|
for filename in opts.filenames:
|
||||||
logger.debug("loading coverage info from '%s'\n" % (filename,))
|
|
||||||
d = figleaf.read_coverage(filename)
|
d = figleaf.read_coverage(filename)
|
||||||
coverage = figleaf.combine_coverage(coverage, d)
|
coverage = figleaf.combine_coverage(coverage, d)
|
||||||
|
|
||||||
if not coverage:
|
if not coverage:
|
||||||
logger.warning('EXITING -- no coverage info!\n')
|
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
### make directory
|
### make directory
|
||||||
prepare_reportdir(options.output_dir)
|
prepare_reportdir(opts["output-directory"])
|
||||||
report_as_html(coverage, options.output_dir,
|
report_as_html(coverage, opts["output-directory"],
|
||||||
read_exclude_patterns(options.exclude_patterns_file),
|
read_exclude_patterns(opts["exclude-patterns"]),
|
||||||
options.root)
|
opts["root"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user