2023-12-10 00:04:34 +00:00
|
|
|
from logging import getLogger
|
|
|
|
from os import path
|
2023-12-10 00:46:47 +00:00
|
|
|
from typing import Optional
|
2023-12-10 00:04:34 +00:00
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
2023-12-10 00:46:47 +00:00
|
|
|
from ..utils import ConversionContext
|
|
|
|
from .base import BaseClient
|
|
|
|
|
2023-12-10 00:04:34 +00:00
|
|
|
logger = getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class FileClient(BaseClient):
|
|
|
|
protocol = "file://"
|
|
|
|
|
|
|
|
root: str
|
|
|
|
|
|
|
|
def __init__(self, root: str):
|
|
|
|
self.root = root
|
|
|
|
|
2023-12-10 00:46:47 +00:00
|
|
|
def download(
|
|
|
|
self,
|
|
|
|
_conversion: ConversionContext,
|
|
|
|
_name: str,
|
|
|
|
uri: str,
|
|
|
|
format: Optional[str] = None,
|
|
|
|
dest: Optional[str] = None,
|
|
|
|
) -> str:
|
2023-12-10 00:04:34 +00:00
|
|
|
parts = urlparse(uri)
|
|
|
|
logger.info("loading model from: %s", parts.path)
|
|
|
|
return path.join(self.root, parts.path)
|