Files
MoviePilot/app/application/storage.py
freeman f3ad81b39e style: apply safe ruff auto-fixes and exempt startup late imports
Run `ruff check app tests scripts --fix` with the configured rule set
(E4/E7/E9/F/I): import sorting (I001), f-strings without placeholders
(F541), lambda/variable/unused-import cleanups that ruff marks safe.
Nine files whose only ruff debt sits next to pre-existing pylint
import-resolution errors (lazy exports, sys.path script imports) or
whose "unused" imports are reached through attribute access by tests are
left untouched so the changed-file pylint gate and the benchmark tests
stay green; their diagnostics remain in the baseline.

app/startup/lifecycle/__init__.py and app/main.py import business
modules after cache composition, import-path and stdio setup on purpose
(the source comments document the contract), so declare E402
per-file-ignores for them instead of adding per-line noqa.

Ruff ratchet watermark drops from 498 to 100; sync the baseline fixture
and the optimization checklist figure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-09 13:29:09 +08:00

83 lines
2.4 KiB
Python

from typing import List, Optional
from app.application.configuration import get_configured_system_config
from app.schemas.system import StorageConf as _SchemaStorageConf
from app.schemas.types import SystemConfigKey
class StorageHelper:
"""
存储帮助类
"""
@staticmethod
def get_storagies() -> List[_SchemaStorageConf]:
"""
获取所有存储设置
"""
storage_confs: List[dict] = get_configured_system_config().get(SystemConfigKey.Storages)
if not storage_confs:
return []
return [_SchemaStorageConf(**s) for s in storage_confs]
def get_storage(self, storage: str) -> Optional[_SchemaStorageConf]:
"""
获取指定存储配置
"""
storagies = self.get_storagies()
for s in storagies:
if s.type == storage:
return s
return None
def set_storage(self, storage: str, conf: dict):
"""
设置存储配置
"""
storagies = self.get_storagies()
if not storagies:
storagies = [
_SchemaStorageConf(
type=storage,
config=conf
)
]
else:
for s in storagies:
if s.type == storage:
s.config = conf
break
get_configured_system_config().set(SystemConfigKey.Storages, [s.model_dump() for s in storagies])
def add_storage(self, storage: str, name: str, conf: dict):
"""
添加存储配置
"""
storagies = self.get_storagies()
if not storagies:
storagies = [
_SchemaStorageConf(
type=storage,
name=name,
config=conf
)
]
else:
storagies.append(_SchemaStorageConf(
type=storage,
name=name,
config=conf
))
get_configured_system_config().set(SystemConfigKey.Storages, [s.model_dump() for s in storagies])
def reset_storage(self, storage: str):
"""
重置存储配置
"""
storagies = self.get_storagies()
for s in storagies:
if s.type == storage:
s.config = {}
break
get_configured_system_config().set(SystemConfigKey.Storages, [s.model_dump() for s in storagies])