diff --git a/cps/editbooks.py b/cps/editbooks.py index 2c375c72..0a6410b1 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -162,7 +162,7 @@ def upload(): return make_response(jsonify(resp)) else: resp = {"location": url_for('web.show_book', book_id=book_id)} - return make_response(jsonify(resp)) + return Response(json.dumps(resp), mimetype='application/json') except (OperationalError, IntegrityError, StaleDataError) as e: calibre_db.session.rollback() log.error_or_exception("Database error: {}".format(e)) @@ -398,6 +398,7 @@ def get_sorted_entry(field, bookid): return make_response(jsonify(authors=" & ".join([a.name for a in calibre_db.order_authors([book])]))) return "" + @editbook.route("/ajax/simulatemerge", methods=['POST']) @user_login_required @edit_required @@ -462,6 +463,7 @@ def read_selected_books(): return json.dumps({'success': True}) return "" + @editbook.route("/ajax/mergebooks", methods=['POST']) @user_login_required @edit_required @@ -772,8 +774,9 @@ def prepare_authors(authr, calibre_path, gdrive=False): all_new_name = helper.get_valid_filename(one_book.title, chars=42) + ' - ' \ + helper.get_valid_filename(renamed_author.name, chars=42) # change location in database to new author/title path - helper.rename_all_files_on_change(one_book, new_path, new_path, all_new_name, gdrive) - + error = helper.rename_all_files_on_change(one_book, new_path, new_path, all_new_name, gdrive) + if error: + flash(error) return input_authors diff --git a/cps/helper.py b/cps/helper.py index fb8b3547..6d584454 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -394,10 +394,16 @@ def delete_book_file(book, calibrepath, book_format=None): def rename_all_files_on_change(one_book, new_path, old_path, all_new_name, gdrive=False): for file_format in one_book.data: if not gdrive: - if not os.path.exists(new_path): - os.makedirs(new_path) - shutil.move(os.path.join(old_path, file_format.name + '.' + file_format.format.lower()), - os.path.join(new_path, all_new_name + '.' + file_format.format.lower())) + try: + if not os.path.exists(new_path): + os.makedirs(new_path) + shutil.move(os.path.join(old_path, file_format.name + '.' + file_format.format.lower()), + os.path.join(new_path, all_new_name + '.' + file_format.format.lower())) + except PermissionError as ex: + log.error("Moving book-id %s folder %s failed: %s", one_book.id, new_path, ex) + return _("Moving book path of Book %(book_id)s to: '%(src)s' failed with error: %(error)s", + book_id=one_book.id, src=new_path, error=str(ex)) + else: g_file = gd.getFileFromEbooksFolder(old_path, file_format.name + '.' + file_format.format.lower()) @@ -410,6 +416,7 @@ def rename_all_files_on_change(one_book, new_path, old_path, all_new_name, gdriv # change name in Database file_format.name = all_new_name + return False def rename_author_path(first_author, old_author_dir, renamed_author, calibre_path="", gdrive=False): @@ -468,7 +475,7 @@ def update_dir_structure_file(book_id, calibre_path, original_filepath, new_auth all_new_name = get_valid_filename(local_book.title, chars=42) + ' - ' \ + get_valid_filename(new_author, chars=42) # Book folder already moved, only files need to be renamed - rename_all_files_on_change(local_book, new_path, new_path, all_new_name) + error |= rename_all_files_on_change(local_book, new_path, new_path, all_new_name) if error: return error @@ -511,11 +518,11 @@ def update_dir_structure_gdrive(book_id, first_author): book.path = new_authordir + '/' + book.path.split('/')[1] gd.updateDatabaseOnEdit(g_file['id'], book.path) else: - return _('File %(file)s not found on Google Drive', file=authordir) # file not found''' + return _('File %(file)s not found on Google Drive', file=authordir) # file not found if titledir != new_titledir or authordir != new_authordir : all_new_name = get_valid_filename(book.title, chars=42) + ' - ' \ + get_valid_filename(new_authordir, chars=42) - rename_all_files_on_change(book, book.path, book.path, all_new_name, gdrive=True) # todo: Move filenames on gdrive + return rename_all_files_on_change(book, book.path, book.path, all_new_name, gdrive=True) # todo: Move filenames on gdrive return False @@ -558,26 +565,6 @@ def move_files_on_change(calibre_path, new_author_dir, new_titledir, localbook, return False -def rename_files_on_change(first_author, - renamed_author, - local_book, - original_filepath="", - path="", - calibre_path="", - gdrive=False): - # Rename all files from old names to new names - #try: - #clean_author_database(renamed_author, calibre_path, gdrive=gdrive) - #if first_author and first_author not in renamed_author: - # clean_author_database([first_author], calibre_path, local_book, gdrive) - #if not gdrive and not renamed_author and not original_filepath and len(os.listdir(os.path.dirname(path))) == 0: - # shutil.rmtree(os.path.dirname(path)) - #except (OSError, FileNotFoundError) as ex: - # log.error_or_exception("Error in rename file in path {}".format(ex)) - # return _("Error in rename file in path: {}".format(str(ex))) - return False - - def delete_book_gdrive(book, book_format): error = None if book_format: @@ -972,8 +959,9 @@ def do_download_file(book, book_format, client, data, headers): # ToDo Check headers parameter for element in headers: response.headers[element[0]] = element[1] - log.info('Downloading file: \'%s\' by %s - %s', format(os.path.join(filename, book_name + "." + book_format)), + log.info('Downloading file: \'%s\' by %s', format(os.path.join(filename, book_name + "." + book_format)), current_user.name, request.headers.get('X-Forwarded-For', request.remote_addr)) + log.info('Downloading file: {}'.format(os.path.join(filename, book_name + "." + book_format))) return response diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 1dce233b..dad550db 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
Start Time: 2024-12-13 18:37:11
+Start Time: 2024-12-15 07:24:54
Stop Time: 2024-12-14 01:56:41
+Stop Time: 2024-12-15 14:36:53
Duration: 6h 13 min
+Duration: 6h 5 min
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 500, in test_backup_change_custom_text + self.assertEqual(custom["#value#"], "人物 *'(}\"") +AssertionError: None != '人物 *\'(}"'+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 502, in test_booklist_xss + self.assertEqual("", response.json()['newValue']) +KeyError: 'newValue'+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 202, in test_bookslist_edit_categories + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 482, in test_bookslist_edit_comment + self.assertEqual("+", bl['table'][4]["Comments"]['text']) +AssertionError: '+' != '[...]\nEnter comments\n Normal text \nBol[45 chars]uest' +- + ++ [...] +Enter comments + Normal text +Bold +Italic +Underline +Value is missing on request+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 394, in test_bookslist_edit_cust_category + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 467, in test_bookslist_edit_cust_comment + self.assertEqual("+", bl['table'][4]["Custom Comment 人物"]['text']) +AssertionError: '+' != '[...]\nEnter Custom Comment 人物\n Normal t[54 chars]uest' +- + ++ [...] +Enter Custom Comment 人物 + Normal text +Bold +Italic +Underline +Value is missing on request+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 408, in test_bookslist_edit_cust_enum + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 363, in test_bookslist_edit_cust_float + self.assertEqual("3.55", values['cust_columns'][0]['value']) +AssertionError: '3.55' != 'Test1234' +- 3.55 ++ Test1234+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 351, in test_bookslist_edit_cust_int + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 423, in test_bookslist_edit_cust_ratings + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 435, in test_bookslist_edit_cust_text + self.assertEqual("执 Huks", values['cust_columns'][0]['value']) +AssertionError: '执 Huks' != '3.5' +- 执 Huks ++ 3.5+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 276, in test_bookslist_edit_languages + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 245, in test_bookslist_edit_publisher + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 224, in test_bookslist_edit_series + bl = self.get_books_list(-1) + File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1928, in get_books_list + element_text = "+" if "glyphicon-plus" in click_element.find_elements(By.XPATH, "./span")[0].get_attribute('class') else "" +IndexError: list index out of range+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 86, in test_search_books_list + bl = self.check_search(bl, "genot", 4, "Categories", "Gênot") + File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_list.py", line 51, in check_search + self.assertEqual(count, len(bl['table'])) +AssertionError: 4 != 5+
ImportError: Failed to import test module: test_mass_edit_books_list +Traceback (most recent call last): + File "/usr/lib/python3.10/unittest/loader.py", line 436, in _find_test_path + module = self._get_module_from_name(name) + File "/usr/lib/python3.10/unittest/loader.py", line 377, in _get_module_from_name + __import__(name) + File "/home/ozzie/Development/calibre-web-test/test/test_mass_edit_books_list.py", line 172 + Title, autor write protect single edit + ^^^^^ +SyntaxError: invalid syntax+
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_reader.py", line 98, in test_kepub_reader + if but.accessible_name == "kepub": + File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 311, in accessible_name + return self._execute(Command.GET_ELEMENT_ARIA_LABEL)["value"] + File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 403, in _execute + return self._parent.execute(command, params) + File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute + self.error_handler.check_response(response) + File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 209, in check_response + raise exception_class(value) +selenium.common.exceptions.WebDriverException: Message: HTTP method not allowed+