mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
Remove database migration code support for v17 and older.
The migration code was never working to begin with. Users migrating from v17 or older will be starting from an empty, new database.
This commit is contained in:
parent
e96dc4c9d8
commit
f41d0fb7b3
41
bin/autojump
41
bin/autojump
@ -29,7 +29,7 @@ import shutil
|
||||
import sys
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
VERSION = 'release-v20.9.4'
|
||||
VERSION = 'release-v20.9.5'
|
||||
MAX_KEYWEIGHT = 1000
|
||||
MAX_STORED_PATHS = 1000
|
||||
COMPLETION_SEPARATOR = '__'
|
||||
@ -129,8 +129,6 @@ class Database:
|
||||
trying to recover from backup...', file=sys.stderr)
|
||||
shutil.copy(self.filename + '.bak', self.filename)
|
||||
return self.load(True)
|
||||
else:
|
||||
self.migrate()
|
||||
|
||||
def maintenance(self):
|
||||
"""
|
||||
@ -142,33 +140,6 @@ class Database:
|
||||
self.trim()
|
||||
self.save()
|
||||
|
||||
def migrate(self):
|
||||
"""
|
||||
Migrates database from old format autojump_py, last used in release-v17.
|
||||
"""
|
||||
self.filename = get_db_file('autojump_py')
|
||||
if os.path.exists(self.filename):
|
||||
try: # fix to get optimised pickle in python < 3
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
try:
|
||||
with open(self.filename, 'rb') as f:
|
||||
# encoding is only specified for Python 2 compatibility
|
||||
if sys.version_info[0] > 2:
|
||||
self.data = pickle.load(f, encoding="utf-8")
|
||||
else:
|
||||
self.data = pickle.load(f)
|
||||
unicode_dict = {}
|
||||
for k, v in self.data.items():
|
||||
print(k)
|
||||
unicode_dict[decode(k, errors="replace")] = v
|
||||
return unicode_dict
|
||||
except (IOError, EOFError, pickle.UnpicklingError):
|
||||
pass
|
||||
return {} # if everything fails, return an empty dictionary
|
||||
|
||||
def purge(self):
|
||||
"""
|
||||
Deletes all entries that no longer exist on system.
|
||||
@ -228,16 +199,6 @@ class Database:
|
||||
del self.data[path]
|
||||
|
||||
|
||||
def get_db_file(filename = "autojump.txt"):
|
||||
"""
|
||||
Retrieve full database path.
|
||||
"""
|
||||
# TODO: Remove when migration code is removed.
|
||||
if CONFIG_DIR == os.path.expanduser("~"):
|
||||
return CONFIG_DIR + "/." + filename
|
||||
else:
|
||||
return CONFIG_DIR + "/" + filename
|
||||
|
||||
def options():
|
||||
"""
|
||||
Parse command line options.
|
||||
|
@ -95,34 +95,6 @@ class TestAutojump(unittest.TestCase):
|
||||
os.remove(fname)
|
||||
os.remove(fname + '.bak')
|
||||
|
||||
def test_db_migration(self):
|
||||
ORIG_CONFIG_DIR = autojump.CONFIG_DIR
|
||||
try:
|
||||
# setup
|
||||
CONFIG_DIR = '/tmp/autojump_test_db_load_migrate_' + str(random.randint(0,32678))
|
||||
os.mkdir(CONFIG_DIR)
|
||||
autojump.CONFIG_DIR = CONFIG_DIR
|
||||
fname = CONFIG_DIR + '/autojump_py'
|
||||
db = autojump.Database(fname)
|
||||
db.add('/1')
|
||||
db.add('/2')
|
||||
shutil.copy(fname, fname + '.bak')
|
||||
|
||||
# test
|
||||
missing_fname = '/tmp/autojump_test_db_load_missing_' + str(random.randint(0,32678)) + '.txt'
|
||||
db = autojump.Database(missing_fname)
|
||||
|
||||
db.add('/3')
|
||||
self.assertEquals(len(db.data), 3)
|
||||
|
||||
finally:
|
||||
# teardown
|
||||
shutil.rmtree(CONFIG_DIR)
|
||||
os.remove(missing_fname)
|
||||
os.remove(missing_fname + '.bak')
|
||||
|
||||
autojump.CONFIG_DIR = ORIG_CONFIG_DIR
|
||||
|
||||
def test_db_purge(self):
|
||||
self.db.add('/1')
|
||||
self.db.purge()
|
||||
|
Loading…
Reference in New Issue
Block a user