当前位置: 首页>>代码示例>>Python>>正文


Python Manager.finalize方法代码示例

本文整理汇总了Python中codeintel2.manager.Manager.finalize方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.finalize方法的具体用法?Python Manager.finalize怎么用?Python Manager.finalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在codeintel2.manager.Manager的用法示例。


在下文中一共展示了Manager.finalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_scan

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    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()
开发者ID:nagyist,项目名称:KomodoEdit,代码行数:37,代码来源:codeintel.py

示例2: worker

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
def worker(queue, lock, cix_dir, root="/"):
    """
    worker procedure
    """
    fix_module_path()
    import dxr.mime
    from codeintel2.citadel import CitadelBuffer
    from codeintel2.common import CodeIntelError
    from codeintel2.manager import Manager
    from codeintel2.util import guess_lang_from_path

    logging.getLogger("codeintel").setLevel(logging.ERROR)
    log.info("starting indexing using %s", multiprocessing.current_process().name)

    mgr = Manager(db_base_dir=cix_dir)
    #mgr.upgrade()
    mgr.initialize()

    while True:
        file_path = queue.get()
        if file_path is None:
            # marker for end of list
            queue.put(None) # put it back so others can quit too
            break

        rel_path = os.path.relpath(file_path, root)

        try:
            lang = guess_lang_from_path(file_path)
        except CodeIntelError:
            log.info("%s: Cannot determine language, skipping", rel_path)
            continue

        # the file
        with open(file_path, "r") as source_file:
            data = source_file.read()

        # Discard non-text files
        if not dxr.mime.is_text(file_path, data):
            continue

        try:
            buf = mgr.buf_from_path(file_path, lang=lang)
        except CodeIntelError as ex:
            if ex.message.startswith("File too big."):
                log.info("%s: %s", file_path, ex.message)
                continue # Nothing we can do about that, and the user can't
                         # fix this ever.
            raise
        if not isinstance(buf, CitadelBuffer):
            log.info("%s: language %s does not have CIX, skipping",
                     rel_path, lang)
            continue

        log.info("%s: Using language %s", rel_path, lang)

        buf.scan()

    mgr.finalize()
开发者ID:mook,项目名称:dxr-plugin-komodo-codeintel,代码行数:61,代码来源:indexer.py

示例3: do_json

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_json(self, subcmd, opts, path):
        """Convert cix XML file into json format.

        ${cmd_usage}
        ${cmd_option_list}
        """
        import json

        if opts.output == '-':
            output_path = None
            output_file = sys.stdout
        else:
            if opts.output:
                output_path = opts.output
            else:
                output_path = splitext(path)[0]+".json"
            if exists(output_path):
                if opts.force:
                    os.remove(output_path)
                else:
                    raise Error("`%s' exists: use -f|--force option to "
                                "allow overwrite" % output_path)
            output_file = open(output_path, 'w')

        mgr = Manager()
        mgr.upgrade()
        mgr.initialize()

        try:
            if path.endswith(".cix"):
                tree = tree_from_cix(open(path, 'r').read())
            else:
                buf = mgr.buf_from_path(path, lang=opts.lang)
                tree = buf.tree

            result = {}
            ci = result["codeintel"] = defaultdict(list)

            def _elemToDict(parent, elem):
                data = defaultdict(list)
                name = elem.get("name")
                if name is not None:
                    data["name"] = name
                data["tag"] = elem.tag
                for attr_name, attr in elem.attrib.items():
                    data[attr_name] = attr
                parent["children"].append(data)
                for child in elem:
                    _elemToDict(data, child)

            for child in tree:
                _elemToDict(ci, child)

            json.dump(result, output_file, indent=2)

        finally:
            mgr.finalize()
开发者ID:ball6847,项目名称:openkomodo,代码行数:59,代码来源:ci2.py

