Automatically move database from legacy location if it exists
This commit is contained in:
parent
20b3b52629
commit
fbf5006978
28
buku
28
buku
@ -27,6 +27,7 @@ import html.parser as HTMLParser
|
|||||||
from http.client import HTTPConnection, HTTPSConnection
|
from http.client import HTTPConnection, HTTPSConnection
|
||||||
from urllib.parse import urljoin, unquote
|
from urllib.parse import urljoin, unquote
|
||||||
import signal
|
import signal
|
||||||
|
import shutil
|
||||||
|
|
||||||
# Import libraries needed for encryption
|
# Import libraries needed for encryption
|
||||||
try:
|
try:
|
||||||
@ -114,6 +115,30 @@ def getDataPath():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def moveOldDatabase():
|
||||||
|
olddbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku')
|
||||||
|
olddbfile = os.path.join(olddbpath, 'bookmarks.db')
|
||||||
|
|
||||||
|
if not os.path.exists(olddbfile):
|
||||||
|
return
|
||||||
|
|
||||||
|
newdbpath = getDataPath()
|
||||||
|
newdbfile = os.path.join(newdbpath, 'bookmarks.db')
|
||||||
|
|
||||||
|
if os.path.exists(newdbfile):
|
||||||
|
print("Both old (%s) and new (%s) databases exist, need manual action" % (olddbfile, newdbfile))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not os.path.exists(newdbpath):
|
||||||
|
os.makedirs(newdbpath)
|
||||||
|
|
||||||
|
shutil.move(olddbfile, newdbfile)
|
||||||
|
print("Database was moved from old (%s) to new (%s) location" % (olddbfile, newdbfile))
|
||||||
|
|
||||||
|
os.rmdir(olddbpath)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def initdb():
|
def initdb():
|
||||||
"""Initialize the database connection. Create DB file and/or bookmarks table
|
"""Initialize the database connection. Create DB file and/or bookmarks table
|
||||||
if they don't exist. Alert on encryption options on first execution.
|
if they don't exist. Alert on encryption options on first execution.
|
||||||
@ -1017,6 +1042,9 @@ if online == True and titleManual != None:
|
|||||||
print("You can either fetch title from web or add/update title manually.\n")
|
print("You can either fetch title from web or add/update title manually.\n")
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
|
# Move database to new location, if needed
|
||||||
|
moveOldDatabase()
|
||||||
|
|
||||||
# Handle encrypt/decrypt options at top priority
|
# Handle encrypt/decrypt options at top priority
|
||||||
if encrypt == True:
|
if encrypt == True:
|
||||||
encrypt_file()
|
encrypt_file()
|
||||||
|
Loading…
Reference in New Issue
Block a user