Reformatting code.

This commit is contained in:
Roland 2025-12-06 14:49:46 -07:00 • committed by lrnselfreliance
parent 5b29144d70
commit 8a7f0737f0
42 changed files with 306 additions and 238 deletions

View file

@ -26,9 +26,9 @@ from wrolpi.common import get_media_directory, get_relative_to_media_directory,
from wrolpi.dates import now, Seconds
from wrolpi.db import get_db_session, get_db_curs, optional_session
from wrolpi.errors import UnknownArchive, InvalidOrderBy, InvalidDatetime
from wrolpi.events import Events
from wrolpi.files.lib import handle_file_group_search_results
from wrolpi.files.models import FileGroup
from wrolpi.events import Events
from wrolpi.switches import register_switch_handler, ActivateSwitchMethod
from wrolpi.tags import tag_append_sub_select_where
from wrolpi.vars import PYTEST, DOCKERIZED

View file

@ -84,7 +84,8 @@ async def test_model_archive_sets_collection_id(async_client, test_session, test
@pytest.mark.asyncio
async def test_model_archive_extracts_url_from_singlefile(async_client, test_session, test_directory, make_files_structure):
async def test_model_archive_extracts_url_from_singlefile(async_client, test_session, test_directory,
make_files_structure):
"""
Test that model_archive() can extract URL from singlefile when file_group.url is None.

View file

@ -593,7 +593,8 @@ async def test_archive_meta(async_client, test_session, make_files_structure):
@pytest.mark.asyncio
async def test_refresh_archives_deleted_singlefile(async_client, test_session, make_files_structure, singlefile_contents_factory):
async def test_refresh_archives_deleted_singlefile(async_client, test_session, make_files_structure,
singlefile_contents_factory):
"""Removing a Singlefile file from a FileGroup makes that group no longer an Archive."""
singlefile, readability = make_files_structure({
'2022-09-04-16-20-11_The Title.html': singlefile_contents_factory(),
@ -923,7 +924,8 @@ def test_detect_domain_directory_no_archives(test_directory, test_session):
@pytest.mark.asyncio
async def test_get_or_create_domain_collection_auto_detects_directory(async_client, test_directory, test_session, archive_factory):
async def test_get_or_create_domain_collection_auto_detects_directory(async_client, test_directory, test_session,
archive_factory):
"""get_or_create_domain_collection should auto-detect directory for existing archives."""
from modules.archive.lib import get_or_create_domain_collection
@ -1075,4 +1077,4 @@ def test_link_domain_and_downloads(test_session, test_download_manager):
assert download1.collection_id == collection.id # matched by directory (exact)
assert download2.collection_id == collection.id # matched by subdirectory
assert download3.collection_id == collection.id # matched by URL domain
assert download4.collection_id is None # no frequency = no link
assert download4.collection_id is None # no frequency = no link

View file

@ -59,5 +59,3 @@ class Inventory(Base, ModelHelper):
@staticmethod
def find_by_name(session: Session, name: str) -> 'Inventory':
return session.query(Inventory).filter_by(name=name).one()

View file

@ -111,12 +111,12 @@ def claim_videos_for_channels(channel_ids: List[int]):
with get_db_curs(commit=True) as curs:
# Note: %% is escaped to % in psycopg2 when parameters are used
curs.execute('''
UPDATE video v
SET channel_id = c.id
FROM channel c
INNER JOIN collection col ON col.id = c.collection_id
LEFT JOIN file_group fg ON fg.primary_path LIKE col.directory || '/%%'::VARCHAR
WHERE v.channel_id IS NULL
AND fg.id = v.file_group_id
AND c.id = ANY(%s)
''', (list(channel_ids),))
UPDATE video v
SET channel_id = c.id
FROM channel c
INNER JOIN collection col ON col.id = c.collection_id
LEFT JOIN file_group fg ON fg.primary_path LIKE col.directory || '/%%'::VARCHAR
WHERE v.channel_id IS NULL
AND fg.id = v.file_group_id
AND c.id = ANY (%s)
''', (list(channel_ids),))

View file

@ -12,12 +12,10 @@ from wrolpi.captions import read_captions
from wrolpi.common import Base, ModelHelper, logger, get_media_directory, background_task, replace_file, \
unique_by_predicate
from wrolpi.db import get_db_curs, get_db_session, optional_session
from wrolpi.downloader import Download, download_manager, save_downloads_config
from wrolpi.errors import InvalidDownload
from wrolpi.downloader import Download, save_downloads_config
from wrolpi.events import Events
from wrolpi.files.lib import refresh_files, split_path_stem_and_suffix, move
from wrolpi.files.models import FileGroup
from wrolpi.media_path import MediaPathType
from wrolpi.tags import Tag, TagFile, save_tags_config
from wrolpi.vars import PYTEST, VIDEO_INFO_JSON_KEYS_TO_CLEAN

View file

@ -68,7 +68,7 @@ class TestChannelsConfigUpgrade:
"""Tests for upgrade scenarios where config file exists."""
async def test_upgrade_config_exists_with_data(self, test_session, test_directory, async_client,
test_channels_config, channel_factory):
test_channels_config, channel_factory):
"""
Upgrade with existing config containing channel data.
Should import and sync DB with config.
@ -94,7 +94,7 @@ class TestChannelsConfigUpgrade:
assert channels[0].name == 'Config Channel'
async def test_upgrade_config_exists_empty_list(self, test_session, test_directory, async_client,
test_channels_config, channel_factory):
test_channels_config, channel_factory):
"""
Config exists but has empty channels list.
Should NOT delete existing DB channels (never delete on empty).
@ -123,7 +123,7 @@ class TestChannelsConfigUpgrade:
assert channels[0].name == 'Should Not Delete'
async def test_upgrade_config_missing_db_has_data(self, test_session, test_directory, async_client,
test_channels_config, channel_factory):
test_channels_config, channel_factory):
"""
Config file missing but DB has channels.
Import should succeed (nothing to import), DB data preserved.
@ -157,7 +157,7 @@ class TestChannelsConfigEdgeCases:
"""Tests for edge cases in config import."""
async def test_config_deletes_removed_items(self, test_session, test_directory, async_client, test_channels_config,
channel_factory):
channel_factory):
"""
Config removes a channel that exists in DB.
Should delete the channel from DB.
@ -233,7 +233,7 @@ class TestChannelsConfigEdgeCases:
assert channels[0].url == 'https://example.com/new'
async def test_config_updates_existing_items(self, test_session, test_directory, async_client, test_channels_config,
channel_factory):
channel_factory):
"""
Config updates an existing channel's URL.
Should update the channel in DB.

View file

@ -9,7 +9,7 @@ from modules.zim.errors import UnknownZim, UnknownZimEntry
from modules.zim.models import TagZimEntry, ZimSubscription
from wrolpi import tags, flags
from wrolpi.common import DownloadFileInfo, get_wrolpi_config
from wrolpi.downloader import Download, import_downloads_config, save_downloads_config, get_download_manager_config
from wrolpi.downloader import Download, import_downloads_config, get_download_manager_config
from wrolpi.files import lib as files_lib
from wrolpi.files.models import FileGroup
from wrolpi.test.common import skip_circleci