summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarikg <darikg@users.noreply.github.com>2015-11-06 06:37:12 -0500
committerdarikg <darikg@users.noreply.github.com>2015-11-06 06:37:12 -0500
commitf0b8c71f66dad8a06e3d5e9d4a379d955fc879f9 (patch)
tree3362e6e5004d952c789b492bb5e639cc2bc69f02
parent2c1c493977dbb5d208815b1adc1413084d636813 (diff)
parentb84013ffa2d7ccab1896ba8b52d6819680dafb58 (diff)
Merge pull request #407 from dbcli/amjith/fix_log_file_windows
Switch the location of log/history file based on OS.
-rw-r--r--pgcli/config.py4
-rwxr-xr-xpgcli/main.py19
-rw-r--r--pgcli/pgclirc10
-rw-r--r--pgcli/pgcompleter.py5
4 files changed, 25 insertions, 13 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..6c44905e 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,
@@ -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)
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".
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):