diff options
author | kotfu <kotfu@kotfu.net> | 2019-05-25 15:03:18 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2019-05-25 15:03:18 -0600 |
commit | 8fd6d50a58764ad0f8fa6e38fbce60b2b2a52014 (patch) | |
tree | ecfd7ba5de8a063684368d34b1448bafeb22dbae | |
parent | 5fe14a26eb9abe5a198eb38b07b3b7af4225802c (diff) | |
download | cmd2-git-8fd6d50a58764ad0f8fa6e38fbce60b2b2a52014.tar.gz |
switch _initialize_history() from os.path to pathlib
-rw-r--r-- | cmd2/cmd2.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 8310da93..f7c91172 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -34,6 +34,7 @@ import cmd import glob import inspect import os +import pathlib import pickle import re import sys @@ -3465,29 +3466,29 @@ class Cmd(cmd.Cmd): self.persistent_history_file = hist_file return - hist_file = os.path.expanduser(hist_file) + histpath = pathlib.Path(hist_file).expanduser().resolve() # first we try and unpickle the history file history = History() # on Windows, trying to open a directory throws a permission # error, not a `IsADirectoryError`. So we'll check it ourselves. - if os.path.isdir(hist_file): + if histpath.is_dir(): msg = "persistent history file '{}' is a directory" - self.perror(msg.format(hist_file)) + self.perror(msg.format(histpath)) return try: - with open(hist_file, 'rb') as fobj: + with open(str(histpath), 'rb') as fobj: history = pickle.load(fobj) except (FileNotFoundError, KeyError, EOFError): pass except OSError as ex: msg = "can not read persistent history file '{}': {}" - self.perror(msg.format(hist_file, ex), traceback_war=False) + self.perror(msg.format(histpath, ex), traceback_war=False) return self.history = history - self.persistent_history_file = hist_file + self.persistent_history_file = str(histpath) # populate readline history if rl_type != RlType.NONE: |