mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Fixing local imports.
This commit is contained in:
parent
fb4575dd92
commit
9cb6594ca5
6 changed files with 33 additions and 23 deletions
|
|
@ -81,6 +81,7 @@ async def get_upload_singlefile(request: Request):
|
|||
@register_switch_handler('singlefile_upload_switch_handler')
|
||||
async def singlefile_upload_switch_handler(url=None):
|
||||
"""Used by `post_upload_singlefile` to upload a single file"""
|
||||
# Local imports to avoid circular import: downloader -> archive -> api -> downloader
|
||||
from wrolpi.downloader import Download
|
||||
from . import ArchiveDownloader
|
||||
|
||||
|
|
@ -153,7 +154,6 @@ async def generate_screenshot_switch_handler(archive_id=None):
|
|||
try:
|
||||
await lib.generate_archive_screenshot(archive_id)
|
||||
# Always send success event since exceptions are raised on failure
|
||||
from modules.archive import Archive
|
||||
archive = lib.get_archive(archive_id=archive_id)
|
||||
location = archive.location
|
||||
name = archive.file_group.title or archive.file_group.url
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import base64
|
||||
import base64
|
||||
import gzip
|
||||
import json
|
||||
import os
|
||||
|
|
@ -14,19 +13,21 @@ from typing import Optional, Tuple, List, Union
|
|||
from urllib.parse import urlparse
|
||||
|
||||
import pytz
|
||||
from sqlalchemy import asc
|
||||
from sqlalchemy import asc, func, BigInteger
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from modules.archive.models import Archive
|
||||
from wrolpi import dates
|
||||
from wrolpi.cmd import READABILITY_BIN, run_command
|
||||
from wrolpi.collections import Collection
|
||||
from wrolpi.common import get_media_directory, logger, extract_domain, escape_file_name, aiohttp_post, \
|
||||
format_html_string, split_lines_by_length, get_html_soup, get_title_from_html, get_wrolpi_config, html_screenshot, \
|
||||
ConfigFile
|
||||
from wrolpi.common import get_media_directory, get_relative_to_media_directory, logger, extract_domain, \
|
||||
escape_file_name, aiohttp_post, format_html_string, split_lines_by_length, get_html_soup, get_title_from_html, \
|
||||
get_wrolpi_config, html_screenshot, ConfigFile
|
||||
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.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
|
||||
|
|
@ -607,8 +608,8 @@ def link_domain_and_downloads(session: Session):
|
|||
- Recurring downloads whose destination is within the domain collection's directory (including subdirectories)
|
||||
- RSS downloads with sub_downloader='archive' (matched by URL domain)
|
||||
"""
|
||||
# Local import to avoid circular import: downloader -> archive -> downloader
|
||||
from wrolpi.downloader import Download
|
||||
from wrolpi.collections.models import Collection
|
||||
|
||||
# Only Downloads with a frequency can be a Collection Download.
|
||||
downloads = list(session.query(Download).filter(Download.frequency.isnot(None)).all())
|
||||
|
|
@ -855,9 +856,6 @@ def get_domains():
|
|||
This is a thin wrapper around Collection queries that adds archive-specific statistics.
|
||||
Returns a list of dicts with collection id, domain name, url_count, and total size.
|
||||
"""
|
||||
from sqlalchemy import func, BigInteger
|
||||
from wrolpi.files.models import FileGroup
|
||||
|
||||
with get_db_session() as session:
|
||||
# Query all domain collections with archive statistics in a single query
|
||||
# This uses ORM for better maintainability while keeping performance
|
||||
|
|
@ -1032,7 +1030,6 @@ def search_archives(search_str: str, domain: str, limit: int, offset: int, order
|
|||
'''.strip()
|
||||
logger.debug(stmt, params)
|
||||
|
||||
from wrolpi.files.lib import handle_file_group_search_results
|
||||
results, total = handle_file_group_search_results(stmt, params)
|
||||
return results, total
|
||||
|
||||
|
|
@ -1058,7 +1055,6 @@ async def search_domains_by_name(name: str, limit: int = 5, session: Session = N
|
|||
.all()
|
||||
|
||||
# Convert to old Domain format for backward compatibility
|
||||
from wrolpi.common import get_relative_to_media_directory
|
||||
archive_dir = get_archive_directory()
|
||||
return [
|
||||
{
|
||||
|
|
@ -1155,8 +1151,6 @@ async def generate_archive_screenshot(archive_id: int) -> pathlib.Path:
|
|||
ValueError: If Archive has no singlefile
|
||||
RuntimeError: If screenshot generation fails
|
||||
"""
|
||||
from wrolpi.db import get_db_session
|
||||
|
||||
with get_db_session() as session:
|
||||
archive = Archive.find_by_id(archive_id, session=session)
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ class Archive(Base, ModelHelper):
|
|||
|
||||
@staticmethod
|
||||
def can_model(file_group: FileGroup) -> bool:
|
||||
# Local import to avoid circular import within archive module
|
||||
from modules.archive.lib import is_singlefile_file
|
||||
if file_group.mimetype.startswith('text') and is_singlefile_file(file_group.primary_path):
|
||||
return True
|
||||
|
|
@ -98,6 +99,7 @@ class Archive(Base, ModelHelper):
|
|||
|
||||
@staticmethod
|
||||
def do_model(file_group: FileGroup, session: Session) -> 'Archive':
|
||||
# Local import to avoid circular import within archive module
|
||||
from modules.archive import model_archive
|
||||
archive = model_archive(file_group, session)
|
||||
archive.validate()
|
||||
|
|
@ -155,6 +157,7 @@ class Archive(Base, ModelHelper):
|
|||
|
||||
@property
|
||||
def singlefile_file(self) -> Optional[dict]:
|
||||
# Local import to avoid circular import within archive module
|
||||
from modules.archive.lib import is_singlefile_file
|
||||
for file in self.file_group.my_html_files():
|
||||
if is_singlefile_file(file['path']):
|
||||
|
|
@ -315,6 +318,7 @@ class Archive(Base, ModelHelper):
|
|||
|
||||
def apply_domain(self):
|
||||
"""Get the domain collection from the URL."""
|
||||
# Local import to avoid circular import within archive module
|
||||
from modules.archive.lib import get_or_create_domain_collection
|
||||
collection = None
|
||||
if self.file_group.url:
|
||||
|
|
@ -332,6 +336,7 @@ class Archive(Base, ModelHelper):
|
|||
|
||||
def apply_metadata(self):
|
||||
"""Read and apply <meta> (and more) data from the Singlefile HTML."""
|
||||
# Local import to avoid circular import within archive module
|
||||
from modules.archive import lib
|
||||
contents = self.singlefile_path.read_bytes()
|
||||
|
||||
|
|
@ -365,6 +370,7 @@ class Archive(Base, ModelHelper):
|
|||
"""Create a new Archive and FileGroup from the provided paths.
|
||||
|
||||
The files will be read and Archive data extracted."""
|
||||
# Local import to avoid circular import within archive module
|
||||
from modules.archive import model_archive
|
||||
file_group = FileGroup.from_paths(session, *paths)
|
||||
archive = model_archive(file_group, session)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue