refactor: use services layer and modularize transfer operations
Decouple CLI commands from internal helper logic and consolidate the core file transfer operations in the service layer to improve library portability. - Make MdrsClient subclass MdrsService to inherit resource resolution. - Remove all deprecated helper methods from BaseCommand. - Move core upload and download logic to a new transfer module. - Refactor all CLI commands to route actions through MdrsClient. - Eliminate circular imports between client and CLI command modules.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from typing import Any
|
||||
import os
|
||||
import re
|
||||
from typing import Any
|
||||
from unicodedata import normalize
|
||||
|
||||
from mdrsclient.api import DoiApi, FilesApi, FoldersApi, LaboratoriesApi, UsersApi
|
||||
from mdrsclient.cache import CacheInterface
|
||||
from mdrsclient.config import ConfigFile
|
||||
from mdrsclient.connection import MDRSConnection
|
||||
from mdrsclient.exceptions import (
|
||||
@@ -21,11 +22,11 @@ class MdrsService:
|
||||
self.connection = connection
|
||||
|
||||
@classmethod
|
||||
def create_connection(cls, remote: str) -> MDRSConnection:
|
||||
def create_connection(cls, remote: str, cache: CacheInterface | None = None) -> MDRSConnection:
|
||||
config = ConfigFile(remote)
|
||||
if config.url is None:
|
||||
raise MissingConfigurationException(f"Remote host `{remote}` is not found.")
|
||||
return MDRSConnection(config.remote, config.url)
|
||||
return MDRSConnection(config.remote, config.url, cache=cache)
|
||||
|
||||
def login(self, username: str, password: str) -> tuple[Token, User]:
|
||||
user_api = UsersApi(self.connection)
|
||||
|
||||
Reference in New Issue
Block a user