mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
Squashing config rework.
This commit is contained in:
parent
5425142adb
commit
08065155cf
38 changed files with 1046 additions and 633 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue