agi-med-common 5.2.2__tar.gz → 5.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/PKG-INFO +1 -1
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/__init__.py +2 -2
- agi_med_common-5.2.4/src/agi_med_common/file_storage.py +113 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/utils.py +5 -3
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common.egg-info/PKG-INFO +1 -1
- agi_med_common-5.2.2/src/agi_med_common/file_storage.py +0 -63
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/README.md +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/pyproject.toml +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/setup.cfg +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/api.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/__init__.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/base.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/base_config_models/__init__.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/base_config_models/gigachat_config.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/chat.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/chat_item.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/enums.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/tracks.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/models/widget.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/parallel_map.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/type_union.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/validators.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common/xml_parser.py +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common.egg-info/SOURCES.txt +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common.egg-info/dependency_links.txt +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common.egg-info/requires.txt +0 -0
- {agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common.egg-info/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "5.2.
|
1
|
+
__version__ = "5.2.4"
|
2
2
|
|
3
3
|
from .file_storage import FileStorage, ResourceId
|
4
4
|
from .models.base import Base
|
@@ -9,6 +9,6 @@ from .models.enums import MTRSLabelEnum, DiagnosticsXMLTagEnum, MTRSXMLTagEnum,
|
|
9
9
|
from .models.tracks import TrackInfo, DomainInfo
|
10
10
|
from .models.widget import Widget
|
11
11
|
from .parallel_map import parallel_map
|
12
|
-
from .utils import make_session_id, read_json, try_parse_json, try_parse_int, try_parse_float, pretty_line
|
12
|
+
from .utils import make_session_id, read_json, try_parse_json, try_parse_int, try_parse_float, try_parse_bool, pretty_line
|
13
13
|
from .validators import ExistingPath, ExistingFile, ExistingDir, StrNotEmpty, SecretStrNotEmpty, Prompt, Message
|
14
14
|
from .xml_parser import XMLParser
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import string
|
2
|
+
from hashlib import md5
|
3
|
+
from pathlib import Path
|
4
|
+
from zipfile import ZipFile, is_zipfile
|
5
|
+
|
6
|
+
|
7
|
+
ResourceId = str
|
8
|
+
ASCII_DIGITS = set(string.ascii_lowercase + string.digits)
|
9
|
+
SUFFIX_DIR = ".dir"
|
10
|
+
|
11
|
+
|
12
|
+
def _validate_exist(files_dir):
|
13
|
+
if not files_dir.exists():
|
14
|
+
err = f"Failed to access file-storage directory: {files_dir}"
|
15
|
+
raise OSError(err)
|
16
|
+
|
17
|
+
|
18
|
+
def _validate_dtype(dtype: str):
|
19
|
+
if all(map(ASCII_DIGITS.__contains__, dtype)):
|
20
|
+
return
|
21
|
+
raise ValueError(f"Bad dtype: {dtype}")
|
22
|
+
|
23
|
+
|
24
|
+
def generate_fname(content, dtype):
|
25
|
+
fname_hash = md5(content).hexdigest()
|
26
|
+
fname = f"{fname_hash}.{dtype}"
|
27
|
+
return fname
|
28
|
+
|
29
|
+
|
30
|
+
class FileStorage:
|
31
|
+
def __init__(self, files_dir):
|
32
|
+
self.files_dir = Path(files_dir)
|
33
|
+
self.files_dir.mkdir(exist_ok=True, parents=True)
|
34
|
+
_validate_exist(self.files_dir)
|
35
|
+
|
36
|
+
def _generate_fname_path(self, content: bytes, dtype: str):
|
37
|
+
fpath = self.files_dir / generate_fname(content, dtype)
|
38
|
+
return fpath
|
39
|
+
|
40
|
+
def upload_maybe(self, content: bytes | None, dtype: str) -> ResourceId | None:
|
41
|
+
if not content:
|
42
|
+
return None
|
43
|
+
resource_id = self.upload(content, dtype)
|
44
|
+
return resource_id
|
45
|
+
|
46
|
+
def upload(self, content: bytes | str, dtype: str) -> ResourceId:
|
47
|
+
_validate_dtype(dtype)
|
48
|
+
if isinstance(content, str):
|
49
|
+
content = content.encode()
|
50
|
+
fpath = self._generate_fname_path(content, dtype)
|
51
|
+
fpath.write_bytes(content)
|
52
|
+
return str(fpath)
|
53
|
+
|
54
|
+
def upload_dir(self, resource_ids: list[ResourceId]) -> ResourceId:
|
55
|
+
content = "\n".join(resource_ids)
|
56
|
+
res = self.upload(content, "dir")
|
57
|
+
return res
|
58
|
+
|
59
|
+
def download(self, resource_id: ResourceId) -> bytes:
|
60
|
+
return Path(resource_id).read_bytes()
|
61
|
+
|
62
|
+
def download_text(self, resource_id: ResourceId) -> str:
|
63
|
+
return Path(resource_id).read_text(encoding="utf-8")
|
64
|
+
|
65
|
+
def read_dir_or_none(self, resource_id: ResourceId) -> list[ResourceId] | None:
|
66
|
+
if not self.is_dir(resource_id):
|
67
|
+
return None
|
68
|
+
res = self.download_text(resource_id).split("\n")
|
69
|
+
return res
|
70
|
+
|
71
|
+
def _get_path(self, resource_id: ResourceId | None) -> Path | None:
|
72
|
+
if not resource_id:
|
73
|
+
return None
|
74
|
+
path = Path(resource_id)
|
75
|
+
return path if (path.exists() and path.is_file()) else None
|
76
|
+
|
77
|
+
def is_valid(self, resource_id: ResourceId | None) -> bool:
|
78
|
+
path = self._get_path(resource_id)
|
79
|
+
return path is not None
|
80
|
+
|
81
|
+
def is_file(self, resource_id: ResourceId | None) -> bool:
|
82
|
+
path = self._get_path(resource_id)
|
83
|
+
return path and path.suffix != SUFFIX_DIR
|
84
|
+
|
85
|
+
def is_dir(self, resource_id: ResourceId | None) -> bool:
|
86
|
+
path = self._get_path(resource_id)
|
87
|
+
return path and path.suffix == SUFFIX_DIR
|
88
|
+
|
89
|
+
def get_dtype(self, resource_id: ResourceId | None) -> str | None:
|
90
|
+
return resource_id and resource_id.rsplit(".")[-1]
|
91
|
+
|
92
|
+
def unzip_file(self, resource_id: str) -> ResourceId:
|
93
|
+
""" takes resource_id which refer to zip-archive, unpacks it and returns directory ResourceId with content of zip-archive """
|
94
|
+
path = self._get_path(resource_id)
|
95
|
+
if not path:
|
96
|
+
raise ValueError(f"Not found path: {resource_id}")
|
97
|
+
if not is_zipfile(resource_id):
|
98
|
+
raise ValueError(f"Expected zip archive but found: {resource_id}")
|
99
|
+
|
100
|
+
resource_ids = []
|
101
|
+
|
102
|
+
with ZipFile(path, mode='r') as zip_file:
|
103
|
+
files_info = zip_file.filelist
|
104
|
+
|
105
|
+
for file_info in zip_file.filelist:
|
106
|
+
file_dtype = file_info.filename.rsplit('.')[-1]
|
107
|
+
file_bytes = zip_file.read(file_info)
|
108
|
+
rid = self.upload(file_bytes, file_dtype)
|
109
|
+
resource_ids.append(rid)
|
110
|
+
|
111
|
+
res = self.upload_dir(resource_ids)
|
112
|
+
return res
|
113
|
+
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import codecs
|
2
2
|
import json
|
3
3
|
import os
|
4
|
+
from collections.abc import Iterable
|
4
5
|
from datetime import datetime
|
5
6
|
from pathlib import Path
|
6
|
-
from collections.abc import Iterable
|
7
7
|
|
8
8
|
|
9
9
|
def make_session_id() -> str:
|
10
|
-
return f"{datetime.now():%
|
10
|
+
return f"{datetime.now():%Y-%m-%d--%H-%M-%S}"
|
11
11
|
|
12
12
|
|
13
13
|
def read_json(path: Path | os.PathLike[str] | str) -> list | dict:
|
@@ -45,9 +45,11 @@ def try_parse_float(text: str) -> float | None:
|
|
45
45
|
return None
|
46
46
|
|
47
47
|
|
48
|
-
def try_parse_bool(v: str | bool) -> bool:
|
48
|
+
def try_parse_bool(v: str | bool | int) -> bool:
|
49
49
|
if isinstance(v, bool):
|
50
50
|
return v
|
51
|
+
if isinstance(v, int):
|
52
|
+
return bool(v)
|
51
53
|
return v.lower() in ("yes", "true", "t", "1")
|
52
54
|
|
53
55
|
|
@@ -1,63 +0,0 @@
|
|
1
|
-
import string
|
2
|
-
from hashlib import md5
|
3
|
-
from pathlib import Path
|
4
|
-
|
5
|
-
ResourceId = str
|
6
|
-
ASCII_DIGITS = set(string.ascii_lowercase + string.digits)
|
7
|
-
|
8
|
-
|
9
|
-
def _validate_exist(files_dir):
|
10
|
-
if not files_dir.exists():
|
11
|
-
err = f"Failed to access file-storage directory: {files_dir}"
|
12
|
-
raise OSError(err)
|
13
|
-
|
14
|
-
|
15
|
-
def _validate_dtype(dtype: str):
|
16
|
-
if all(map(ASCII_DIGITS.__contains__, dtype)):
|
17
|
-
return
|
18
|
-
raise ValueError(f"Bad dtype: {dtype}")
|
19
|
-
|
20
|
-
|
21
|
-
def generate_fname(content, dtype):
|
22
|
-
fname_hash = md5(content).hexdigest()
|
23
|
-
fname = f"{fname_hash}.{dtype}"
|
24
|
-
return fname
|
25
|
-
|
26
|
-
|
27
|
-
class FileStorage:
|
28
|
-
def __init__(self, files_dir):
|
29
|
-
self.files_dir = Path(files_dir)
|
30
|
-
self.files_dir.mkdir(exist_ok=True, parents=True)
|
31
|
-
_validate_exist(self.files_dir)
|
32
|
-
|
33
|
-
def _generate_fname_path(self, content, dtype):
|
34
|
-
fpath = self.files_dir / generate_fname(content, dtype)
|
35
|
-
return fpath
|
36
|
-
|
37
|
-
def upload_maybe(
|
38
|
-
self,
|
39
|
-
content: bytes | None,
|
40
|
-
dtype: str,
|
41
|
-
) -> ResourceId | None:
|
42
|
-
if not content:
|
43
|
-
return None
|
44
|
-
resource_id = self.upload(content, dtype)
|
45
|
-
return resource_id
|
46
|
-
|
47
|
-
def upload(self, content: bytes, dtype: str) -> ResourceId | None:
|
48
|
-
_validate_dtype(dtype)
|
49
|
-
fpath = self._generate_fname_path(content, dtype)
|
50
|
-
fpath.write_bytes(content)
|
51
|
-
return str(fpath)
|
52
|
-
|
53
|
-
def download(self, rid: ResourceId) -> bytes:
|
54
|
-
return Path(rid).read_bytes()
|
55
|
-
|
56
|
-
def download_text(self, rid: ResourceId) -> str:
|
57
|
-
return Path(rid).read_text(encoding="utf-8")
|
58
|
-
|
59
|
-
def is_valid(self, rid: ResourceId | None) -> bool:
|
60
|
-
return rid and Path(rid).exists() and Path(rid).is_file()
|
61
|
-
|
62
|
-
def get_dtype(self, rid: ResourceId | None) -> str | None:
|
63
|
-
return rid and rid.rsplit(".")[-1]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{agi_med_common-5.2.2 → agi_med_common-5.2.4}/src/agi_med_common.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|