mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
Reformatting code.
This commit is contained in:
parent
4b8b897eb3
commit
947135985d
13 changed files with 54 additions and 57 deletions
|
|
@ -26,7 +26,7 @@ import {SearchView, useSearch, useSearchSuggestions} from "./components/Search";
|
|||
import {KiwixRestartMessage, OutdatedZimsMessage} from "./components/Zim";
|
||||
import {useWROLMode} from "./hooks/customHooks";
|
||||
import {FileSearchFilterButton} from "./components/Files";
|
||||
import {dateRangeIsEmpty, DateSelectorButton} from "./components/DatesSelector";
|
||||
import {DateSelectorButton} from "./components/DatesSelector";
|
||||
|
||||
function FlagsMessages({flags}) {
|
||||
const {settings, fetchSettings} = React.useContext(SettingsContext);
|
||||
|
|
|
|||
|
|
@ -39,14 +39,7 @@ import {
|
|||
TableCell
|
||||
} from "semantic-ui-react";
|
||||
import {ChannelEditPage, ChannelNewPage, ChannelsPage} from "./Channels";
|
||||
import {
|
||||
useChannel,
|
||||
useQuery,
|
||||
useSearchOrder,
|
||||
useSearchVideos,
|
||||
useVideo,
|
||||
useVideoStatistics
|
||||
} from "../hooks/customHooks";
|
||||
import {useChannel, useSearchOrder, useSearchVideos, useVideo, useVideoStatistics} from "../hooks/customHooks";
|
||||
import {FileRowTagIcon, FilesView} from "./Files";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
||||
|
|
@ -184,10 +177,10 @@ function VideosPage() {
|
|||
|
||||
const [localSearchStr, setLocalSearchStr] = React.useState(searchStr || '');
|
||||
const searchInput = <SearchInput
|
||||
searchStr={localSearchStr}
|
||||
onChange={setLocalSearchStr}
|
||||
onSubmit={setSearchStr}
|
||||
placeholder='Search Videos...'
|
||||
searchStr={localSearchStr}
|
||||
onChange={setLocalSearchStr}
|
||||
onSubmit={setSearchStr}
|
||||
placeholder='Search Videos...'
|
||||
/>;
|
||||
|
||||
return <>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import {
|
|||
import {Button, Header, Modal, ModalActions, ModalContent, ModalHeader, Placeholder, Segment, Table} from "../Theme";
|
||||
import {useDownloads} from "../../hooks/customHooks";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {Media} from "../../contexts/contexts";
|
||||
|
||||
function ClearCompleteDownloads({callback}) {
|
||||
async function localClearDownloads() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -207,8 +207,8 @@ async def search_channels_by_name(name: str, limit: int = 5, session: Session =
|
|||
name_no_spaces = ''.join(name.split(' '))
|
||||
stmt = session.query(Channel) \
|
||||
.filter(or_(
|
||||
Channel.name.ilike(f'%{name}%'),
|
||||
Channel.name.ilike(f'%{name_no_spaces}%'),
|
||||
Channel.name.ilike(f'%{name}%'),
|
||||
Channel.name.ilike(f'%{name_no_spaces}%'),
|
||||
)) \
|
||||
.order_by(asc(Channel.name)) \
|
||||
.limit(limit)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from dataclasses import dataclass, field
|
||||
from datetime import date
|
||||
from typing import List, Optional
|
||||
|
||||
from modules.videos.video.lib import DEFAULT_VIDEO_ORDER, VIDEO_QUERY_LIMIT
|
||||
|
|
|
|||
|
|
@ -251,8 +251,10 @@ def test_search_videos(test_session, video_factory, assert_video_search, simple_
|
|||
assert_video_search(assert_total=3, assert_ids=[vid1.id, vid2.id, vid3.id], order_by='published_datetime')
|
||||
assert_video_search(assert_total=3, assert_ids=[vid3.id, vid2.id, vid1.id], order_by='-published_datetime')
|
||||
assert_video_search(assert_total=3, assert_ids=[vid3.id, vid2.id], order_by='-published_datetime', limit=2)
|
||||
assert_video_search(assert_total=3, assert_ids=[vid2.id, vid1.id], order_by='-published_datetime', limit=2, offset=1)
|
||||
assert_video_search(assert_total=1, assert_ids=[vid2.id], order_by='-published_datetime', channel_id=simple_channel.id)
|
||||
assert_video_search(assert_total=3, assert_ids=[vid2.id, vid1.id], order_by='-published_datetime', limit=2,
|
||||
offset=1)
|
||||
assert_video_search(assert_total=1, assert_ids=[vid2.id], order_by='-published_datetime',
|
||||
channel_id=simple_channel.id)
|
||||
assert_video_search(assert_total=2, assert_ids=[vid1.id, vid2.id], tag_names=[tag1.name])
|
||||
assert_video_search(assert_total=2, assert_ids=[vid3.id, vid2.id], tag_names=[tag2.name])
|
||||
assert_video_search(assert_total=2, assert_ids=[vid1.id], tag_names=[tag1.name], limit=1)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import asyncio
|
||||
import random
|
||||
import tempfile
|
||||
from datetime import timedelta
|
||||
from typing import Tuple, Optional, List, Dict
|
||||
|
||||
|
|
@ -9,7 +8,7 @@ from sqlalchemy import or_
|
|||
from sqlalchemy.orm import Session
|
||||
|
||||
from modules.videos.models import Video
|
||||
from wrolpi.common import run_after, logger, limit_concurrent, wrol_mode_check, chdir
|
||||
from wrolpi.common import run_after, logger, limit_concurrent, wrol_mode_check
|
||||
from wrolpi.dates import now
|
||||
from wrolpi.db import get_db_session, optional_session
|
||||
from wrolpi.downloader import download_manager
|
||||
|
|
|
|||
|
|
@ -130,14 +130,17 @@ __all__ = [
|
|||
'extract_domain',
|
||||
'extract_headlines',
|
||||
'extract_html_text',
|
||||
'format_html_string',
|
||||
'format_json_file',
|
||||
'get_absolute_media_path',
|
||||
'get_wrolpi_config',
|
||||
'get_download_info',
|
||||
'get_files_and_directories',
|
||||
'get_html_soup',
|
||||
'get_media_directory',
|
||||
'get_relative_to_media_directory',
|
||||
'get_warn_once',
|
||||
'get_wrolpi_config',
|
||||
'html_screenshot',
|
||||
'insert_parameter',
|
||||
'iterify',
|
||||
'limit_concurrent',
|
||||
|
|
@ -150,6 +153,7 @@ __all__ = [
|
|||
'register_modeler',
|
||||
'register_refresh_cleanup',
|
||||
'remove_whitespace',
|
||||
'resolve_generators',
|
||||
'run_after',
|
||||
'set_log_level',
|
||||
'set_test_config',
|
||||
|
|
@ -164,8 +168,6 @@ __all__ = [
|
|||
'wrol_mode_check',
|
||||
'wrol_mode_enabled',
|
||||
'zig_zag',
|
||||
'html_screenshot',
|
||||
'format_html_string',
|
||||
]
|
||||
|
||||
# Base is used for all SQLAlchemy models.
|
||||
|
|
@ -902,7 +904,7 @@ def get_files_and_directories(directory: Path):
|
|||
|
||||
|
||||
# These characters are invalid in Windows or Linux.
|
||||
INVALID_FILE_CHARS = re.compile(r'[/<>:\|"\\\?\*%!\n\r]')
|
||||
INVALID_FILE_CHARS = re.compile(r'[/<>:|"\\?*%!\n\r]')
|
||||
|
||||
SPACE_FILE_CHARS = re.compile(r'( +)|(\t+)')
|
||||
|
||||
|
|
@ -1228,7 +1230,7 @@ def chunks(it: Iterable, size: int):
|
|||
return iter(lambda: tuple(islice(it, size)), ())
|
||||
|
||||
|
||||
def chunks_by_stem(it: List[Union[pathlib.Path, str]], size: int) -> Generator[List[pathlib.Path], None, None]:
|
||||
def chunks_by_stem(it: List[Union[pathlib.Path, str, int]], size: int) -> Generator[List[pathlib.Path], None, None]:
|
||||
"""
|
||||
Attempt to split a list of paths near the defined size. Keep groups of files together when they share
|
||||
matching names.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import logging
|
|||
import pathlib
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from sqlalchemy import Column, Integer, String, BigInteger, ForeignKey, or_, and_
|
||||
from sqlalchemy import Column, Integer, BigInteger, ForeignKey, or_, and_
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from wrolpi.common import ModelHelper, Base, register_modeler, get_html_soup
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ from wrolpi import flags
|
|||
from wrolpi.cmd import which
|
||||
from wrolpi.common import get_media_directory, wrol_mode_check, logger, limit_concurrent, \
|
||||
partition, cancelable_wrapper, \
|
||||
get_files_and_directories, chunks_by_stem, apply_modelers, apply_refresh_cleanup, background_task, walk, get_wrolpi_config, \
|
||||
get_files_and_directories, chunks_by_stem, apply_modelers, apply_refresh_cleanup, background_task, walk, \
|
||||
get_wrolpi_config, \
|
||||
timer
|
||||
from wrolpi.dates import now, from_timestamp, months_selector_to_where, date_range_to_where
|
||||
from wrolpi.db import get_db_session, get_db_curs, mogrify, optional_session
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import pytz
|
|||
|
||||
from wrolpi import dates
|
||||
from wrolpi.common import register_modeler, logger, truncate_generator_bytes, truncate_object_bytes, \
|
||||
split_lines_by_length
|
||||
split_lines_by_length, slow_logger
|
||||
from wrolpi.db import get_db_session
|
||||
from wrolpi.files.indexers import Indexer
|
||||
from wrolpi.files.models import FileGroup
|
||||
|
|
@ -124,29 +124,32 @@ async def pdf_modeler():
|
|||
|
||||
reader = PdfReader(pdf_file)
|
||||
|
||||
metadata = get_pdf_metadata(reader, pdf_file)
|
||||
with slow_logger(2, f'Modeling PDF took %(elapsed)s seconds: {file_group}',
|
||||
logger__=logger):
|
||||
metadata = get_pdf_metadata(reader, pdf_file)
|
||||
|
||||
words = ''
|
||||
if pdf_file.stat().st_size > FILE_MAX_PDF_SIZE:
|
||||
logger.warning(f'PDF too large to fully index: {pdf_file}')
|
||||
else:
|
||||
try:
|
||||
# PDFs are complex, don't fail to create title index if text extraction fails.
|
||||
words = '\n'.join(truncate_generator_bytes(get_words(reader, pdf_file), FILE_MAX_TEXT_SIZE))
|
||||
words = truncate_object_bytes(words, FILE_MAX_TEXT_SIZE)
|
||||
words = split_lines_by_length(words)
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to index {pdf_file}', exc_info=e)
|
||||
if PYTEST:
|
||||
raise
|
||||
words = ''
|
||||
if pdf_file.stat().st_size > FILE_MAX_PDF_SIZE:
|
||||
logger.warning(f'PDF too large to fully index: {pdf_file}')
|
||||
else:
|
||||
try:
|
||||
# PDFs are complex, don't fail to create title index if text extraction fails.
|
||||
words = '\n'.join(
|
||||
truncate_generator_bytes(get_words(reader, pdf_file), FILE_MAX_TEXT_SIZE))
|
||||
words = truncate_object_bytes(words, FILE_MAX_TEXT_SIZE)
|
||||
words = split_lines_by_length(words)
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to index {pdf_file}', exc_info=e)
|
||||
if PYTEST:
|
||||
raise
|
||||
|
||||
file_group.title = file_group.a_text = metadata.title or file_title
|
||||
file_group.author = file_group.b_text = metadata.author
|
||||
file_group.c_text = file_title # The name of the file may not match the title in the PDF metadata.
|
||||
file_group.d_text = words or None
|
||||
file_group.published_datetime = metadata.published_datetime
|
||||
file_group.published_modified_datetime = metadata.modification_datetime
|
||||
file_group.model = 'pdf'
|
||||
file_group.title = file_group.a_text = metadata.title or file_title
|
||||
file_group.author = file_group.b_text = metadata.author
|
||||
file_group.c_text = file_title # The name of the file may not match the title in the PDF metadata.
|
||||
file_group.d_text = words or None
|
||||
file_group.published_datetime = metadata.published_datetime
|
||||
file_group.published_modified_datetime = metadata.modification_datetime
|
||||
file_group.model = 'pdf'
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to index PDF {pdf_file}', exc_info=e)
|
||||
if PYTEST:
|
||||
|
|
|
|||
|
|
@ -66,38 +66,38 @@ def test_insert_parameter():
|
|||
wherever that may be according to the function's signature.
|
||||
"""
|
||||
|
||||
def func(foo, bar):
|
||||
def func(foo, bar): # noqa
|
||||
pass
|
||||
|
||||
results = common.insert_parameter(func, 'bar', 'bar', (1,), {})
|
||||
assert results == ((1, 'bar'), {})
|
||||
|
||||
def func(foo, bar, baz):
|
||||
def func(foo, bar, baz): # noqa
|
||||
pass
|
||||
|
||||
results = common.insert_parameter(func, 'bar', 'bar', (1, 2), {})
|
||||
assert results == ((1, 'bar', 2), {})
|
||||
|
||||
def func(foo, baz, bar=None):
|
||||
def func(foo, baz, bar=None): # noqa
|
||||
pass
|
||||
|
||||
results = common.insert_parameter(func, 'bar', 'bar', (1, 2), {})
|
||||
assert results == ((1, 2, 'bar'), {})
|
||||
|
||||
def func(foo, baz, bar=None):
|
||||
def func(foo, baz, bar=None): # noqa
|
||||
pass
|
||||
|
||||
results = common.insert_parameter(func, 'baz', 'baz', (1, 2), {})
|
||||
assert results == ((1, 'baz', 2), {})
|
||||
|
||||
def func(foo, baz, qux=None, bar=None):
|
||||
def func(foo, baz, qux=None, bar=None): # noqa
|
||||
pass
|
||||
|
||||
results = common.insert_parameter(func, 'bar', 'bar', (1, 2, 3), {})
|
||||
assert results == ((1, 2, 3, 'bar'), {})
|
||||
|
||||
# bar is not defined as a parameter!
|
||||
def func(foo):
|
||||
def func(foo): # noqa
|
||||
pass
|
||||
|
||||
pytest.raises(TypeError, common.insert_parameter, func, 'bar', 'bar', (1,), {})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue