コード例 #1
0
ファイル: voltsql.py プロジェクト: qq690712575/voltdb
    def __init__(self, server, port, user, password, credentials, kerberos, query_timeout, ssl, ssl_set,
                 output_format, output_skip_metadata, stop_on_error):
        self.server = server
        self.port = port
        self.user = user
        self.password = password
        self.credentials = credentials
        self.kerberos = kerberos
        self.query_timeout = query_timeout
        self.ssl = ssl
        self.ssl_set = ssl_set
        self.output_format = output_format
        self.output_skip_metadata = output_skip_metadata
        self.stop_on_error = stop_on_error

        self.completer = VoltCompleter()
        self.refresher = VoltRefresher()
        self.executor = VoltExecutor(self.server, self.port, self.user, self.password,
                                     self.query_timeout, self.kerberos, self.ssl, self.ssl_set, self.credentials)
        self.multiline = False
        self.auto_refresh = True
コード例 #2
0
ファイル: voltsql.py プロジェクト: alexeevm/voltdb
    def __init__(self, server, port, user, password, credentials, kerberos, query_timeout, ssl, ssl_set,
                 output_format, output_skip_metadata, stop_on_error):
        self.server = server
        self.port = port
        self.user = user
        self.password = password
        self.credentials = credentials
        self.kerberos = kerberos
        self.query_timeout = query_timeout
        self.ssl = ssl
        self.ssl_set = ssl_set
        self.output_format = output_format
        self.output_skip_metadata = output_skip_metadata
        self.stop_on_error = stop_on_error

        self.completer = VoltCompleter()
        self.refresher = VoltRefresher()
        self.executor = VoltExecutor(self.server, self.port, self.user, self.password,
                                     self.query_timeout, self.kerberos, self.ssl, self.ssl_set, self.credentials)
        self.multiline = False
        self.auto_refresh = True
