mirror of
https://github.com/dbcli/pgcli.git
synced 2024-09-19 01:37:26 +03:00
Merge pull request #407 from dbcli/amjith/fix_log_file_windows
Switch the location of log/history file based on OS.
This commit is contained in:
commit
f0b8c71f66
@ -6,9 +6,9 @@ from configobj import ConfigObj
|
||||
|
||||
def config_location():
|
||||
if platform.system() == 'Windows':
|
||||
return os.getenv('USERPROFILE') + '\AppData\Local\dbcli\pgcli\config'
|
||||
return os.getenv('USERPROFILE') + '\\AppData\\Local\\dbcli\\pgcli\\'
|
||||
else:
|
||||
return expanduser('~/.config/pgcli/config')
|
||||
return expanduser('~/.config/pgcli/')
|
||||
|
||||
def load_config(usr_cfg, def_cfg=None):
|
||||
cfg = ConfigObj()
|
||||
|
@ -154,6 +154,8 @@ class PGCli(object):
|
||||
def initialize_logging(self):
|
||||
|
||||
log_file = self.config['main']['log_file']
|
||||
if log_file == 'default':
|
||||
log_file = config_location() + 'log'
|
||||
log_level = self.config['main']['log_level']
|
||||
|
||||
level_map = {'CRITICAL': logging.CRITICAL,
|
||||
@ -382,6 +384,8 @@ class PGCli(object):
|
||||
])
|
||||
|
||||
history_file = self.config['main']['history_file']
|
||||
if history_file == 'default':
|
||||
history_file = config_location() + 'history'
|
||||
with self._completer_lock:
|
||||
buf = PGBuffer(
|
||||
always_multiline=self.multi_line,
|
||||
@ -535,8 +539,8 @@ class PGCli(object):
|
||||
@click.option('-v', '--version', is_flag=True, help='Version of pgcli.')
|
||||
@click.option('-d', '--dbname', default='', envvar='PGDATABASE',
|
||||
help='database name to connect to.')
|
||||
@click.option('--pgclirc', default=config_location(), envvar='PGCLIRC',
|
||||
help='Location of pgclirc file.')
|
||||
@click.option('--pgclirc', default=config_location() + 'config',
|
||||
envvar='PGCLIRC', help='Location of pgclirc file.')
|
||||
@click.argument('database', default=lambda: None, envvar='PGDATABASE', nargs=1)
|
||||
@click.argument('username', default=lambda: None, envvar='PGUSER', nargs=1)
|
||||
def cli(database, user, host, port, prompt_passwd, never_prompt, dbname,
|
||||
@ -551,15 +555,16 @@ def cli(database, user, host, port, prompt_passwd, never_prompt, dbname,
|
||||
os.makedirs(config_dir)
|
||||
|
||||
# Migrate the config file from old location.
|
||||
config_full_path = config_location() + 'config'
|
||||
if os.path.exists(os.path.expanduser('~/.pgclirc')):
|
||||
if not os.path.exists(config_location()):
|
||||
shutil.move(os.path.expanduser('~/.pgclirc'), config_location())
|
||||
if not os.path.exists(config_full_path):
|
||||
shutil.move(os.path.expanduser('~/.pgclirc'), config_full_path)
|
||||
print ('Config file (~/.pgclirc) moved to new location',
|
||||
config_location())
|
||||
config_full_path)
|
||||
else:
|
||||
print ('Config file is now located at', config_location())
|
||||
print ('Config file is now located at', config_full_path)
|
||||
print ('Please move the existing config file ~/.pgclirc to',
|
||||
config_location())
|
||||
config_full_path)
|
||||
|
||||
pgcli = PGCli(prompt_passwd, never_prompt, pgclirc_file=pgclirc)
|
||||
|
||||
|
@ -16,10 +16,16 @@ wider_completion_menu = False
|
||||
multi_line = False
|
||||
|
||||
# log_file location.
|
||||
log_file = ~/.config/pgcli/log
|
||||
# In Unix/Linux: ~/.config/pgcli/log
|
||||
# In Windows: %USERPROFILE%\AppData\Local\dbcli\pgcli\log
|
||||
# %USERPROFILE% is typically C:\Users\{username}
|
||||
log_file = default
|
||||
|
||||
# history_file location.
|
||||
history_file = ~/.config/pgcli/history
|
||||
# In Unix/Linux: ~/.config/pgcli/history
|
||||
# In Windows: %USERPROFILE%\AppData\Local\dbcli\pgcli\history
|
||||
# %USERPROFILE% is typically C:\Users\{username}
|
||||
history_file = default
|
||||
|
||||
# Default log level. Possible values: "CRITICAL", "ERROR", "WARNING", "INFO"
|
||||
# and "DEBUG".
|
||||
|
@ -8,7 +8,7 @@ from prompt_toolkit.completion import Completer, Completion
|
||||
from .packages.sqlcompletion import suggest_type
|
||||
from .packages.parseutils import last_word
|
||||
from .packages.pgliterals.main import get_literals
|
||||
from .config import load_config
|
||||
from .config import load_config, config_location
|
||||
|
||||
try:
|
||||
from collections import Counter
|
||||
@ -18,7 +18,8 @@ except ImportError:
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
NamedQueries.instance = NamedQueries.from_config(load_config('~/.pgclirc'))
|
||||
NamedQueries.instance = NamedQueries.from_config(
|
||||
load_config(config_location() + 'config'))
|
||||
|
||||
|
||||
class PGCompleter(Completer):
|
||||
|
Loading…
Reference in New Issue
Block a user