Exemple #1
0
def main() -> int:
    args = setup()
    if not args.disable_bblfsh_autorun:
        ensure_bblfsh_is_running()

    client = BblfshClient(args.endpoint)
    ctx = client.parse(args.file, args.language)

    if args.query:
        run_query(ctx, args.query, array=args.array)
    else:
        pprint.pprint(ctx.load())

    return 0
def main():
    args = setup()
    if not args.disable_bblfsh_autorun:
        ensure_bblfsh_is_running()

    client = BblfshClient(args.endpoint)
    response = client.parse(args.file, args.language)
    root = response.uast
    if len(response.errors):
        sys.stderr.write("\n".join(response.errors) + "\n")
    query = args.query
    if query:
        run_query(root, query, args.mapn, args.array)
    else:
        print(root)
Exemple #3
0
def ensure_bblfsh_is_running_noexc():
    """
    Launches the Babelfish server, if it is possible and needed.

    :return: None
    """
    try:
        ensure_bblfsh_is_running()
    except:
        log = logging.getLogger("bblfsh")
        message = "Failed to ensure that the Babelfish server is running."
        if log.isEnabledFor(logging.DEBUG):
            log.exception(message)
        else:
            log.warning(message)
Exemple #4
0
def ensure_bblfsh_is_running_noexc(bblfsh_endpoint=None):
    """
    Launches the Babelfish server, if it is possible and needed.

    :param bblfsh_endpoint: bblfsh endpoint to check.
    :return: None
    """
    if resolve_bblfsh_endpoint(bblfsh_endpoint) != DEFAULT_BBLFSH_ENDPOINTS[0]:
        return
    try:
        ensure_bblfsh_is_running()
    except:
        log = logging.getLogger("bblfsh")
        message = "Failed to ensure that the Babelfish server is running."
        if log.isEnabledFor(logging.DEBUG):
            log.exception(message)
        else:
            log.warning(message)
Exemple #5
0
def main() -> int:
    args = setup()
    # TODO: parse the address properly
    localAddrs = ('localhost', '0.0.0.0', '127.0.0.1', '[::1]')
    if args.endpoint.startswith(
            localAddrs) and not args.disable_bblfsh_autorun:
        if not ensure_bblfsh_is_running():
            return 1

    client = BblfshClient(args.endpoint)
    ctx = client.parse(args.file, args.language)

    if args.query:
        run_query(ctx, args.query, array=args.array)
    else:
        pprint.pprint(ctx.load())

    return 0
Exemple #6
0
 def setUpClass(cls: t.Any) -> None:
     cls.BBLFSH_SERVER_EXISTED = ensure_bblfsh_is_running()
Exemple #7
0
 def setUpClass(cls):
     cls.BBLFSH_SERVER_EXISTED = ensure_bblfsh_is_running()