Created
July 15, 2013 20:53
-
-
Save minrk/6003365 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Migrate old IPython history (readline) to new IPython history (sqlite) | |
Author: Min RK (benjaminrk@gmail.com) | |
License: Public Domain | |
""" | |
import os | |
from IPython.core.interactiveshell import InteractiveShell | |
from IPython.core.history import HistoryManager | |
from IPython.utils.path import locate_profile, get_ipython_dir | |
def migrate_history(old_histfile, new_histfile): | |
"""populate an IPython sqlite history from an old readline history file""" | |
# shell = InteractiveShell.instance() | |
history = HistoryManager(hist_file=new_histfile, | |
# this line shouldn't be necessary, but it is in 0.13 | |
shell = InteractiveShell.instance() | |
) | |
with open(old_histfile) as f: | |
# iterate through readline history, | |
# and write to the new history database | |
for linenum, line in enumerate(f): | |
history.store_inputs(linenum, line) | |
if __name__ == '__main__': | |
# the default location of old history file | |
old = os.path.join(get_ipython_dir(), "history") | |
# the default location of the new history file | |
new = os.path.join(locate_profile(), "history.sqlite") | |
migrate_history(old, new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment