@@ -27,6 +27,7 @@ import html.parser as HTMLParser
2727from http .client import HTTPConnection , HTTPSConnection
2828from urllib .parse import urljoin , unquote
2929import signal
30+ import shutil
3031
3132# Import libraries needed for encryption
3233try :
@@ -114,6 +115,30 @@ def getDataPath():
114115
115116
116117
118+ def moveOldDatabase ():
119+ olddbpath = os .path .join (os .environ .get ('HOME' ), '.cache' , 'buku' )
120+ olddbfile = os .path .join (olddbpath , 'bookmarks.db' )
121+
122+ if not os .path .exists (olddbfile ):
123+ return
124+
125+ newdbpath = getDataPath ()
126+ newdbfile = os .path .join (newdbpath , 'bookmarks.db' )
127+
128+ if os .path .exists (newdbfile ):
129+ print ("Both old (%s) and new (%s) databases exist, need manual action" % (olddbfile , newdbfile ))
130+ sys .exit (1 )
131+
132+ if not os .path .exists (newdbpath ):
133+ os .makedirs (newdbpath )
134+
135+ shutil .move (olddbfile , newdbfile )
136+ print ("Database was moved from old (%s) to new (%s) location" % (olddbfile , newdbfile ))
137+
138+ os .rmdir (olddbpath )
139+
140+
141+
117142def initdb ():
118143 """Initialize the database connection. Create DB file and/or bookmarks table
119144 if they don't exist. Alert on encryption options on first execution.
@@ -1017,6 +1042,9 @@ if online == True and titleManual != None:
10171042 print ("You can either fetch title from web or add/update title manually.\n " )
10181043 usage ()
10191044
1045+ # Move database to new location, if needed
1046+ moveOldDatabase ()
1047+
10201048# Handle encrypt/decrypt options at top priority
10211049if encrypt == True :
10221050 encrypt_file ()
0 commit comments