示例4: do_html

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_html(self, subcmd, opts, path):
        """Convert the given path to styled HTML.

        ${cmd_usage}
        ${cmd_option_list}

        The output includes trigger info and other stats. I.e. this is
        primarily a debugging tool.
        """
        from codeintel2.manager import Manager
        from codeintel2.common import Error
        from ci2 import _url_from_local_path

        mgr = Manager()
        try:
            if opts.browse:
                htmls = []
            buf = mgr.buf_from_path(path, lang=opts.lang)
            html = buf.to_html(True, True, title=path,
                               do_trg=opts.do_trg,
                               do_eval=opts.do_eval)
        finally:
            mgr.finalize()

        if opts.output == '-':
            output_path = None
            output_file = sys.stdout
        else:
            if opts.output:
                output_path = opts.output
            else:
                output_path = path + ".html"
            if os.path.exists(output_path):
                if opts.force:
                    os.remove(output_path)
                else:
                    raise Error("`%s' exists: use -f|--force option to allow overwrite" % output_path)
            output_file = open(output_path, 'w')
        # else:
        #    output_path = None
        #    output_file = sys.stdout
        #    #XXX Disable writing t
        #    output_file = None
        if output_file:
            output_file.write(html)
        if output_path:
            output_file.close()

        if opts.browse:
            if not output_path:
                raise Error("cannot open in browser if stdout used "
                            "for output")
            import webbrowser
            url = _url_from_local_path(output_path)
            webbrowser.open_new(url)
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:57,代码来源:__main__.py

示例5: do_html

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_html(self, subcmd, opts, path):
        """Convert the given path to styled HTML.

        ${cmd_usage}
        ${cmd_option_list}
        
        The generated HTML provides a good tool for seeing how Komodo's
        lexer lexes the given content. This is the same tokenization that
        you get from "buf.accessor.*" methods -- which you can use for
        writing the CILE, trigger handling, and completion evaluation
        for this language.
        
        Use the "-t" and "-e" option to also exercise the current
        trigger handling and completion evaluation (i.e. determining
        the appropriate completions and calltips at a given trigger
        point).
        """
        extra_lang_module_dirs = []
        if koextlib.is_ext_dir() and exists("pylib"):
            sys.path.append(abspath("pylib"))
            extra_lang_module_dirs = [sys.path[-1]]

        mgr = Manager(extra_lang_module_dirs=extra_lang_module_dirs)
        try:
            if opts.browse:
                htmls = []
            buf = mgr.buf_from_path(path, lang=opts.lang)
            html = buf.to_html(True, True, title=path, do_trg=opts.do_trg, do_eval=opts.do_eval)
        finally:
            mgr.finalize()

        if opts.output == "-":
            output_path = None
            output_file = sys.stdout
        else:
            if opts.output:
                output_path = opts.output
            else:
                output_path = path + ".html"
            if exists(output_path):
                os.remove(output_path)
            output_file = open(output_path, "w")
        if output_file:
            output_file.write(html)
        if output_path:
            output_file.close()

        if opts.browse:
            if not output_path:
                raise CodeIntelError("cannot open in browser if stdout " "used for output")
            import webbrowser

            url = _url_from_local_path(output_path)
            webbrowser.open_new(url)
开发者ID:nagyist,项目名称:KomodoEdit,代码行数:56,代码来源:codeintel.py

示例6: do_dbcheck

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_dbcheck(self, subcmd, opts):
        """Run an internal consistency check on the database.

        ${cmd_usage}
        ${cmd_option_list}
        Any errors will be printed. Returns the number of errors (i.e.
        exit value is 0 if there are no consistency problems).
        """
        mgr = Manager(opts.db_base_dir)
        try:
            errors = mgr.db.check()
        finally:
            mgr.finalize()
        for error in errors:
            print error
        return len(errors)
开发者ID:ball6847,项目名称:openkomodo,代码行数:18,代码来源:ci2.py