コード例 #3
0
ファイル: voltsql.py プロジェクト: qq690712575/voltdb
class VoltCli(object):
    def __init__(self, server, port, user, password, credentials, kerberos, query_timeout, ssl, ssl_set,
                 output_format, output_skip_metadata, stop_on_error):
        self.server = server
        self.port = port
        self.user = user
        self.password = password
        self.credentials = credentials
        self.kerberos = kerberos
        self.query_timeout = query_timeout
        self.ssl = ssl
        self.ssl_set = ssl_set
        self.output_format = output_format
        self.output_skip_metadata = output_skip_metadata
        self.stop_on_error = stop_on_error

        self.completer = VoltCompleter()
        self.refresher = VoltRefresher()
        self.executor = VoltExecutor(self.server, self.port, self.user, self.password,
                                     self.query_timeout, self.kerberos, self.ssl, self.ssl_set, self.credentials)
        self.multiline = False
        self.auto_refresh = True

    def create_key_bindings(self):
        bindings = KeyBindings()

        @bindings.add('f2')
        def _(event):
            self.completer.smart_completion = not self.completer.smart_completion

        @bindings.add('f3')
        def _(event):
            self.multiline = not self.multiline
            event.app.current_buffer.multiline = ~event.app.current_buffer.multiline

        @bindings.add('f4')
        def _(event):
            self.auto_refresh = not self.auto_refresh

        return bindings

    def bottom_toolbar(self):
        toolbar_result = []
        if self.completer.smart_completion:
            toolbar_result.append(
                '<style bg="ansiyellow">[F2]</style> <b><style bg="ansigreen">Smart Completion:</style></b> ON')
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F2]</style> <b><style bg="ansired">Smart Completion:</style></b> OFF')

        if self.multiline:
            toolbar_result.append(
                '<style bg="ansiyellow">[F3]</style> <b><style bg="ansigreen">Multiline:</style></b> ON')
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F3]</style> <b><style bg="ansired">Multiline:</style></b> OFF')
        if self.auto_refresh:
            toolbar_result.append(
                '<style bg="ansiyellow">[F4]</style> <b><style bg="ansigreen">Auto Refresh:</style></b> ON')
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F4]</style> <b><style bg="ansired">Auto Refresh:</style></b> OFF')

        return HTML('  '.join(toolbar_result))

    def run_cli(self):
        # get catalog data before start
        self.refresher.refresh(self.executor, self.completer, [])
        # Load history into completer so it can learn user preferences
        history = FileHistory(os.path.expanduser('~/.voltsql_history'))
        self.completer.init_prioritization_from_history(history)

        session = PromptSession(
            lexer=PygmentsLexer(SqlLexer), completer=self.completer, style=style,
            auto_suggest=AutoSuggestFromHistory(), bottom_toolbar=self.bottom_toolbar,
            key_bindings=self.create_key_bindings(), multiline=True,
            history=history)

        # directly assign multiline=False in PromptSession constructor will cause some unexpected behavior
        # due to some issue i don't know. This is a workaround.
        if not self.multiline:
            session.default_buffer.multiline = ~session.default_buffer.multiline

        option_str = "--servers={server} --port={port_number}{user}{password}{credentials}" \
                     "{ssl}{output_format}{output_skip_metadata}{stop_on_error}{kerberos} " \
                     "--query-timeout={number_of_milliseconds}".format(
            server=self.server, port_number=self.port,
            user="******" + self.user if self.user else "",
            password="******" + self.password if self.password else "",
            credentials=" --credentials=" + self.credentials if self.credentials else "",
            kerberos=" --kerberos=" + self.kerberos if self.kerberos else "",
            number_of_milliseconds=self.query_timeout,
            ssl=" --ssl=" + self.ssl_set if self.ssl_set else " --ssl" if self.ssl else "",
            output_format=" --output-format=" + self.output_format if self.output_format else "",
            output_skip_metadata=" --output-skip-metadata" if self.output_skip_metadata else "",
            stop_on_error=" --stop-on-error=false" if not self.stop_on_error else ""
        )
        while True:
            try:
                sql_cmd = session.prompt('> ')
            except KeyboardInterrupt:
                break
            except EOFError:
                break
            else:
                if sql_cmd.lower() == "update":
                    # use "update" command to force a fresh
                    self.refresher.refresh(self.executor, self.completer, [])
                    continue
                if sql_cmd.strip().lower() in ("quit", "quit;", "exit", "exit;"):
                    # exit
                    break
                if sql_cmd.strip().lower() in ("help", "help;"):
                    print(README)
                    continue
                call(
                    "echo \"{sql_cmd}\" | sqlcmd {options}".format(
                        sql_cmd=sql_cmd, options=option_str),
                    shell=True)
                if self.auto_refresh:
                    self.refresher.refresh(self.executor, self.completer, [])
        print('GoodBye!')
コード例 #4
0
class VoltCli(object):
    def __init__(self, server, port, user, password, credentials, kerberos,
                 query_timeout, ssl, ssl_set, output_format,
                 output_skip_metadata, stop_on_error):
        self.server = server
        self.port = port
        self.user = user
        self.password = password
        self.credentials = credentials
        self.kerberos = kerberos
        self.query_timeout = query_timeout
        self.ssl = ssl
        self.ssl_set = ssl_set
        self.output_format = output_format
        self.output_skip_metadata = output_skip_metadata
        self.stop_on_error = stop_on_error

        self.completer = VoltCompleter()
        self.refresher = VoltRefresher()
        self.executor = VoltExecutor(self.server, self.port, self.user,
                                     self.password, self.query_timeout,
                                     self.kerberos, self.ssl, self.ssl_set,
                                     self.credentials)
        self.multiline = True
        self.auto_refresh = True

    def create_key_bindings(self):
        bindings = KeyBindings()

        @bindings.add('f2')
        def _(event):
            self.completer.smart_completion = not self.completer.smart_completion

        @bindings.add('f3')
        def _(event):
            self.multiline = not self.multiline
            event.app.current_buffer.multiline = ~event.app.current_buffer.multiline

        @bindings.add('f4')
        def _(event):
            self.auto_refresh = not self.auto_refresh

        return bindings

    def bottom_toolbar(self):
        toolbar_result = []
        if self.completer.smart_completion:
            toolbar_result.append(
                '<style bg="ansiyellow">[F2]</style> <b><style bg="ansigreen">Smart Completion:</style></b> ON'
            )
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F2]</style> <b><style bg="ansired">Smart Completion:</style></b> OFF'
            )

        if self.multiline:
            toolbar_result.append(
                '<style bg="ansiyellow">[F3]</style> <b><style bg="ansigreen">Multiline:</style></b> ON'
            )
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F3]</style> <b><style bg="ansired">Multiline:</style></b> OFF'
            )
        if self.auto_refresh:
            toolbar_result.append(
                '<style bg="ansiyellow">[F4]</style> <b><style bg="ansigreen">Auto Refresh:</style></b> ON'
            )
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F4]</style> <b><style bg="ansired">Auto Refresh:</style></b> OFF'
            )

        return HTML('  '.join(toolbar_result))

    def run_cli(self):
        # get catalog data before start
        self.refresher.refresh(self.executor, self.completer, [])
        session = PromptSession(lexer=PygmentsLexer(SqlLexer),
                                completer=self.completer,
                                style=style,
                                auto_suggest=AutoSuggestFromHistory(),
                                bottom_toolbar=self.bottom_toolbar,
                                key_bindings=self.create_key_bindings(),
                                multiline=self.multiline)
        option_str = "--servers={server} --port={port_number}{user}{password}{credentials}" \
                     "{ssl}{output_format}{output_skip_metadata}{stop_on_error}{kerberos} " \
                     "--query-timeout={number_of_milliseconds}".format(
                        server=self.server, port_number=self.port,
                        user="******" + self.user if self.user else "",
                        password="******" + self.password if self.password else "",
                        credentials=" --credentials=" + self.credentials if self.credentials else "",
                        kerberos=" --kerberos=" + self.kerberos if self.kerberos else "",
                        number_of_milliseconds=self.query_timeout,
                        ssl=" --ssl=" + self.ssl_set if self.ssl_set else " --ssl" if self.ssl else "",
                        output_format=" --output-format=" + self.output_format if self.output_format else "",
                        output_skip_metadata=" --output-skip-metadata" if self.output_skip_metadata else "",
                        stop_on_error=" --stop-on-error=false" if not self.stop_on_error else ""
                        )
        while True:
            try:
                sql_cmd = session.prompt('> ')
            except KeyboardInterrupt:
                break
            except EOFError:
                break
            else:
                if sql_cmd.lower() == "update":
                    # use "update" command to force a fresh
                    self.refresher.refresh(self.executor, self.completer, [])
                    continue
                call("echo \"{sql_cmd}\" | sqlcmd {options}".format(
                    sql_cmd=sql_cmd, options=option_str),
                     shell=True)
                if self.auto_refresh:
                    self.refresher.refresh(self.executor, self.completer, [])
        print('GoodBye!')
