Update book path when it's been moved

This commit is contained in:
BasioMeusPuga
2018-01-09 18:15:47 +05:30
parent 01d1be9ddc
commit 9a4ce12465
3 changed files with 13 additions and 10 deletions

View File

@@ -97,7 +97,7 @@ class DatabaseFunctions:
tags = ', '.join([j for j in tags if j]) tags = ', '.join([j for j in tags if j])
sql_command_add = ( sql_command_add = (
"INSERT INTO \ "INSERT OR REPLACE INTO \
books (Title, Author, Year, Path, ISBN, Tags, Hash, CoverImage) \ books (Title, Author, Year, Path, ISBN, Tags, Hash, CoverImage) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?)") VALUES (?, ?, ?, ?, ?, ?, ?, ?)")

View File

@@ -79,7 +79,7 @@ class BookSorter:
# Caching upon closing # Caching upon closing
self.file_list = [i for i in file_list if os.path.exists(i)] self.file_list = [i for i in file_list if os.path.exists(i)]
self.statistics = [0, (len(file_list))] self.statistics = [0, (len(file_list))]
self.hashes = [] self.hashes_and_paths = {}
self.mode = mode self.mode = mode
self.database_path = database_path self.database_path = database_path
self.auto_tags = auto_tags self.auto_tags = auto_tags
@@ -99,15 +99,17 @@ class BookSorter:
# Overwrite book if deleted and then re-added # Overwrite book if deleted and then re-added
# Also fetch the path of the file here # Also fetch the path of the file here
all_hashes = database.DatabaseFunctions( all_hashes_and_paths = database.DatabaseFunctions(
self.database_path).fetch_data( self.database_path).fetch_data(
('Hash',), ('Hash', 'Path'),
'books', 'books',
{'Hash': ''}, {'Hash': ''},
'LIKE') 'LIKE')
if all_hashes: if all_hashes_and_paths:
self.hashes = [i[0] for i in all_hashes] # self.hashes = [i[0] for i in all_hashes]
self.hashes_and_paths = {
i[0]: i[1] for i in all_hashes_and_paths}
def database_position(self, file_hash): def database_position(self, file_hash):
position = database.DatabaseFunctions( position = database.DatabaseFunctions(
@@ -139,9 +141,11 @@ class BookSorter:
# This should not get triggered in reading mode # This should not get triggered in reading mode
# IF the file is NOT being loaded into the reader, # IF the file is NOT being loaded into the reader,
# Do not allow addition in case the file # Do not allow addition in case the file
# is already in the database # is already in the database and it remains at its original path
if self.mode == 'addition' and file_md5 in self.hashes: if self.mode == 'addition' and file_md5 in self.hashes_and_paths:
if self.hashes_and_paths[file_md5] == filename:
return return
file_extension = os.path.splitext(filename)[1][1:] file_extension = os.path.splitext(filename)[1][1:]

View File

@@ -92,7 +92,6 @@ class BackGroundBookSearch(QtCore.QThread):
pathlib.Path(i[0]) for i in data_list if i[3] == QtCore.Qt.Unchecked] pathlib.Path(i[0]) for i in data_list if i[3] == QtCore.Qt.Unchecked]
def run(self): def run(self):
def is_wanted(directory): def is_wanted(directory):
directory_parents = pathlib.Path(directory).parents directory_parents = pathlib.Path(directory).parents
for i in self.unwanted_directories: for i in self.unwanted_directories: