Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure xklb-metadata.db has live_status and error columns #265

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .cli import CliParameter
from .constants import CONFIG_DIR
from .reverseproxy import ReverseProxied
from .subproc_wrapper import process_open
from .server import WebServer
from .dep_check import dependency_check
from .updater import Updater
Expand Down Expand Up @@ -152,6 +153,12 @@ def create_app():
db.CalibreDB.setup_db(config.config_calibre_dir, cli_param.settings_path)
calibre_db.init_db()

XKLB_PATCH = os.getenv('XKLB_PATCH', 'xklb-patch')
p = process_open([XKLB_PATCH], newlines=True)
while p.poll is None:
log.info(p.stdout.readline())
p.wait()

updater_thread.init_updater(config, web_server)
# Perform dry run of updater and exit afterward
if cli_param.dry_run:
Expand Down
46 changes: 46 additions & 0 deletions scripts/xklb-patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# FILE_PATH="$HOME/.local/pipx/venvs/xklb/lib/python3.12/site-packages/xklb/createdb/tube_add.py"
# Debian 12 and Ubuntu 23.10 use: /root/.local/pipx/...
# Debian 13 and Ubuntu 24.04 use: /root/.local/share/pipx/...
# Running 'updatedb' is an ugly hack that might be very slow (optimize later!)
# but at least fixes (a) "share" in path on new OS's (b) Python version in path
# updatedb
# FILE_PATH=$(locate /site-packages/xklb/mediadb/db_media.py | grep /pipx/venvs/xklb/lib/ | grep '/root/.local' | head -1)

# Locate db_media.py and objects.py using find instead of updatedb and locate
# Adjust the base directory to your environment
BASE_DIR="/root/.local/"

# Find db_media.py and objects.py
DB_MEDIA_PY=$(find "$BASE_DIR" -type f -path '*/site-packages/xklb/mediadb/db_media.py' | head -1)
OBJECTS_PY=$(find "$BASE_DIR" -type f -path '*/site-packages/xklb/utils/objects.py' | head -1)

# Patch objects.py to add the keep_keys parameter to dict_filter_bool
if grep -q 'def dict_filter_bool(kwargs, keep_0=True, keep_keys=None)' "$OBJECTS_PY"; then
echo "objects.py already patched. No changes necessary."
else
echo "Patching objects.py to add keep_keys parameter to dict_filter_bool."

sed -i.bak '/def dict_filter_bool(/{
deldesir marked this conversation as resolved.
Show resolved Hide resolved
s/def dict_filter_bool(\(.*\))/def dict_filter_bool(\1, keep_keys=None)/
N;N;
s/if keep_0:.*{/{\
if keep_keys is None:\
keep_keys = set()\
\
if keep_0:\
filtered_dict = {k: v for k, v in kwargs.items() if (v is not None and v != "" and v is not False) or k in keep_keys}/
}' "$OBJECTS_PY"
fi

# Patch db_media.py to specify keep_keys=['error'] in the call to dict_filter_bool
if grep -q "entry = objects.dict_filter_bool(entry, keep_keys=['error'])" "$DB_MEDIA_PY"; then
echo "db_media.py already patched. No changes necessary."
else
echo "Patching db_media.py to specify keep_keys=['error'] when calling dict_filter_bool."

sed -i.bak "s/entry = objects\.dict_filter_bool(entry)/entry = objects.dict_filter_bool(entry, keep_keys=['error'])/" "$DB_MEDIA_PY"
fi

echo "Patching completed."