コード例 #5
0
ファイル: voltsql.py プロジェクト: alexeevm/voltdb
class VoltCli(object):
    def __init__(self, server, port, user, password, credentials, kerberos, query_timeout, ssl, ssl_set,
                 output_format, output_skip_metadata, stop_on_error):
        self.server = server
        self.port = port
        self.user = user
        self.password = password
        self.credentials = credentials
        self.kerberos = kerberos
        self.query_timeout = query_timeout
        self.ssl = ssl
        self.ssl_set = ssl_set
        self.output_format = output_format
        self.output_skip_metadata = output_skip_metadata
        self.stop_on_error = stop_on_error

        self.completer = VoltCompleter()
        self.refresher = VoltRefresher()
        self.executor = VoltExecutor(self.server, self.port, self.user, self.password,
                                     self.query_timeout, self.kerberos, self.ssl, self.ssl_set, self.credentials)
        self.multiline = False
        self.auto_refresh = True

    def create_key_bindings(self):
        bindings = KeyBindings()

        @bindings.add('f2')
        def _(event):
            self.completer.smart_completion = not self.completer.smart_completion

        @bindings.add('f3')
        def _(event):
            self.auto_refresh = not self.auto_refresh

        @bindings.add('f4')
        def _(event):
            self.multiline = not self.multiline
            event.app.current_buffer.multiline = ~event.app.current_buffer.multiline

        return bindings

    def bottom_toolbar(self):
        toolbar_result = []
        if self.completer.smart_completion:
            toolbar_result.append(
                '<style bg="ansiyellow">[F2]</style> <b><style bg="ansigreen">Smart Completion:</style></b> <b>ON</b>')
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F2]</style> <b><style bg="ansired">Smart Completion:</style></b> OFF')
        if self.auto_refresh:
            toolbar_result.append(
                '<style bg="ansiyellow">[F3]</style> <b><style bg="ansigreen">Auto Refresh:</style></b> <b>ON</b>')
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F3]</style> <b><style bg="ansired">Auto Refresh:</style></b> OFF')
        if self.multiline:
            toolbar_result.append(
                '<style bg="ansiyellow">[F4]</style> <b><style bg="ansigreen">Multiline:</style></b> <b>ON</b>')
            toolbar_result.append('<style bg="ansiyellow">Execute: [ESC+ENTER]</style>')
        else:
            toolbar_result.append(
                '<style bg="ansiyellow">[F4]</style> <b><style bg="ansired">Multiline:</style></b> OFF')

        return HTML('  '.join(toolbar_result))

    def run_cli(self):
        # get catalog data before start
        self.refresher.refresh(self.executor, self.completer, [])
        # Load history into completer so it can learn user preferences
        history = FileHistory(os.path.expanduser('~/.voltsql_history'))
        self.completer.init_prioritization_from_history(history)

        session = PromptSession(
            lexer=PygmentsLexer(SqlLexer), completer=self.completer, style=style,
            auto_suggest=AutoSuggestFromHistory(), bottom_toolbar=self.bottom_toolbar,
            key_bindings=self.create_key_bindings(), multiline=True,
            history=history)

        # directly assign multiline=False in PromptSession constructor will cause some unexpected behavior
        # due to some issue i don't know. This is a workaround.
        if not self.multiline:
            session.default_buffer.multiline = ~session.default_buffer.multiline

        option_str = "--servers={server} --port={port_number}{user}{password}{credentials}" \
                     "{ssl}{output_format}{output_skip_metadata}{stop_on_error}{kerberos} " \
                     "--query-timeout={number_of_milliseconds}".format(
            server=self.server, port_number=self.port,
            user="******" + self.user if self.user else "",
            password="******" + self.password if self.password else "",
            credentials=" --credentials=" + self.credentials if self.credentials else "",
            kerberos=" --kerberos=" + self.kerberos if self.kerberos else "",
            number_of_milliseconds=self.query_timeout,
            ssl=" --ssl=" + self.ssl_set if self.ssl_set else " --ssl" if self.ssl else "",
            output_format=" --output-format=" + self.output_format if self.output_format else "",
            output_skip_metadata=" --output-skip-metadata" if self.output_skip_metadata else "",
            stop_on_error=" --stop-on-error=false" if not self.stop_on_error else ""
        )
        while True:
            try:
                sql_cmd = session.prompt('> ')
            except KeyboardInterrupt:
                break
            except EOFError:
                break
            else:
                if sql_cmd.lower() == "refresh":
                    # use "refresh" command to force a fresh
                    self.refresher.refresh(self.executor, self.completer, [])
                    continue
                if sql_cmd.strip().lower() in ("quit", "quit;", "exit", "exit;"):
                    # exit
                    break
                if sql_cmd.strip().lower() in ("help", "help;"):
                    print(README)
                    continue
                call(
                    "echo \"{sql_cmd}\" | sqlcmd {options}".format(
                        sql_cmd=sql_cmd, options=option_str),
                    shell=True)
                if self.auto_refresh:
                    self.refresher.refresh(self.executor, self.completer, [])
        print('GoodBye!')