示例7: casper_tests

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
def casper_tests():
    from codeintel2.manager import Manager

    db_base_dir = join(dirname(__file__), "tmp", "db")
    mgr = Manager(db_base_dir)
    mgr.upgrade()
    mgr.initialize()
    try:
        for testpath in testpaths():
            buf = mgr.buf_from_path(testpath, lang="JavaScript")
            # Ensure the test is up to date.
            if buf.scan_time < os.stat(testpath).st_mtime:
                buf.scan()
            for test in casper_tests_from_citree(buf.tree):
                yield test
    finally:
        mgr.finalize()
开发者ID:Acidburn0zzz,项目名称:KomodoEdit,代码行数:19,代码来源:test_casper.py

示例8: do_play

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_play(self, subcmd, opts):
        """Run my current play/dev code.

        ${cmd_usage}
        ${cmd_option_list}
        """
        import pprint
        import random
        import ciElementTree as ET
        from codeintel2.manager import Manager
        from codeintel2.tree import pretty_tree_from_tree
        from codeintel2.common import LogEvalController, Error
        from codeintel2.util import tree_from_cix, dedent, unmark_text, banner
        from ci2 import _escaped_text_from_text

        if False:
            lang = "CSS"
            markedup_content = dedent("""
                /* http://www.w3.org/TR/REC-CSS2/fonts.html#propdef-font-weight */
                h1 {
                    border: 1px solid black;
                    font-weight /* hi */: <|> !important
                }
            """)
            content, data = unmark_text(markedup_content)
            pos = data["pos"]
            mgr = Manager()
            # mgr.upgrade() # Don't need it for just CSS usage.
            mgr.initialize()
            try:
                buf = mgr.buf_from_content(content, lang=lang, path="play.css")
                trg = buf.trg_from_pos(pos)
                if trg is None:
                    raise Error("unexpected trigger: %r" % trg)
                completions = buf.cplns_from_trg(trg)
                print("COMPLETIONS: %r" % completions)
            finally:
                mgr.finalize()

        elif False:
            lang = "Python"
            path = os.path.join("<Unsaved>", "rand%d.py" % random.randint(0, 100))
            markedup_content = dedent("""
                import sys, os

                class Foo:
                    def bar(self):
                        pass

                sys.<|>path    # should have path in completion list
                f = Foo()
                """)
            content, data = unmark_text(markedup_content)
            print(banner(path))
            print(_escaped_text_from_text(content, "whitespace"))
            pos = data["pos"]
            mgr = Manager()
            mgr.upgrade()
            mgr.initialize()
            try:
                buf = mgr.buf_from_content(content, lang=lang, path=path)
                print(banner("cix", '-'))
                print(buf.cix)

                trg = buf.trg_from_pos(pos)
                if trg is None:
                    raise Error("unexpected trigger: %r" % trg)
                print(banner("completions", '-'))
                ctlr = LogEvalController(self.log)
                buf.async_eval_at_trg(trg, ctlr)
                ctlr.wait(2)  # XXX
                if not ctlr.is_done():
                    ctlr.abort()
                    raise Error("XXX async eval timed out")
                pprint.pprint(ctlr.cplns)
                print(banner(None))
            finally:
                mgr.finalize()
        elif False:
            lang = "Ruby"
            path = os.path.join("<Unsaved>", "rand%d.py" % random.randint(0, 100))
            markedup_content = dedent("""\
            r<1>equire 'net/http'
            include Net
            req = HTTPRequest.new
            req.<2>get()
            """)
            content, data = unmark_text(markedup_content)
            print(banner(path))
            print(_escaped_text_from_text(content, "whitespace"))
            pos = data[1]
            mgr = Manager()
            mgr.upgrade()
            mgr.initialize()
            try:
                buf = mgr.buf_from_content(content, lang=lang, path=path)
                print(banner("cix", '-'))
                cix = buf.cix
                print(ET.tostring(pretty_tree_from_tree(tree_from_cix(cix))))

#.........这里部分代码省略.........
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:103,代码来源:__main__.py

示例9: do_scan

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]

