Do not fail in python2.7
This commit is contained in:
parent
d9372bd5b5
commit
1f86901f00
1 changed files with 24 additions and 19 deletions
|
@ -4,18 +4,23 @@
|
|||
import os
|
||||
import atexit
|
||||
import readline
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import pathlib
|
||||
except ImportError: # not part of python2
|
||||
pass
|
||||
else:
|
||||
|
||||
if readline.get_current_history_length() == 0:
|
||||
state_home = os.environ.get("XDG_STATE_HOME")
|
||||
if state_home is None:
|
||||
state_home = Path.home() / ".local" / "state"
|
||||
state_home = pathlib.Path.home() / ".local" / "state"
|
||||
else:
|
||||
state_home = Path(state_home)
|
||||
state_home = pathlib.Path(state_home)
|
||||
|
||||
history_path = state_home / "python" / "history"
|
||||
if history_path.is_dir():
|
||||
raise OSError(f"'{history_path}' cannot be a directory")
|
||||
raise OSError(history_path + " cannot be a directory")
|
||||
|
||||
history = str(history_path)
|
||||
|
||||
|
|
Loading…
Reference in a new issue