Show More
@@ -65,8 +65,23 b' class HistoryAccessor(Configurable):' | |||
|
65 | 65 | |
|
66 | 66 | This is intended for use by standalone history tools. IPython shells use |
|
67 | 67 | HistoryManager, below, which is a subclass of this.""" |
|
68 | ||
|
68 | 69 | # String holding the path to the history file |
|
69 |
hist_file = Unicode(config=True |
|
|
70 | hist_file = Unicode(config=True, | |
|
71 | help="""Path to file to use for SQLite history database. | |
|
72 | ||
|
73 | By default, IPython will put the history database in the IPython profile | |
|
74 | directory. If you would rather share one history among profiles, | |
|
75 | you ca set this value in each, so that they are consistent. | |
|
76 | ||
|
77 | Due to an issue with fcntl, SQLite is known to misbehave on some NFS mounts. | |
|
78 | If you see IPython hanging, try setting this to something on a local disk, | |
|
79 | e.g:: | |
|
80 | ||
|
81 | ipython --HistoryManager.hist_file=/tmp/ipython_hist.sqlite | |
|
82 | ||
|
83 | """) | |
|
84 | ||
|
70 | 85 | |
|
71 | 86 | # The SQLite database |
|
72 | 87 | if sqlite3: |
@@ -74,7 +89,7 b' class HistoryAccessor(Configurable):' | |||
|
74 | 89 | else: |
|
75 | 90 | db = Instance(DummyDB) |
|
76 | 91 | |
|
77 |
def __init__(self, profile='default', hist_file=u'', |
|
|
92 | def __init__(self, profile='default', hist_file=u'', config=None, **traits): | |
|
78 | 93 | """Create a new history accessor. |
|
79 | 94 | |
|
80 | 95 | Parameters |
@@ -84,15 +99,17 b' class HistoryAccessor(Configurable):' | |||
|
84 | 99 | hist_file : str |
|
85 | 100 | Path to an SQLite history database stored by IPython. If specified, |
|
86 | 101 | hist_file overrides profile. |
|
87 | shell : | |
|
88 | InteractiveShell object, for use by HistoryManager subclass | |
|
89 | 102 | config : |
|
90 | 103 | Config object. hist_file can also be set through this. |
|
91 | 104 | """ |
|
92 | 105 | # We need a pointer back to the shell for various tasks. |
|
93 |
super(HistoryAccessor, self).__init__( |
|
|
94 | hist_file=hist_file, **traits) | |
|
95 | ||
|
106 | super(HistoryAccessor, self).__init__(config=config, **traits) | |
|
107 | # defer setting hist_file from kwarg until after init, | |
|
108 | # otherwise the default kwarg value would clobber any value | |
|
109 | # set by config | |
|
110 | if hist_file: | |
|
111 | self.hist_file = hist_file | |
|
112 | ||
|
96 | 113 | if self.hist_file == u'': |
|
97 | 114 | # No one has set the hist_file, yet. |
|
98 | 115 | self.hist_file = self._get_hist_file_name(profile) |
@@ -106,8 +123,9 b' class HistoryAccessor(Configurable):' | |||
|
106 | 123 | self.init_db() |
|
107 | 124 | except sqlite3.DatabaseError: |
|
108 | 125 | if os.path.isfile(self.hist_file): |
|
109 |
# Try to move the file out of the way |
|
|
110 | newpath = os.path.join(self.shell.profile_dir.location, "hist-corrupt.sqlite") | |
|
126 | # Try to move the file out of the way | |
|
127 | base,ext = os.path.splitext(self.hist_file) | |
|
128 | newpath = base + '-corrupt' + ext | |
|
111 | 129 | os.rename(self.hist_file, newpath) |
|
112 | 130 | print("ERROR! History file wasn't a valid SQLite database.", |
|
113 | 131 | "It was moved to %s" % newpath, "and a new file created.") |
@@ -8,12 +8,15 b'' | |||
|
8 | 8 | # stdlib |
|
9 | 9 | import os |
|
10 | 10 | import sys |
|
11 | import tempfile | |
|
11 | 12 | import unittest |
|
12 | 13 | from datetime import datetime |
|
14 | ||
|
13 | 15 | # third party |
|
14 | 16 | import nose.tools as nt |
|
15 | 17 | |
|
16 | 18 | # our own packages |
|
19 | from IPython.config.loader import Config | |
|
17 | 20 | from IPython.utils.tempdir import TemporaryDirectory |
|
18 | 21 | from IPython.core.history import HistoryManager, extract_hist_ranges |
|
19 | 22 | from IPython.utils import py3compat |
@@ -122,3 +125,10 b' def test_timestamp_type():' | |||
|
122 | 125 | ip = get_ipython() |
|
123 | 126 | info = ip.history_manager.get_session_info() |
|
124 | 127 | nt.assert_true(isinstance(info[1], datetime)) |
|
128 | ||
|
129 | def test_hist_file_config(): | |
|
130 | cfg = Config() | |
|
131 | cfg.HistoryManager.hist_file = tempfile.mktemp() | |
|
132 | hm = HistoryManager(shell=get_ipython(), config=cfg) | |
|
133 | nt.assert_equals(hm.hist_file, cfg.HistoryManager.hist_file) | |
|
134 |
General Comments 0
You need to be logged in to leave comments.
Login now