Squashing config rework.

This commit is contained in:
Roland 2022-02-16 21:57:27 -07:00
parent 5425142adb
commit 08065155cf
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
38 changed files with 1046 additions and 633 deletions

View file

@ -5,7 +5,6 @@ from pathlib import Path
from typing import List
from uuid import uuid4
import magic
import psycopg2
from sqlalchemy.orm import Session
@ -16,6 +15,13 @@ from wrolpi.db import get_db_session, get_db_curs, get_ranked_models
from wrolpi.errors import InvalidFile
from wrolpi.vars import PYTEST
try:
import magic
have_magic = True
except ImportError:
logger.error('Could not import magic. Is libmagic installed?')
have_magic = False
logger = logger.getChild(__name__)
__all__ = ['list_files', 'delete_file', 'split_file_name', 'upsert_file', 'refresh_files', 'search']
@ -96,7 +102,7 @@ def upsert_file(path: Path, session: Session) -> File:
if not file:
file = File(path=path)
session.add(file)
if not file.mimetype:
if not file.mimetype and have_magic:
file.mimetype = magic.from_file(str(path), mime=True)
if not file.title:
file.title = split_file_name(path)