support case insensitive and normalized file and folder names.
This commit is contained in:
parent
0f12549ec3
commit
b569c20b6e
@ -68,7 +68,7 @@ class FileApi(BaseApi):
|
|||||||
def move(self, file: File, folder_id: str) -> bool:
|
def move(self, file: File, folder_id: str) -> bool:
|
||||||
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
|
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
|
||||||
url = self.ENTRYPOINT + file.id + "/move/"
|
url = self.ENTRYPOINT + file.id + "/move/"
|
||||||
data = {"folder": folder_id}
|
data = {"folder": folder_id, "name": file.name}
|
||||||
token_check(self.connection)
|
token_check(self.connection)
|
||||||
response = self.connection.post(url, data=data)
|
response = self.connection.post(url, data=data)
|
||||||
self._raise_response_error(response)
|
self._raise_response_error(response)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from argparse import _SubParsersAction
|
from argparse import _SubParsersAction
|
||||||
|
from unicodedata import normalize
|
||||||
|
|
||||||
from mdrsclient.api import FolderApi, LaboratoryApi
|
from mdrsclient.api import FolderApi, LaboratoryApi
|
||||||
from mdrsclient.config import ConfigFile
|
from mdrsclient.config import ConfigFile
|
||||||
@ -39,7 +40,7 @@ class BaseCommand(ABC):
|
|||||||
self, connection: MDRSConnection, laboratory: Laboratory, path: str, password: str | None = None
|
self, connection: MDRSConnection, laboratory: Laboratory, path: str, password: str | None = None
|
||||||
) -> Folder:
|
) -> Folder:
|
||||||
folder_api = FolderApi(connection)
|
folder_api = FolderApi(connection)
|
||||||
folders = folder_api.list(laboratory.id, path)
|
folders = folder_api.list(laboratory.id, normalize("NFC", path))
|
||||||
if len(folders) != 1:
|
if len(folders) != 1:
|
||||||
raise UnexpectedException(f"Folder `{path}` not found.")
|
raise UnexpectedException(f"Folder `{path}` not found.")
|
||||||
if folders[0].lock:
|
if folders[0].lock:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
import os
|
import os
|
||||||
from argparse import Namespace, _SubParsersAction
|
from argparse import Namespace, _SubParsersAction
|
||||||
|
from unicodedata import normalize
|
||||||
|
|
||||||
from pydantic import parse_obj_as
|
from pydantic import parse_obj_as
|
||||||
|
|
||||||
@ -49,12 +50,10 @@ class MvCommand(BaseCommand):
|
|||||||
if d_sub_folder is not None:
|
if d_sub_folder is not None:
|
||||||
raise IllegalArgumentException(f"Cannot overwrite non-folder `{d_basename}` with folder `{d_path}`.")
|
raise IllegalArgumentException(f"Cannot overwrite non-folder `{d_basename}` with folder `{d_path}`.")
|
||||||
file_api = FileApi(connection)
|
file_api = FileApi(connection)
|
||||||
if s_parent_folder.id != d_parent_folder.id:
|
if s_parent_folder.id != d_parent_folder.id or d_basename != s_basename:
|
||||||
file_api.move(s_file, d_parent_folder.id)
|
d_file_dict = dataclasses.asdict(s_file) | {"name": normalize("NFC", d_basename)}
|
||||||
if d_basename != s_basename:
|
|
||||||
d_file_dict = dataclasses.asdict(s_file) | {"name": d_basename}
|
|
||||||
d_file = parse_obj_as(File, d_file_dict)
|
d_file = parse_obj_as(File, d_file_dict)
|
||||||
file_api.update(d_file, None)
|
file_api.move(d_file, d_parent_folder.id)
|
||||||
else:
|
else:
|
||||||
s_folder = s_parent_folder.find_sub_folder(s_basename)
|
s_folder = s_parent_folder.find_sub_folder(s_basename)
|
||||||
if s_folder is None:
|
if s_folder is None:
|
||||||
@ -71,6 +70,6 @@ class MvCommand(BaseCommand):
|
|||||||
if s_parent_folder.id != d_parent_folder.id:
|
if s_parent_folder.id != d_parent_folder.id:
|
||||||
folder_api.move(s_folder, d_parent_folder.id)
|
folder_api.move(s_folder, d_parent_folder.id)
|
||||||
if s_basename != d_basename:
|
if s_basename != d_basename:
|
||||||
d_folder_dict = dataclasses.asdict(s_folder) | {"name": d_basename}
|
d_folder_dict = dataclasses.asdict(s_folder) | {"name": normalize("NFC", d_basename)}
|
||||||
d_folder = parse_obj_as(FolderSimple, d_folder_dict)
|
d_folder = parse_obj_as(FolderSimple, d_folder_dict)
|
||||||
folder_api.update(d_folder)
|
folder_api.update(d_folder)
|
||||||
|
@ -46,7 +46,7 @@ class UploadCommand(BaseCommand):
|
|||||||
folder_map: dict[str, Folder] = {}
|
folder_map: dict[str, Folder] = {}
|
||||||
folder_map[r_path] = folder
|
folder_map[r_path] = folder
|
||||||
l_basename = os.path.basename(l_path)
|
l_basename = os.path.basename(l_path)
|
||||||
for dirpath, dirnames, filenames in os.walk(l_path):
|
for dirpath, _, filenames in os.walk(l_path):
|
||||||
sub = l_basename if dirpath == l_path else os.path.join(l_basename, os.path.relpath(dirpath, l_path))
|
sub = l_basename if dirpath == l_path else os.path.join(l_basename, os.path.relpath(dirpath, l_path))
|
||||||
d_dirname = os.path.join(r_path, sub)
|
d_dirname = os.path.join(r_path, sub)
|
||||||
d_basename = os.path.basename(d_dirname)
|
d_basename = os.path.basename(d_dirname)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from typing import Final, NamedTuple
|
from typing import Final, NamedTuple
|
||||||
|
from unicodedata import normalize
|
||||||
|
|
||||||
from pydantic.dataclasses import dataclass
|
from pydantic.dataclasses import dataclass
|
||||||
|
|
||||||
@ -71,7 +72,9 @@ class Folder(FolderSimple):
|
|||||||
path: str
|
path: str
|
||||||
|
|
||||||
def find_sub_folder(self, name: str) -> FolderSimple | None:
|
def find_sub_folder(self, name: str) -> FolderSimple | None:
|
||||||
return next((x for x in self.sub_folders if x.name == name), None)
|
_name = normalize("NFC", name).lower()
|
||||||
|
return next((x for x in self.sub_folders if x.name.lower() == _name), None)
|
||||||
|
|
||||||
def find_file(self, name: str) -> File | None:
|
def find_file(self, name: str) -> File | None:
|
||||||
return next((x for x in self.files if x.name == name), None)
|
_name = normalize("NFC", name).lower()
|
||||||
|
return next((x for x in self.files if x.name.lower() == _name), None)
|
||||||
|
Loading…
Reference in New Issue
Block a user