1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-28 12:30:00 +00:00

Start renaming author names on gdrive

This commit is contained in:
Ozzie Isaacs 2021-12-05 19:01:23 +01:00
parent f78d2245aa
commit 6e15280fac
3 changed files with 32 additions and 9 deletions

View File

@ -864,10 +864,9 @@ class CalibreDB():
limit_all = result_count limit_all = result_count
ub.store_combo_ids(result) ub.store_combo_ids(result)
# ToDo: doesn't work as more than one table returned entries = self.order_authors(result[offset:limit_all], list_return=True, combined=True)
# entries = self.order_authors(result[offset:limit_all], True)
return result[offset:limit_all], result_count, pagination return entries, result_count, pagination
# Creates for all stored languages a translated speaking name in the array for the UI # Creates for all stored languages a translated speaking name in the array for the UI
def speaking_language(self, languages=None, return_all_languages=False, with_count=False, reverse_order=False): def speaking_language(self, languages=None, return_all_languages=False, with_count=False, reverse_order=False):

View File

@ -452,7 +452,7 @@ def update_dir_structure_file(book_id, calibrepath, first_author, orignal_filepa
return _("Error in rename file in path: %(error)s", error=str(ex)) return _("Error in rename file in path: %(error)s", error=str(ex))
return False return False
def update_dir_structure_gdrive(book_id, first_author): def update_dir_structure_gdrive(book_id, first_author, renamed_author):
error = False error = False
book = calibre_db.get_book(book_id) book = calibre_db.get_book(book_id)
path = book.path path = book.path
@ -460,8 +460,24 @@ def update_dir_structure_gdrive(book_id, first_author):
authordir = book.path.split('/')[0] authordir = book.path.split('/')[0]
if first_author: if first_author:
new_authordir = get_valid_filename(first_author) new_authordir = get_valid_filename(first_author)
for r in renamed_author:
# Todo: Rename all authors on gdrive
new_author = calibre_db.session.query(db.Authors).filter(db.Authors.name == r).first()
old_author_dir = get_valid_filename(r)
new_author_rename_dir = get_valid_filename(new_author.name)
'''if os.path.isdir(os.path.join(calibrepath, old_author_dir)):
try:
old_author_path = os.path.join(calibrepath, old_author_dir)
new_author_path = os.path.join(calibrepath, new_author_rename_dir)
shutil.move(os.path.normcase(old_author_path), os.path.normcase(new_author_path))
except (OSError) as ex:
log.error("Rename author from: %s to %s: %s", old_author_path, new_author_path, ex)
log.debug(ex, exc_info=True)
return _("Rename author from: '%(src)s' to '%(dest)s' failed with error: %(error)s",
src=old_author_path, dest=new_author_path, error=str(ex))'''
else: else:
new_authordir = get_valid_filename(book.authors[0].name) new_authordir = get_valid_filename(book.authors[0].name)
titledir = book.path.split('/')[1] titledir = book.path.split('/')[1]
new_titledir = get_valid_filename(book.title) + u" (" + str(book_id) + u")" new_titledir = get_valid_filename(book.title) + u" (" + str(book_id) + u")"
@ -485,8 +501,19 @@ def update_dir_structure_gdrive(book_id, first_author):
gd.updateDatabaseOnEdit(gFile['id'], book.path) gd.updateDatabaseOnEdit(gFile['id'], book.path)
else: else:
error = _(u'File %(file)s not found on Google Drive', file=authordir) # file not found error = _(u'File %(file)s not found on Google Drive', file=authordir) # file not found
# Todo: Rename all authors on gdrive
# Rename all files from old names to new names # Rename all files from old names to new names
'''
try:
clean_author_database(renamed_author, calibrepath)
if first_author not in renamed_author:
clean_author_database([first_author], calibrepath, localbook)
if not renamed_author and not orignal_filepath and len(os.listdir(os.path.dirname(path))) == 0:
shutil.rmtree(os.path.dirname(path))
except (OSError, FileNotFoundError) as ex:
log.error("Error in rename file in path %s", ex)
log.debug(ex, exc_info=True)
return _("Error in rename file in path: %(error)s", error=str(ex))'''
if authordir != new_authordir or titledir != new_titledir: if authordir != new_authordir or titledir != new_titledir:
new_name = get_valid_filename(book.title) + u' - ' + get_valid_filename(new_authordir) new_name = get_valid_filename(book.title) + u' - ' + get_valid_filename(new_authordir)
for file_format in book.data: for file_format in book.data:
@ -584,8 +611,7 @@ def update_dir_structure(book_id,
db_filename=None, db_filename=None,
renamed_author=False): renamed_author=False):
if config.config_use_google_drive: if config.config_use_google_drive:
# ToDo: rename author on gdrive return update_dir_structure_gdrive(book_id, first_author, renamed_author)
return update_dir_structure_gdrive(book_id, first_author)
else: else:
return update_dir_structure_file(book_id, return update_dir_structure_file(book_id,
calibrepath, calibrepath,

View File

@ -894,8 +894,6 @@ def list_books():
@web.route("/ajax/table_settings", methods=['POST']) @web.route("/ajax/table_settings", methods=['POST'])
@login_required @login_required
def update_table_settings(): def update_table_settings():
# vals = request.get_json()
# ToDo: Save table settings
current_user.view_settings['table'] = json.loads(request.data) current_user.view_settings['table'] = json.loads(request.data)
try: try:
try: try: