Show More
@@ -5,8 +5,8 b' An application for managing IPython history.' | |||
|
5 | 5 | To be invoked as the `ipython history` subcommand. |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | import os | |
|
9 | 8 | import sqlite3 |
|
9 | from pathlib import Path | |
|
10 | 10 | |
|
11 | 11 | from traitlets.config.application import Application |
|
12 | 12 | from .application import BaseIPythonApplication |
@@ -52,8 +52,8 b' class HistoryTrim(BaseIPythonApplication):' | |||
|
52 | 52 | )) |
|
53 | 53 | |
|
54 | 54 | def start(self): |
|
55 | profile_dir = self.profile_dir.location | |
|
56 |
hist_file = |
|
|
55 | profile_dir = Path(self.profile_dir.location) | |
|
56 | hist_file = profile_dir / "history.sqlite" | |
|
57 | 57 | con = sqlite3.connect(hist_file) |
|
58 | 58 | |
|
59 | 59 | # Grab the recent history from the current database. |
@@ -77,12 +77,12 b' class HistoryTrim(BaseIPythonApplication):' | |||
|
77 | 77 | con.close() |
|
78 | 78 | |
|
79 | 79 | # Create the new history database. |
|
80 |
new_hist_file = |
|
|
80 | new_hist_file = profile_dir / "history.sqlite.new" | |
|
81 | 81 | i = 0 |
|
82 |
while |
|
|
82 | while new_hist_file.exists(): | |
|
83 | 83 | # Make sure we don't interfere with an existing file. |
|
84 | 84 | i += 1 |
|
85 |
new_hist_file = |
|
|
85 | new_hist_file = profile_dir / ("history.sqlite.new" + str(i)) | |
|
86 | 86 | new_db = sqlite3.connect(new_hist_file) |
|
87 | 87 | new_db.execute("""CREATE TABLE IF NOT EXISTS sessions (session integer |
|
88 | 88 | primary key autoincrement, start timestamp, |
@@ -106,16 +106,16 b' class HistoryTrim(BaseIPythonApplication):' | |||
|
106 | 106 | |
|
107 | 107 | if self.backup: |
|
108 | 108 | i = 1 |
|
109 |
backup_hist_file = |
|
|
110 |
while |
|
|
109 | backup_hist_file = profile_dir / ("history.sqlite.old.%d" % i) | |
|
110 | while backup_hist_file.exists(): | |
|
111 | 111 | i += 1 |
|
112 |
backup_hist_file = |
|
|
113 |
|
|
|
112 | backup_hist_file = profile_dir / ("history.sqlite.old.%d" % i) | |
|
113 | hist_file.rename(backup_hist_file) | |
|
114 | 114 | print("Backed up longer history file to", backup_hist_file) |
|
115 | 115 | else: |
|
116 |
|
|
|
116 | hist_file.unlink() | |
|
117 | 117 | |
|
118 |
|
|
|
118 | new_hist_file.rename(hist_file) | |
|
119 | 119 | |
|
120 | 120 | class HistoryClear(HistoryTrim): |
|
121 | 121 | description = clear_hist_help |
General Comments 0
You need to be logged in to leave comments.
Login now