Skip to content

Commit 2756bde

Browse files
Added first iteration of split library support for CWA
1 parent 1b02673 commit 2756bde

File tree

9 files changed

+99
-192
lines changed

9 files changed

+99
-192
lines changed

.github/workflows/dockerhub-build-push-on-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
BUILD_DATE=${{ github.event.repository.updated_at }}
5858
VERSION=${{ vars.CURRENT_DEV_VERSION }}-DEV_BUILD-${{ env.IMAGE_TAG }}-${{ vars.CURRENT_DEV_BUILD_NUM }}
5959
tags: |
60-
${{ secrets.DOCKERHUB_USERNAME }}/calibre-web-automated:dev-${{ env.IMAGE_TAG }}
60+
${{ secrets.DOCKERHUB_USERNAME }}/calibre-web-automated:dev
6161
6262
platforms: linux/amd64,linux/arm64
6363

Dockerfile_calibre_not_included

Lines changed: 0 additions & 173 deletions
This file was deleted.

root/app/calibre-web/cps/cwa_functions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,8 @@ def convert_library_start(queue):
478478
queue.put(cl_process)
479479

480480
def get_tmp_conversion_dir() -> str:
481-
dirs_json_path = "/app/calibre-web-automated/dirs.json"
482481
dirs = {}
483-
with open(dirs_json_path, 'r') as f:
482+
with open(DIRS_JSON, 'r') as f:
484483
dirs: dict[str, str] = json.load(f)
485484
tmp_conversion_dir = f"{dirs['tmp_conversion_dir']}/"
486485

root/app/calibre-web/cps/templates/config_db.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h2>{{title}}</h2>
1818
</div>
1919
<div class="form-group required">
2020
<input type="checkbox" id="config_calibre_split" name="config_calibre_split" data-control="split_settings" data-t ="{{ config.config_calibre_split_dir }}" {% if config.config_calibre_split %}checked{% endif %} >
21-
<label for="config_calibre_split">{{_('Separate Book Files from Library - DO NOT USE! COMING IN CWA V3.1.0!')}}</label>
21+
<label for="config_calibre_split">{{_('Separate Book Files from Library - metadata.db file should remain in /calibre-library, however your library files can be wherever you desire')}}</label>
2222
</div>
2323
<div data-related="split_settings">
2424
<div class="form-group required input-group">

root/app/calibre-web/cps/web.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,20 @@ def get_sort_function(sort_param, data):
382382

383383

384384
def cwa_get_library_location() -> str:
385-
dirs = {}
386-
with open('/app/calibre-web-automated/dirs.json', 'r') as f:
387-
dirs: dict[str, str] = json.load(f)
388-
library_dir = f"{dirs['calibre_library_dir']}/"
389-
return library_dir
385+
con = sqlite3.connect("/config/app.db")
386+
cur = con.cursor()
387+
split_library = cur.execute('SELECT config_calibre_split FROM settings;').fetchone()[0]
388+
389+
if split_library:
390+
split_path = cur.execute('SELECT config_calibre_split_dir FROM settings;').fetchone()[0]
391+
con.close()
392+
return split_path
393+
else:
394+
dirs = {}
395+
with open('/app/calibre-web-automated/dirs.json', 'r') as f:
396+
dirs: dict[str, str] = json.load(f)
397+
library_dir = f"{dirs['calibre_library_dir']}/"
398+
return library_dir
390399

391400
def cwa_get_num_books_in_library() -> int:
392401
try:

scripts/convert_library.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tempfile
1111
import atexit
1212
from datetime import datetime
13+
import sqlite3
1314

1415
import pwd
1516
import grp
@@ -95,6 +96,26 @@ def __init__(self, args) -> None:
9596
self.ingest_folder, self.library_dir, self.tmp_conversion_dir = self.get_dirs('/app/calibre-web-automated/dirs.json')
9697
self.to_convert = self.get_books_to_convert()
9798

99+
# Gets split library info from app.db and sets library dir to the split dir if split library is enabled
100+
self.split_library = self.get_split_library()
101+
if self.split_library:
102+
self.library_dir = self.split_library
103+
104+
105+
def get_split_library() -> bool | None:
106+
"""Checks whether or not the user has split library enabled. Returns None if they don't and the path of the Split Library location if True."""
107+
con = sqlite3.connect("/config/app.db")
108+
cur = con.cursor()
109+
split_library = cur.execute('SELECT config_calibre_split FROM settings;').fetchone()[0]
110+
111+
if split_library:
112+
split_path = cur.execute('SELECT config_calibre_split_dir FROM settings;').fetchone()[0]
113+
con.close()
114+
return split_path
115+
else:
116+
con.close()
117+
return None
118+
98119

99120
def get_dirs(self, dirs_json_path: str) -> tuple[str, str, str]:
100121
dirs = {}