#.........这里部分代码省略.........
        """
        import time
        import ciElementTree as ET
        from ci2 import _paths_from_path_patterns
        from codeintel2.manager import Manager
        from codeintel2.citadel import CitadelBuffer
        from codeintel2.common import CodeIntelError
        from codeintel2.tree import pretty_tree_from_tree
        from codeintel2.util import guess_lang_from_path

        mgr = Manager()
        mgr.upgrade()
        mgr.initialize()
        try:
            if opts.time_it:
                start = time.time()
            quiet = opts.quiet
            if opts.time_it or opts.time_details:
                opts.force = True

            scan_count = 0
            lang_warnings = set()
            tree = None
            for path in _paths_from_path_patterns(path_patterns,
                                                  recursive=opts.recursive,
                                                  includes=opts.includes):
                if opts.time_it:
                    sys.stderr.write(path + "\n")
                if opts.time_details:
                    start1 = time.time()

                try:
                    lang = opts.lang or guess_lang_from_path(path)
                except CodeIntelError:
                    self.log.info("skip `%s': couldn't determine language", path)
                    continue
                try:
                    buf = mgr.buf_from_path(path, lang=lang)
                except OSError as ex:
                    # Couldn't access the file.
                    if not opts.recursive:
                        raise
                    # Ignore files we don't really care about.
                    self.log.warn("%r - %r", ex, path)
                    continue
                if not isinstance(buf, CitadelBuffer):
                    if opts.recursive:
                        # Ignore files that scanning isn't provided for.
                        continue
                    raise CodeIntelError("`%s' (%s) is not a language that "
                                         "uses CIX" % (path, buf.lang))

                scan_count += 1
                if scan_count % 10 == 0:
                    self.log.info("%d scanning %r", scan_count, path)

                try:
                    if opts.force:
                        buf.scan()
                    if tree is None:
                        tree = ET.Element("codeintel", version="2.0")
                    file_elem = ET.SubElement(tree, "file",
                                              lang=buf.lang,
                                              mtime=str(int(time.time())),
                                              path=os.path.basename(path))
                    for lang, blob in sorted(buf.blob_from_lang.items()):
                        blob = buf.blob_from_lang[lang]
                        file_elem.append(blob)
                except KeyError as ex:
                    # Unknown cile language.
                    if not opts.recursive:
                        raise
                    message = str(ex)
                    if message not in lang_warnings:
                        lang_warnings.add(message)
                        self.log.warn("Skipping unhandled language %s", message)

                if opts.time_details:
                    delta = time.time() - start1
                    sys.stderr.write("%.3f %s\n" % (delta, path))
                    sys.stderr.flush()

            if tree is not None:
                if opts.stripfuncvars:
                    # For stdlibs, we don't care about variables inside of
                    # functions and they take up a lot of space.
                    for function in tree.getiterator('scope'):
                        if function.get('ilk') == 'function':
                            function[:] = [child for child in function
                                           if child.tag != 'variable']
                if opts.pretty_print:
                    tree = pretty_tree_from_tree(tree)
                if not quiet:
                    sys.stdout.write('<?xml version="1.0" encoding="UTF-8"?>\n')
                    ET.dump(tree)
                if opts.time_it:
                    end = time.time()
                    sys.stderr.write("scan took %.3fs\n" % (end - start))
        finally:
            mgr.finalize()
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:104,代码来源:__main__.py

示例10: do_outline

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_outline(self, subcmd, opts, path):
        """Print code outline of the given file.

        You can specify a lookup path into the file code outline to
        display via URL-anchor syntax, e.g.:
            ci2 outline path/to/foo.py#AClass.amethod

        ${cmd_usage}
        ${cmd_option_list}
        """
        import re
        from ci2 import _outline_ci_elem
        from codeintel2.manager import Manager
        from codeintel2.util import tree_from_cix

        mgr = Manager()
        mgr.upgrade()
        mgr.initialize()
        try:
            if '#' in path:
                path, anchor = path.rsplit('#', 1)
            else:
                anchor = None

            if path.endswith(".cix"):
                tree = tree_from_cix(open(path, 'r').read())
                # buf = mgr.buf_from_content("", tree[0].get("lang"), path=path)
            else:
                buf = mgr.buf_from_path(path, lang=opts.lang)
                tree = buf.tree

            if anchor is not None:
                # Lookup the anchor in the codeintel CIX tree.
                lpath = re.split(r'\.|::', anchor)

                def blobs_from_tree(tree):
                    for file_elem in tree:
                        for blob in file_elem:
                            yield blob

                for elem in blobs_from_tree(tree):
                    # Generally have 3 types of codeintel trees:
                    # 1. single-lang file: one <file>, one <blob>
                    # 2. multi-lang file: one <file>, one or two <blob>'s
                    # 3. CIX stdlib/catalog file: possibly multiple
                    #    <file>'s, likely multiple <blob>'s
                    # Allow the first token to be the blob name or lang.
                    # (This can sometimes be weird, but seems the most
                    # convenient solution.)
                    if lpath[0] in (elem.get("name"), elem.get("lang")):
                        remaining_lpath = lpath[1:]
                    else:
                        remaining_lpath = lpath
                    for name in remaining_lpath:
                        try:
                            elem = elem.names[name]
                        except KeyError:
                            elem = None
                            break  # try next lang blob
                    if elem is not None:
                        break  # found one
                else:
                    self.log.error("could not find `%s' definition (or blob) in `%s'",
                              anchor, path)
                    return 1
            else:
                elem = tree

            try:
                _outline_ci_elem(elem, brief=opts.brief, doSort=opts.doSort)
            except IOError as ex:
                if ex.errno == 0:
                    # Ignore this error from aborting 'less' of 'ci2 outline'
                    # output:
                    #    IOError: (0, 'Error')
                    pass
                else:
                    raise
        finally:
            mgr.finalize()
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:82,代码来源:__main__.py

示例11: do_scan

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_scan(self, subcmd, opts, *path_patterns):
        """Scan and print the CIX for the given path(s).

        ${cmd_usage}
        ${cmd_option_list}
        """
        mgr = Manager()
        mgr.upgrade()
        mgr.initialize()
        try:
            if opts.time_it:
                start = time.time()
            quiet = opts.quiet
            if opts.time_it or opts.time_details:
                opts.force = True

            tree = None
            for path in _paths_from_path_patterns(path_patterns,
                                                  recursive=opts.recursive,
                                                  includes=opts.includes):
                if opts.time_it:
                    sys.stderr.write(path+"\n")
                if opts.time_details:
                    start1 = time.time()

                try:
                    lang = opts.lang or guess_lang_from_path(path)
                except CodeIntelError:
                    log.info("skip `%s': couldn't determine language", path)
                    continue
                buf = mgr.buf_from_path(path, lang=lang)
                if not isinstance(buf, CitadelBuffer):
                    raise CodeIntelError("`%s' (%s) is not a language that "
                                         "uses CIX" % (path, buf.lang))
                if opts.force:
                    buf.scan()
                if tree is None:
                    tree = ET.Element("codeintel", version="2.0")
                file_elem = ET.SubElement(tree, "file",
                                          lang=buf.lang,
                                          mtime=str(int(time.time())),
                                          path=os.path.basename(path))
                for lang, blob in sorted(buf.blob_from_lang.items()):
                    blob = buf.blob_from_lang[lang]
                    file_elem.append(blob)

                if opts.time_details: 
                   delta = time.time() - start1
                   sys.stderr.write("%.3f %s\n" % (delta, path)) 
                   sys.stderr.flush()

            if tree is not None:
                if opts.stripfuncvars:
                    # For stdlibs, we don't care about variables inside of
                    # functions and they take up a lot of space.
                    for function in tree.getiterator('scope'):
                        if function.get('ilk') == 'function':
                            function[:] = [child for child in function 
                                           if child.tag != 'variable']
                if opts.pretty_print:
                    tree = pretty_tree_from_tree(tree)
                if not quiet:
                    sys.stdout.write('<?xml version="1.0" encoding="UTF-8"?>\n')
                    ET.dump(tree)
                if opts.time_it:
                    end = time.time()
                    sys.stderr.write("scan took %.3fs\n" % (end-start))
        finally:
            mgr.finalize()
开发者ID:ball6847,项目名称:openkomodo,代码行数:71,代码来源:ci2.py

示例12: Driver

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]

#.........这里部分代码省略.........
        if len(names) > 1:
            # It's inside a package - go look for the package(s).
            for package_name in names[:-1]:
                iinfo = imp.find_module(package_name, [path] if path else None)
                if not iinfo:
                    raise RequestFailure(msg="load-extension could not find "
                                             "package %r for given name %r"
                                             % (package_name, name))
                path = iinfo[1]
            name = names[-1]
        iinfo = imp.find_module(name, [path] if path else None)
        try:
            module = imp.load_module(name, *iinfo)
        finally:
            if iinfo and iinfo[0]:
                iinfo[0].close()
        callback = getattr(module, "registerExtension", None)
        if not callback:
            raise RequestFailure(msg="load-extension module %s should "
                                     "have a 'registerExtension' method "
                                     "taking no arguments" % (name,))
        callback()
        self.send() # success, finally

    def do_quit(self, request):
        self.quit = True
        self.send(command="quit")

    def report_error(self, message):
        self.send(request=None,
                  command="report-error",
                  message=six.text_type(message))

    def finalize(self, timeout=None):
        self.do_quit(None)
        self.mgr.finalize()

    def start(self):
        """Start reading from the socket and dump requests into the queue"""
        log.info("Running codeintel driver...")
        buf = b''
        self.send(success=None)
        self.daemon = True
        threading.Thread.start(self)
        while not self.quit:
            try:
                ch = self.fd_in.read(1)
            except IOError:
                log.debug("Failed to read frame length, assuming connection died")
                self.quit = True
                break
            if not ch:
                log.debug("Input was closed")
                self.quit = True
                break
            if ch == b'{':
                length = int(buf, 10)
                try:
                    buf = ch
                    while len(buf) < length:
                        data = self.fd_in.read(length - len(buf))
                        if not data:
                            # nothing read, EOF
                            raise IOError("Failed to read frame from socket")
                        buf += data
                except IOError:
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:70,代码来源:driver.py

示例13: do_outline

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
    def do_outline(self, subcmd, opts, path):
        """Scan and outline the structure of the given path.

        ${cmd_usage}
        ${cmd_option_list}
        """
        extra_lang_module_dirs = []
        if koextlib.is_ext_dir() and exists("pylib"):
            sys.path.append(abspath("pylib"))
            extra_lang_module_dirs = [sys.path[-1]]

        mgr = Manager(extra_lang_module_dirs=extra_lang_module_dirs)
        mgr.upgrade()
        mgr.initialize()
        try:
            if "#" in path:
                path, anchor = path.rsplit("#", 1)
            else:
                anchor = None

            tree = None
            try:
                lang = opts.lang or guess_lang_from_path(path)
            except CodeIntelError:
                log.info("skip `%s': couldn't determine language " "(use --lang option)", path)
                return

            if path.endswith(".cix"):
                tree = tree_from_cix(open(path, "r").read())
                # buf = mgr.buf_from_content("", tree[0].get("lang"), path=path)
            else:
                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))
                tree = buf.tree

            if anchor is not None:
                # Lookup the anchor in the codeintel CIX tree.
                lpath = re.split(r"\.|::", anchor)

                def blobs_from_tree(tree):
                    for file_elem in tree:
                        for blob in file_elem:
                            yield blob

                for elem in blobs_from_tree(tree):
                    # Generally have 3 types of codeintel trees:
                    # 1. single-lang file: one <file>, one <blob>
                    # 2. multi-lang file: one <file>, one or two <blob>'s
                    # 3. CIX stdlib/catalog file: possibly multiple
                    #    <file>'s, likely multiple <blob>'s
                    # Allow the first token to be the blob name or lang.
                    # (This can sometimes be weird, but seems the most
                    # convenient solution.)
                    if lpath[0] in (elem.get("name"), elem.get("lang")):
                        remaining_lpath = lpath[1:]
                    else:
                        remaining_lpath = lpath
                    for name in remaining_lpath:
                        try:
                            elem = elem.names[name]
                        except KeyError:
                            elem = None
                            break  # try next lang blob
                    if elem is not None:
                        break  # found one
                else:
                    log.error("could not find `%s' definition (or blob) in `%s'", anchor, path)
                    return 1
            else:
                elem = tree

            try:
                _outline_ci_elem(mgr, elem, quiet=opts.quiet)
            except IOError, ex:
                if ex.errno == 0:
                    # Ignore this error from aborting 'less' of this
                    # command:
                    #    IOError: (0, 'Error')
                    pass
                else:
                    raise
        finally:
            mgr.finalize()
开发者ID:nagyist,项目名称:KomodoEdit,代码行数:86,代码来源:codeintel.py

示例14: cix2html

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
def cix2html(opts, path):
    """Turn cix file into html API documentation.

    Example:
        cix2html path/to/foo.cix#AClass.amethod
        cix2html path/to/foo.cix -o file.html

    ${cmd_usage}
    ${cmd_option_list}
    """
    mgr = Manager()
    mgr.upgrade()
    mgr.initialize()
    try:
        def blobs_from_tree(tree):
            for file_elem in tree:
                for blob in file_elem:
                    yield blob

        if '#' in path:
            path, anchor = path.rsplit('#', 1)
        else:
            anchor = None

        if path.endswith(".cix"):
            tree = tree_from_cix(open(path, 'r').read())
            #buf = mgr.buf_from_content("", tree[0].get("lang"), path=path)
        else:
            buf = mgr.buf_from_path(path, lang=opts.lang)
            tree = buf.tree

        if anchor is not None:
            # Lookup the anchor in the codeintel CIX tree.
            lpath = re.split(r'\.|::', anchor)
            for elem in blobs_from_tree(tree):
                # Generally have 3 types of codeintel trees:
                # 1. single-lang file: one <file>, one <blob>
                # 2. multi-lang file: one <file>, one or two <blob>'s
                # 3. CIX stdlib/catalog file: possibly multiple
                #    <file>'s, likely multiple <blob>'s
                # Allow the first token to be the blob name or lang.
                # (This can sometimes be weird, but seems the most
                # convenient solution.)
                if lpath[0] in (elem.get("name"), elem.get("lang")):
                    remaining_lpath = lpath[1:]
                else:
                    remaining_lpath = lpath
                for name in remaining_lpath:
                    try:
                        elem = elem.names[name]
                    except KeyError:
                        elem = None
                        break # try next lang blob
                if elem is not None:
                    break # found one
            else:
                log.error("could not find `%s' definition (or blob) in `%s'",
                          anchor, path)
                return 1
        else:
            elem = tree

        try:
            if elem.tag  == "codeintel":
                _html_ci_elem(opts, elem.getchildren()[0])
            else:
                _html_ci_elem(opts, elem)
        except IOError as ex:
            if ex.errno == 0:
                # Ignore this error from aborting 'less' of 'ci2 outline'
                # output:
                #    IOError: (0, 'Error')
                pass
            else:
                raise
        except Exception as e:
            import traceback
            traceback.print_exc()
    finally:
        mgr.finalize()
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:82,代码来源:cix2html.py

示例15: CodeIntelTestCase

# 需要导入模块: from codeintel2.manager import Manager [as 别名]
# 或者: from codeintel2.manager.Manager import finalize [as 别名]
class CodeIntelTestCase(unittest.TestCase):
    # Subclasses can override this to have setUp pass these settings to the
    # codeintel.Manager.
    _ci_db_base_dir_ = None
    _ci_db_catalog_dirs_ = []
    _ci_db_import_everything_langs = None
    _ci_env_prefs_ = None
    # A test case can set this to false to have the setUp/tearDown *not*
    # create a `self.mgr'.
    _ci_test_setup_mgr_ = True
    _ci_extra_module_dirs_ = None

    def setUp(self):
        if _xpcom_:
            # The tests are run outside of Komodo. If run with PyXPCOM up
            # parts codeintel will try to use the nsIDirectoryService and
            # will query dirs only provided by nsXREDirProvider -- which
            # isn't registered outside of Komodo (XRE_main() isn't called).
            # The KoTestService provides a backup.
            koTestSvc = components.classes["@activestate.com/koTestService;1"] \
                .getService(components.interfaces.koITestService)
            koTestSvc.init()

        if self._ci_test_setup_mgr_:
            env = None
            if self._ci_env_prefs_ is not None:
                env = SimplePrefsEnvironment(**self._ci_env_prefs_)
            self.mgr = Manager(
                extra_module_dirs=self._ci_extra_module_dirs_,
                db_base_dir=self._ci_db_base_dir_ or test_db_base_dir,
                db_catalog_dirs=self._ci_db_catalog_dirs_,
                db_import_everything_langs=self._ci_db_import_everything_langs,
                env=env)
            self.mgr.upgrade()
            self.mgr.initialize()
    
    def tearDown(self):
        if self._ci_test_setup_mgr_:
            self.mgr.finalize()
            self.mgr = None

    def adjust_content(self, content):
        """A hook for subclasses to modify markedup_content before use in
        test cases. This is useful for sharing test cases between pure-
        and multi-lang uses of a given lang.
        """
        return content
    def adjust_pos(self, pos):
        """A accompanying hook for `adjust_content' to adjust trigger
        pos values accordingly.
        """
        return pos

    def _get_buf_and_data(self, markedup_content, lang, path=None, env=None):
        if path is None:
            # Try to ensure no accidental re-use of the same buffer name
            # across the whole test suite. Also try to keep the buffer
            # names relatively short (keeps tracebacks cleaner).
            name = "buf-" + md5(markedup_content).hexdigest()[:16]
            path = os.path.join("<Unsaved>", name)
        content, data = unmark_text(self.adjust_content(markedup_content))
        #print banner(path)
        #sys.stdout.write(content)
        #print banner(None)
        buf = self.mgr.buf_from_content(content, lang=lang, path=path,
                                        env=env)
        return buf, data

    def _get_buf_and_trg(self, markedup_content, lang, path=None,
                         implicit=True, env=None):
        buf, data = self._get_buf_and_data(markedup_content, lang, path, env)
        trg = buf.trg_from_pos(data["pos"], implicit=implicit)
        return buf, trg

    def assertCITDLExprUnderPosIs(self, markedup_content, citdl_expr, lang=None,
                          prefix_filter=None, implicit=True, trigger_name=None,
                          **fields):
        """Assert that the CITDL expression at the current position
        is as expected.

        This uses buf.citdl_expr_under_pos() -- or, for Perl,
        buf.citdl_expr_and_prefix_filter_from_trg().
        Note: This API is a mess right now. C.f. bug 65776.

        The "prefix_filter" optional argument can be used for Perl to test
        the value its relevant function returns.
        """
        if lang is None:
            lang = self.lang
        content, data = unmark_text(
            self.adjust_content(markedup_content))
        path = os.path.join("<Unsaved>", "rand%d" % random.randint(0, 100))
        buf = self.mgr.buf_from_content(content, lang=lang, path=path)
        langintel = self.mgr.langintel_from_lang(lang)
        if trigger_name is None:
            trigger_name = "fakey-completion-type"

        if lang == "Perl":
            trg = Trigger(lang, TRG_FORM_DEFN, trigger_name,
                          data["pos"], implicit=implicit, length=0,
#.........这里部分代码省略.........
开发者ID:ball6847,项目名称:openkomodo,代码行数:103,代码来源:citestsupport.py


注:本文中的codeintel2.manager.Manager.finalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。