MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / MssqlCli

Class MssqlCli

mssqlcli/mssql_cli.py:93–821  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92
93class MssqlCli(object):
94 # pylint: disable=too-many-instance-attributes, useless-object-inheritance
95
96 max_len_prompt = 30
97 default_prompt = '\\d> '
98
99 def set_default_pager(self, config):
100 configured_pager = config['main'].get('pager')
101 os_environ_pager = os.environ.get('PAGER')
102 is_less_installed = is_command_valid(['less', '--version'])
103 default_pager = configured_pager or os_environ_pager or \
104 ('less -SRXF' if is_less_installed else False) or None
105
106 if configured_pager:
107 self.logger.info(
108 'Default pager found in config file: "%s"', configured_pager)
109 elif os_environ_pager:
110 self.logger.info('Default pager found in PAGER environment variable: "%s"',
111 os_environ_pager)
112 elif is_less_installed:
113 self.logger.info('Default pager set to Less')
114 else:
115 self.logger.info(
116 'No default pager found in environment. Using os default pager')
117
118 # Set default set of less recommended options, if they are not already set.
119 # They are ignored if pager is different than less.
120 if not os.environ.get('LESS'):
121 os.environ['LESS'] = '-SRXF'
122
123 if default_pager is not None:
124 os.environ['PAGER'] = default_pager
125 return default_pager
126
127 def __init__(self, options):
128
129 # Load config.
130 c = self.config = get_config(options.mssqlclirc_file)
131
132 self.initialize_logging()
133 self.logger = logging.getLogger(u'mssqlcli.main')
134
135 self.interactive_mode = options.interactive_mode
136
137 self.table_format = c['main']['table_format']
138 self.decimal_format = c['data_formats']['decimal']
139 self.float_format = c['data_formats']['float']
140 self.null_string = c['main'].get('null_string', '<null>')
141 self.expanded_output = c['main']['expand'] == 'always'
142 self.integrated_auth = options.integrated_auth
143 self.less_chatty = bool(
144 options.less_chatty) or c['main'].as_bool('less_chatty') or self.interactive_mode
145
146 keyword_casing = c['main']['keyword_casing']
147 self.settings = {
148 'casing_file': get_casing_file(c),
149 'generate_casing_file': c['main'].as_bool('generate_casing_file'),
150 'generate_aliases': c['main'].as_bool('generate_aliases'),

Callers 6

run_cli_withFunction · 0.90
create_mssql_cliFunction · 0.90
RowLimitTestsClass · 0.90
test_no_limitMethod · 0.90

Calls

no outgoing calls

Tested by 4

create_mssql_cliFunction · 0.72
test_no_limitMethod · 0.72