scripts/cover_enforcer.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import sys
66
import time
7+
import sqlite3
78
from datetime import datetime
89
from pathlib import Path
910

@@ -56,9 +57,18 @@ def __init__(self, book_dir: str, file_path: str):
5657

5758
def get_calibre_library(self) -> str:
5859
"""Gets Calibre-Library location from dirs_json path"""
59-
with open(dirs_json, 'r') as f:
60-
dirs = json.load(f)
61-
return dirs['calibre_library_dir'] # Returns without / on the end
60+
con = sqlite3.connect("/config/app.db")
61+
cur = con.cursor()
62+
split_library = cur.execute('SELECT config_calibre_split FROM settings;').fetchone()[0]
63+
64+
if split_library:
65+
split_path = cur.execute('SELECT config_calibre_split_dir FROM settings;').fetchone()[0]
66+
con.close()
67+
return split_path
68+
else:
69+
with open(dirs_json, 'r') as f:
70+
dirs = json.load(f)
71+
return dirs['calibre_library_dir'] # Returns without / on the end
6272

6373

6474
def get_time(self) -> str:
@@ -110,9 +120,18 @@ def __init__(self, args):
110120

111121
def get_calibre_library(self) -> str:
112122
"""Gets Calibre-Library location from dirs_json path"""
113-
with open(dirs_json, 'r') as f:
114-
dirs = json.load(f)
115-
return dirs['calibre_library_dir'] # Returns without / on the end
123+
con = sqlite3.connect("/config/app.db")
124+
cur = con.cursor()
125+
split_library = cur.execute('SELECT config_calibre_split FROM settings;').fetchone()[0]
126+
127+
if split_library:
128+
split_path = cur.execute('SELECT config_calibre_split_dir FROM settings;').fetchone()[0]
129+
con.close()
130+
return split_path
131+
else:
132+
with open(dirs_json, 'r') as f:
133+
dirs = json.load(f)
134+
return dirs['calibre_library_dir'] # Returns without / on the end
116135

117136
def read_log(self, auto=True, log_path: str = "None") -> dict:
118137
"""Reads pertinent information from the given log file, adds the book_id from the log name and returns the info as a dict"""

scripts/ingest_processor.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tempfile
77
import time
88
import shutil
9+
import sqlite3
910
from pathlib import Path
1011

1112
from cwa_db import CWA_DB
@@ -69,6 +70,26 @@ def __init__(self, filepath: str):
6970
self.is_target_format = bool(self.filepath.endswith(self.target_format))
7071
self.can_convert, self.input_format = self.can_convert_check()
7172

73+
# Gets split library info from app.db and sets library dir to the split dir if split library is enabled
74+
self.split_library = self.get_split_library()
75+
if self.split_library:
76+
self.library_dir = self.split_library
77+
78+
79+
def get_split_library() -> bool | None:
80+
"""Checks whether or not the user has split library enabled. Returns None if they don't and the path of the Split Library location if True."""
81+
con = sqlite3.connect("/config/app.db")
82+
cur = con.cursor()
83+
split_library = cur.execute('SELECT config_calibre_split FROM settings;').fetchone()[0]
84+
85+
if split_library:
86+
split_path = cur.execute('SELECT config_calibre_split_dir FROM settings;').fetchone()[0]
87+
con.close()
88+
return split_path
89+
else:
90+
con.close()
91+
return None
92+
7293

7394
def get_dirs(self, dirs_json_path: str) -> tuple[str, str, str]:
7495
dirs = {}

scripts/kindle_epub_fixer.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
from pathlib import Path
77
import sys
8+
import sqlite3
89

910
import logging
1011
import tempfile
@@ -325,10 +326,20 @@ def process(self, input_path, output_path=None, default_language='en'):
325326

326327

327328
def get_library_location() -> str:
328-
"""Gets Calibre-Library location from dirs_json path"""
329-
with open(dirs_json, 'r') as f:
330-
dirs = json.load(f)
331-
return dirs['calibre_library_dir'] # Returns without / on the end
329+
con = sqlite3.connect("/config/app.db")
330+
cur = con.cursor()
331+
split_library = cur.execute('SELECT config_calibre_split FROM settings;').fetchone()[0]
332+
333+
if split_library:
334+
split_path = cur.execute('SELECT config_calibre_split_dir FROM settings;').fetchone()[0]
335+
con.close()
336+
return split_path
337+
else:
338+
dirs = {}
339+
with open('/app/calibre-web-automated/dirs.json', 'r') as f:
340+
dirs: dict[str, str] = json.load(f)
341+
library_dir = f"{dirs['calibre_library_dir']}/"
342+
return library_dir
332343

333344
def get_all_epubs_in_library() -> list[str]:
334345
""" Returns a list if the book dir given contains files of one or more of the supported formats"""

0 commit comments

Comments
 (0)