def main(): clp = command_line.create_basic_clp() clp["output_options"].add_argument( "--worst-offenders", default=10, type=int, help=("Produce a table of the worst offenders for each metric." " By default this is 10; setting it to 0 disables this" " feature.")) clp["output_options"].add_argument( "--ci", default=False, action="store_true", help=("Do not print any metrics report, only notify about violations." "This is the intended way to run in a CI environment.")) clp["output_options"].add_argument( "--text", default=None, metavar="FILE", help=("Print plain-text metrics summary to the given file. By" " default we print the summary to standard output.")) clp["output_options"].add_argument( "--html", default=None, metavar="FILE", help=("Write HTML metrics report to the file.")) options = command_line.parse_args(clp) if options.text: if os.path.exists(options.text) and not os.path.isfile(options.text): clp["ap"].error("cannot write metrics to %s, it exists and is" " not a file" % options.text) if options.html: if os.path.exists(options.html) and not os.path.isfile(options.html): clp["ap"].error("cannot write metrics to %s, it exists and is" " not a file" % options.text) if options.text and options.html: clp["ap"].error("the text and html options are mutually exclusive") if options.ci and (options.text or options.html): clp["ap"].error("the CI mode and and text/html options are mutually " "exclusive") if options.worst_offenders < 0: clp["ap"].error("the worst-offender option cannot be negative") mh = Message_Handler("metric") mh.show_context = not options.brief mh.show_style = False mh.autofix = False metric_backend = MH_Metric(options) command_line.execute(mh, options, {}, metric_backend)
def main(): parsed_args = command_line.parse_args() handler = tasklet_handler.TaskletHandler(parsed_args) handler.run()
def main(): page_torrents_traverser(command_line.parse_args())
def main(): rule_set = get_rules() clp = command_line.create_basic_clp() clp["ap"].add_argument("--fix", action="store_true", default=False, help=("Automatically fix issues where the fix" " is obvious")) clp["ap"].add_argument("--process-slx", action="store_true", default=False, help=("Style-check (but not yet auto-fix) code" " inside SIMULINK models. This option is" " temporary, and will be removed in" " future once the feature is good enough" " to be enabled by default.")) # Extra output options clp["output_options"].add_argument( "--html", default=None, help="Write report to given file as HTML") clp["output_options"].add_argument( "--no-style", action="store_true", default=False, help="Don't show any style message, only show warnings and errors.") # Debug options clp["debug_options"].add_argument( "--debug-dump-tree", default=None, metavar="FILE", help="Dump text-based parse tree to given file") clp["debug_options"].add_argument("--debug-validate-links", action="store_true", default=False, help="Debug option to check AST links") clp["debug_options"].add_argument("--debug-cfg", action="store_true", default=False, help="Build CFG for every function") style_option = clp["ap"].add_argument_group("rule options") # Add any parameters from rules for rule_kind in rule_set: for rule in rule_set[rule_kind]: rule_params = getattr(rule, "parameters", None) if not rule_params: continue for p_name in rule_params: style_option.add_argument("--" + p_name, **rule_params[p_name]) style_option.add_argument("--copyright-entity", metavar="STR", default=[], nargs="+", help=("Add (company) name to check for in " "Copyright notices. Can be specified " "multiple times.")) options = command_line.parse_args(clp) if options.html: if os.path.exists(options.html) and not os.path.isfile(options.html): clp["ap"].error("Cannot write to %s: it is not a file" % options.html) mh = HTML_Message_Handler("style", options.html) else: mh = Message_Handler("style") mh.show_context = not options.brief mh.show_style = not options.no_style mh.autofix = options.fix extra_options = { "fd_tree": None, "rule_set": rule_set, } if options.debug_dump_tree: extra_options["fd_tree"] = open(options.debug_dump_tree, "w") style_backend = MH_Style() command_line.execute(mh, options, extra_options, style_backend, options.process_slx) if options.debug_dump_tree: extra_options["fd_tree"].close()
def main(): clp = command_line.create_basic_clp() clp["output_options"].add_argument( "--worst-offenders", default=10, type=int, help=("Produce a table of the worst offenders for each metric." " By default this is 10; setting it to 0 disables this" " feature.")) clp["output_options"].add_argument( "--ci", default=False, action="store_true", help=("Do not print any metrics report, only notify about violations." "This is the intended way to run in a CI environment.")) clp["output_options"].add_argument( "--text", default=None, metavar="FILE", help=("Print plain-text metrics summary to the given file. By" " default we print the summary to standard output.")) clp["output_options"].add_argument( "--html", default=None, metavar="FILE", help=("Write HTML metrics report to the file.")) options = command_line.parse_args(clp) if options.text: if os.path.exists(options.text) and not os.path.isfile(options.text): clp["ap"].error("cannot write metrics to %s, it exists and is" " not a file" % options.text) if options.html: if os.path.exists(options.html) and not os.path.isfile(options.html): clp["ap"].error("cannot write metrics to %s, it exists and is" " not a file" % options.text) if options.text and options.html: clp["ap"].error("the text and html options are mutually exclusive") if options.ci and (options.text or options.html): clp["ap"].error("the CI mode and and text/html options are mutually " "exclusive") if options.worst_offenders < 0: clp["ap"].error("the worst-offender option cannot be negative") mh = Message_Handler("metric") mh.show_context = not options.brief mh.show_style = False mh.autofix = False work_list = command_line.read_config(mh, options, {}) all_metrics = {} # file -> { metrics -> {} # functions -> {name -> {}} } if options.single: for processed, filename, result, metrics in map( collect_metrics, work_list): mh.integrate(result) if processed: mh.finalize_file(filename) all_metrics.update(metrics) else: pool = multiprocessing.Pool() for processed, filename, result, metrics in pool.imap( collect_metrics, work_list, 5): mh.integrate(result) if processed: mh.finalize_file(filename) all_metrics.update(metrics) # Postprocess if options.worst_offenders: worst_offenders = build_worst_offenders_table(all_metrics, options.worst_offenders) else: worst_offenders = None # Generate report if options.html: with open(options.html, "w") as fd: write_html_report(fd, options.html, all_metrics, worst_offenders) elif options.text: with open(options.text, "w") as fd: write_text_report(fd, all_metrics, worst_offenders) elif not options.ci: write_text_report(sys.stdout, all_metrics, worst_offenders) mh.summary_and_exit()