auto-archiver/src/auto_archiver/storages/base_storage.py

34 wiersze
905 B
Python
Czysty Zwykły widok Historia

import os, uuid
2022-03-16 18:50:29 +00:00
from loguru import logger
from abc import ABC, abstractmethod
2022-05-26 17:18:29 +00:00
from pathlib import Path
class Storage(ABC):
2022-05-09 12:54:48 +00:00
TMP_FOLDER = "tmp/"
2022-06-03 13:46:00 +00:00
@abstractmethod
def __init__(self, config): pass
@abstractmethod
2022-03-15 10:32:39 +00:00
def get_cdn_url(self, key): pass
@abstractmethod
2022-03-15 10:32:39 +00:00
def exists(self, key): pass
@abstractmethod
def uploadf(self, file, key, **kwargs): pass
def clean_key(self, key):
# Some storages does not work well with trailing forward slashes and some keys come with that
if key.startswith('/'):
logger.debug(f'Found and fixed a leading "/" for {key=}')
return key[1:]
return key
def upload(self, filename: str, key: str, **kwargs):
2022-03-16 18:50:29 +00:00
logger.debug(f'[{self.__class__.__name__}] uploading file {filename} with key {key}')
with open(filename, 'rb') as f:
self.uploadf(f, key, **kwargs)