def do_scan(self, subcmd, opts, *path_patterns): """Scan and print the CIX for the given path(s). ${cmd_usage} ${cmd_option_list} """ extra_module_dirs = [] if koextlib.is_ext_dir() and exists("pylib"): sys.path.append(abspath("pylib")) extra_module_dirs = [sys.path[-1]] mgr = Manager(extra_module_dirs=extra_module_dirs) mgr.upgrade() mgr.initialize() try: tree = None for path in _paths_from_path_patterns(path_patterns): try: lang = opts.lang or guess_lang_from_path(path) except CodeIntelError: log.info("skip `%s': couldn't determine language " "(use --lang option)", path) continue buf = mgr.buf_from_path(path, lang=opts.lang) if not isinstance(buf, CitadelBuffer): raise CodeIntelError("`%s' (%s) is not a language that " "uses CIX" % (path, buf.lang)) buf.scan() # force a fresh scan tree = buf.tree for severity, msg in check_tree(tree): dump = {"warning": log.warn, "error": log.error}[severity] dump(msg) if opts.pretty_print: tree = pretty_tree_from_tree(tree) ET.dump(tree) finally: mgr.finalize()
def do_cix_check(self, subcmd, opts, *path_patterns): """Check the given CIX file(s) for warnings, errors. ${cmd_usage} ${cmd_option_list} Eventually this should include an XML validity check against the RelaxNG schema for CIX. However, currently it just checks for some common errors. Returns the number of warnings/errors generated. """ num_results = 0 for path in _paths_from_path_patterns(path_patterns): tree = None cix = open(path, 'r').read() tree = tree_from_cix(cix) for sev, msg in check_tree(tree): num_results += 1 print("%s: %s: %s" % (path, sev, msg)) return num_results
def do_cix_check(self, subcmd, opts, *path_patterns): """Check the given CIX file(s) for warnings, errors. ${cmd_usage} ${cmd_option_list} Eventually this should include an XML validity check against the RelaxNG schema for CIX. However, currently it just checks for some common errors. Returns the number of warnings/errors generated. """ num_results = 0 for path in _paths_from_path_patterns(path_patterns): tree = None cix = open(path, 'r').read() tree = tree_from_cix(cix) for sev, msg in check_tree(tree): num_results += 1 print "%s: %s: %s" % (path, sev, msg) return num_results
def do_scan(self, subcmd, opts, *path_patterns): """Scan and print the CIX for the given path(s). ${cmd_usage} ${cmd_option_list} """ extra_module_dirs = [] if koextlib.is_ext_dir() and exists("pylib"): sys.path.append(abspath("pylib")) extra_module_dirs = [sys.path[-1]] mgr = Manager(extra_module_dirs=extra_module_dirs) mgr.upgrade() mgr.initialize() try: tree = None for path in _paths_from_path_patterns(path_patterns): try: lang = opts.lang or guess_lang_from_path(path) except CodeIntelError: log.info( "skip `%s': couldn't determine language " "(use --lang option)", path) continue buf = mgr.buf_from_path(path, lang=opts.lang) if not isinstance(buf, CitadelBuffer): raise CodeIntelError("`%s' (%s) is not a language that " "uses CIX" % (path, buf.lang)) buf.scan() # force a fresh scan tree = buf.tree for severity, msg in check_tree(tree): dump = {"warning": log.warn, "error": log.error}[severity] dump(msg) if opts.pretty_print: tree = pretty_tree_from_tree(tree) ET.dump(tree) finally: mgr.finalize()