From 6fd2806e6f4062c452b81565655759d228d008df Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Wed, 4 Nov 2015 18:21:59 -0800 Subject: Switch the location of log/history file based on OS. --- pgcli/config.py | 4 ++-- pgcli/main.py | 8 ++++++-- pgcli/pgclirc | 10 ++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pgcli/config.py b/pgcli/config.py index 3911362a..5f46e7e5 100644 --- a/pgcli/config.py +++ b/pgcli/config.py @@ -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() diff --git a/pgcli/main.py b/pgcli/main.py index 4cdd3169..5c9e42a1 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -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, diff --git a/pgcli/pgclirc b/pgcli/pgclirc index 15c39b6b..d592454b 100644 --- a/pgcli/pgclirc +++ b/pgcli/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". -- cgit v1.2.3 From b84013ffa2d7ccab1896ba8b52d6819680dafb58 Mon Sep 17 00:00:00 2001 From: Iryna Cherniavska Date: Thu, 5 Nov 2015 08:15:32 -0800 Subject: Updated named queries and config migration to use new paths. --- pgcli/main.py | 11 ++++++----- pgcli/pgcompleter.py | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pgcli/main.py b/pgcli/main.py index 5c9e42a1..6c44905e 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -555,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) diff --git a/pgcli/pgcompleter.py b/pgcli/pgcompleter.py index 23b3a397..b5e4211b 100644 --- a/pgcli/pgcompleter.py +++ b/pgcli/pgcompleter.py @@ -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): -- cgit v1.2.3