Change docstrings.

This commit is contained in:
Eadaen1 2020-09-20 18:42:10 +01:00
parent d7141856ae
commit f02e70d905
3 changed files with 13 additions and 15 deletions

View file

@ -157,17 +157,18 @@ class History:
@staticmethod
def remember_history_check(f):
"""Allows the decorated function to run only if
self.remember_history is True.
"""Jumps over the decorated function if self.remember_history is False.
"""
def new_f(self, *args, **kwargs):
def out_f(self, *args, **kwargs):
if self.remember_history:
return f(self, *args, **kwargs)
else:
return
return new_f
return out_f
def clear(self):
"""Wipes the current session from both the disk and memory."""
"""Clears the history of the current session from both the disk and
memory.
"""
pass

View file

@ -509,8 +509,11 @@ class JsonHistory(History):
time.sleep(0.1) # don't monopolize the thread (or Python GIL?)
def clear(self):
"""Clears the current session's history from both memory and disk."""
def wipe_memory(hist):
"""Wipes history entries from memory. Keeps sessionid and other
metadata."""
hist.buffer = []
self.tss = JsonCommandField("ts", self)
self.inps = JsonCommandField("inp", self)
@ -521,6 +524,5 @@ class JsonHistory(History):
wipe_memory(self)
# Flush empty history object to disk. This overwrites the old commands,
# but keeps basic session metadata to prevent things from breaking.
# Flush empty history object to disk, overwriting previous data.
self.flush()

View file

@ -299,21 +299,16 @@ class SqliteHistory(History):
continue
def clear(self):
"""Clears the current session's history from both memory and disk."""
# Wipe memory
self.inps = []
self.rtns = []
self.outs = []
self.tss = []
# Add in dummy command. Delete items has to leave one.
#self.append({"inp": "", "rtn": 0, "ts": (0, 0.5)})
# Wipe data from disk.
#xh_sqlite_delete_items(size_to_keep=1, filename=self.filename) # todo this leads to data loss from other sessions. Need to fix.
# Wipe the current session's entries from the database.
sql = "DELETE FROM xonsh_history WHERE sessionid = ?"
with _xh_sqlite_get_conn(filename=self.filename) as conn:
c = conn.cursor()
_xh_sqlite_create_history_table(c)
c.execute(sql, (str(self.sessionid),))
# "DELETE FROM xonsh_history WHERE sessionid == ?", self.sessionid # check