def __init__(self, region, aws_access_key_id, aws_secret_access_key, s3_staging_dir, work_group, athenaclirc, profile, database): config_files = [DEFAULT_CONFIG_FILE] if os.path.exists(os.path.expanduser(athenaclirc)): config_files.append(athenaclirc) _cfg = self.config = read_config_files(config_files) self.init_logging(_cfg['main']['log_file'], _cfg['main']['log_level']) aws_config = AWSConfig(aws_access_key_id, aws_secret_access_key, region, s3_staging_dir, work_group, profile, _cfg) try: self.connect(aws_config, database) except Exception as e: self.echo(str(e), err=True, fg='red') err_msg = ''' There was an error while connecting to AWS Athena. It could be caused due to missing/incomplete configuration. Please verify the configuration in %s and run athenacli again. For more details about the error, you can check the log file: %s''' % ( athenaclirc, _cfg['main']['log_file']) self.echo(err_msg) LOGGER.exception('error: %r', e) sys.exit(1) special.set_timing_enabled(_cfg['main'].as_bool('timing')) self.multi_line = _cfg['main'].as_bool('multi_line') self.key_bindings = _cfg['main']['key_bindings'] self.prompt = _cfg['main']['prompt'] or self.DEFAULT_PROMPT self.destructive_warning = _cfg['main']['destructive_warning'] self.syntax_style = _cfg['main']['syntax_style'] self.prompt_continuation_format = _cfg['main']['prompt_continuation'] self.formatter = TabularOutputFormatter(_cfg['main']['table_format']) self.formatter.cli = self sql_format.register_new_formatter(self.formatter) self.cli_style = _cfg['colors'] self.output_style = style_factory_output(self.syntax_style, self.cli_style) self.completer = AthenaCompleter() self._completer_lock = threading.Lock() self.completion_refresher = CompletionRefresher() self.prompt_app = None self.query_history = [] # Register custom special commands. self.register_special_commands()
def __init__(self, region=None, aws_access_key_id=None, aws_secret_access_key=None, s3_staging_dir=None, athenaclirc=None, database=None): config_files = (DEFAULT_CONFIG_FILE, athenaclirc) _cfg = self.config = read_config_files(config_files) self.init_logging(_cfg['main']['log_file'], _cfg['main']['log_level']) self.connect(aws_access_key_id, aws_secret_access_key, s3_staging_dir, region, database) special.set_timing_enabled(_cfg['main'].as_bool('timing')) self.multi_line = _cfg['main'].as_bool('multi_line') self.key_bindings = _cfg['main']['key_bindings'] self.prompt = _cfg['main']['prompt'] or self.DEFAULT_PROMPT self.destructive_warning = _cfg['main']['destructive_warning'] self.syntax_style = _cfg['main']['syntax_style'] self.prompt_continuation_format = _cfg['main']['prompt_continuation'] self.formatter = TabularOutputFormatter(_cfg['main']['table_format']) self.formatter.cli = self sql_format.register_new_formatter(self.formatter) self.output_style = style_factory(self.syntax_style, {}) self.completer = AthenaCompleter() self._completer_lock = threading.Lock() self.completion_refresher = CompletionRefresher() self.cli = None self.query_history = [] # Register custom special commands. self.register_special_commands()