gladier-tools 0.4.2__tar.gz → 0.4.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.
- {gladier-tools-0.4.2/gladier_tools.egg-info → gladier-tools-0.4.4}/PKG-INFO +1 -1
- gladier-tools-0.4.4/gladier_tools/experimental/__init__.py +25 -0
- gladier-tools-0.4.4/gladier_tools/experimental/base.py +109 -0
- gladier-tools-0.4.4/gladier_tools/experimental/globus/__init__.py +8 -0
- gladier-tools-0.4.4/gladier_tools/experimental/globus/mkdir.py +42 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/globus/__init__.py +1 -1
- gladier-tools-0.4.4/gladier_tools/posix/__init__.py +19 -0
- gladier-tools-0.4.4/gladier_tools/publish/__init__.py +4 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/publish/publish.py +3 -5
- gladier-tools-0.4.4/gladier_tools/publish/publishv2.py +418 -0
- gladier-tools-0.4.4/gladier_tools/tests/publish/test_publishv2.py +266 -0
- gladier-tools-0.4.4/gladier_tools/version.py +1 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4/gladier_tools.egg-info}/PKG-INFO +1 -1
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools.egg-info/SOURCES.txt +7 -1
- gladier-tools-0.4.2/gladier_tools/posix/__init__.py +0 -14
- gladier-tools-0.4.2/gladier_tools/publish/__init__.py +0 -3
- gladier-tools-0.4.2/gladier_tools/version.py +0 -1
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/LICENSE +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/MANIFEST.in +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/README.rst +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/__init__.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/globus/transfer.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/asymmetric_decrypt.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/asymmetric_encrypt.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/decrypt.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/encrypt.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/https_download_file.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/shell_cmd.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/tar.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/posix/untar.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/__init__.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/__init__.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/conftest.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/test_decrypt.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/test_encrypt.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/test_gladier_tools.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/test_shell_cmd.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/test_tar.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/posix/test_untar.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/publish/__init__.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools/tests/publish/test_publish.py +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools.egg-info/dependency_links.txt +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools.egg-info/requires.txt +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/gladier_tools.egg-info/top_level.txt +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/requirements.txt +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/setup.cfg +0 -0
- {gladier-tools-0.4.2 → gladier-tools-0.4.4}/setup.py +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing as t
|
|
4
|
+
|
|
5
|
+
from .base import (
|
|
6
|
+
GladierExperimentalBaseActionTool,
|
|
7
|
+
GladierExperimentalBaseTool,
|
|
8
|
+
JSONList,
|
|
9
|
+
JSONObject,
|
|
10
|
+
JSONValue,
|
|
11
|
+
get_action_param_name,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
_nameables = (
|
|
15
|
+
x.__name__
|
|
16
|
+
for x in (
|
|
17
|
+
GladierExperimentalBaseTool,
|
|
18
|
+
GladierExperimentalBaseActionTool,
|
|
19
|
+
get_action_param_name,
|
|
20
|
+
)
|
|
21
|
+
if hasattr(x, "__name__")
|
|
22
|
+
)
|
|
23
|
+
_unnameables: t.List[str] = ["JSONObject", "JSONList", "JSONValue"]
|
|
24
|
+
|
|
25
|
+
__all__ = tuple(_nameables) + tuple(_unnameables)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing as t
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
|
|
6
|
+
from gladier import GladierBaseTool
|
|
7
|
+
from typing_extensions import TypeAlias
|
|
8
|
+
|
|
9
|
+
JSONObject: TypeAlias = t.Dict[str, "JSONValue"]
|
|
10
|
+
JSONList: TypeAlias = t.List["JSONValue"]
|
|
11
|
+
JSONValue: TypeAlias = t.Union[JSONObject, JSONList, str, int, float, bool, None]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_action_param_name(param_name: str, param_val: str | int | bool | dict) -> str:
|
|
15
|
+
if isinstance(param_val, str) and param_val.startswith("$."):
|
|
16
|
+
return param_name + ".$"
|
|
17
|
+
else:
|
|
18
|
+
return param_name
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class GladierExperimentalBaseTool(GladierBaseTool, ABC):
|
|
22
|
+
def __init__(
|
|
23
|
+
self, state_name: str | None = None, state_comment: str | None = None, **kwargs
|
|
24
|
+
):
|
|
25
|
+
if state_name is None:
|
|
26
|
+
state_name = str(type(self))
|
|
27
|
+
self.state_name = state_name
|
|
28
|
+
if state_comment is None:
|
|
29
|
+
state_comment = f"State named {state_name}"
|
|
30
|
+
self.state_comment = state_comment
|
|
31
|
+
super().__init__(**kwargs)
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def set_flow_definition(self) -> JSONObject:
|
|
35
|
+
if self.flow_definition is not None:
|
|
36
|
+
return self.flow_definition
|
|
37
|
+
self.flow_definition: JSONObject = {
|
|
38
|
+
"Comment": self.state_comment,
|
|
39
|
+
"StartAt": self.state_name,
|
|
40
|
+
"States": {
|
|
41
|
+
self.state_name: {
|
|
42
|
+
"Comment": self.state_comment,
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
return self.flow_definition
|
|
47
|
+
|
|
48
|
+
def get_dict_for_flow_state(self) -> JSONObject:
|
|
49
|
+
flow_def = GladierExperimentalBaseTool.set_flow_definition(self)
|
|
50
|
+
flow_states: JSONObject = flow_def.get("States", {})
|
|
51
|
+
return flow_states[self.state_name]
|
|
52
|
+
|
|
53
|
+
def get_flow_definition(self) -> JSONObject:
|
|
54
|
+
return self.set_flow_definition()
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def required_input(self) -> list[str]:
|
|
58
|
+
"""
|
|
59
|
+
Attempt to scrape required input from the properties of the self
|
|
60
|
+
object. If a value starts with the JSONPath prefix '$.input.' we assume
|
|
61
|
+
it is intended to be one of the required inputs to this state.
|
|
62
|
+
"""
|
|
63
|
+
return_list: list[str] = []
|
|
64
|
+
required_input_prefix = "$.input."
|
|
65
|
+
for prop_val in vars(self).values():
|
|
66
|
+
if isinstance(prop_val, str) and prop_val.startswith(required_input_prefix):
|
|
67
|
+
return_list.append(prop_val[len(required_input_prefix) :])
|
|
68
|
+
return return_list
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class GladierExperimentalBaseActionTool(GladierExperimentalBaseTool, ABC):
|
|
72
|
+
def __init__(
|
|
73
|
+
self,
|
|
74
|
+
action_url: str,
|
|
75
|
+
action_scope: str | None = None,
|
|
76
|
+
wait_time: int = 600,
|
|
77
|
+
result_path: str | None = None,
|
|
78
|
+
**kwargs,
|
|
79
|
+
):
|
|
80
|
+
super().__init__(**kwargs)
|
|
81
|
+
self.action_url = action_url
|
|
82
|
+
self.action_scope = action_scope
|
|
83
|
+
self.wait_time = wait_time
|
|
84
|
+
if result_path is None:
|
|
85
|
+
result_path = f"$.{self.state_name}Result"
|
|
86
|
+
if not result_path.startswith("$."):
|
|
87
|
+
result_path = "$." + result_path
|
|
88
|
+
self.result_path = result_path
|
|
89
|
+
self.parameters: JSONObject | None = None
|
|
90
|
+
self.input_path: str | None = None
|
|
91
|
+
|
|
92
|
+
def set_flow_definition(self) -> JSONObject:
|
|
93
|
+
flow_state = self.get_dict_for_flow_state()
|
|
94
|
+
flow_state.update(
|
|
95
|
+
{
|
|
96
|
+
"Type": "Action",
|
|
97
|
+
"ActionUrl": self.action_url,
|
|
98
|
+
"ResultPath": self.result_path,
|
|
99
|
+
"WaitTime": self.wait_time,
|
|
100
|
+
"End": True,
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
if self.action_scope is not None:
|
|
104
|
+
flow_state["ActionScope"] = self.action_scope
|
|
105
|
+
if self.required_input is not None:
|
|
106
|
+
flow_state["InputPath"] = self.input_path
|
|
107
|
+
if self.parameters is not None:
|
|
108
|
+
flow_state["Parameters"] = self.parameters
|
|
109
|
+
return self.flow_definition
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from gladier_tools.experimental import (
|
|
4
|
+
GladierExperimentalBaseActionTool,
|
|
5
|
+
get_action_param_name,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GlobusMkDir(GladierExperimentalBaseActionTool):
|
|
10
|
+
"""
|
|
11
|
+
GlobusMkDir provides a state for using the Make Directory capability of Globus
|
|
12
|
+
Transfer to create a directory/folder on a specified Globus Endpoint.
|
|
13
|
+
|
|
14
|
+
:param endpoint_id: Globus Endpoint UUID
|
|
15
|
+
:param path: Path of the directory to create. Containing directory must exist.
|
|
16
|
+
:param state_name: The name of the state within the generated Flow.
|
|
17
|
+
:param result_path: Location in a run's state to store results of this state.
|
|
18
|
+
:param wait_time: Time, in seconds, to wait for this step to complete during a run.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
state_name="MkDir",
|
|
24
|
+
result_path: str | None = None,
|
|
25
|
+
wait_time=600,
|
|
26
|
+
endpoint_id="$.input.mkdir_endpoint_id",
|
|
27
|
+
path="$.input.mkdir_path",
|
|
28
|
+
**kwargs,
|
|
29
|
+
):
|
|
30
|
+
super().__init__(
|
|
31
|
+
state_name=state_name,
|
|
32
|
+
action_url="https://actions.globus.org/transfer/mkdir",
|
|
33
|
+
result_path=result_path,
|
|
34
|
+
wait_time=wait_time,
|
|
35
|
+
**kwargs,
|
|
36
|
+
)
|
|
37
|
+
self.parameters = {
|
|
38
|
+
get_action_param_name("endpoint_id", endpoint_id): endpoint_id,
|
|
39
|
+
get_action_param_name("path", path): path,
|
|
40
|
+
}
|
|
41
|
+
self.endpoint_id = endpoint_id
|
|
42
|
+
self.path = path
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .asymmetric_decrypt import AsymmetricDecrypt
|
|
2
|
+
from .asymmetric_encrypt import AsymmetricEncrypt
|
|
3
|
+
from .decrypt import Decrypt
|
|
4
|
+
from .encrypt import Encrypt
|
|
5
|
+
from .https_download_file import HttpsDownloadFile
|
|
6
|
+
from .shell_cmd import ShellCmdTool
|
|
7
|
+
from .tar import Tar
|
|
8
|
+
from .untar import UnTar
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"UnTar",
|
|
12
|
+
"Tar",
|
|
13
|
+
"HttpsDownloadFile",
|
|
14
|
+
"Encrypt",
|
|
15
|
+
"Decrypt",
|
|
16
|
+
"AsymmetricDecrypt",
|
|
17
|
+
"AsymmetricEncrypt",
|
|
18
|
+
"ShellCmdTool",
|
|
19
|
+
]
|
|
@@ -116,9 +116,7 @@ class Publish(GladierBaseTool):
|
|
|
116
116
|
'PublishGatherMetadata': {
|
|
117
117
|
'Comment': 'Say something to start the conversation',
|
|
118
118
|
'Type': 'Action',
|
|
119
|
-
'ActionUrl': 'https://
|
|
120
|
-
'ActionScope': 'https://auth.globus.org/scopes/'
|
|
121
|
-
'b3db7e59-a6f1-4947-95c2-59d6b7a70f8c/action_all',
|
|
119
|
+
'ActionUrl': 'https://compute2.dev.funcx.org/fxap',
|
|
122
120
|
'ExceptionOnActionFailure': False,
|
|
123
121
|
'Parameters': {
|
|
124
122
|
'tasks': [{
|
|
@@ -135,7 +133,7 @@ class Publish(GladierBaseTool):
|
|
|
135
133
|
'Comment': 'Transfer files for publication',
|
|
136
134
|
'Type': 'Action',
|
|
137
135
|
'ActionUrl': 'https://actions.automate.globus.org/transfer/transfer',
|
|
138
|
-
'InputPath': '$.PublishGatherMetadata.details.
|
|
136
|
+
'InputPath': '$.PublishGatherMetadata.details.results[0].output.transfer',
|
|
139
137
|
'ResultPath': '$.PublishTransfer',
|
|
140
138
|
'WaitTime': 600,
|
|
141
139
|
'Next': 'PublishIngest',
|
|
@@ -145,7 +143,7 @@ class Publish(GladierBaseTool):
|
|
|
145
143
|
'Type': 'Action',
|
|
146
144
|
'ActionUrl': 'https://actions.globus.org/search/ingest',
|
|
147
145
|
'ExceptionOnActionFailure': False,
|
|
148
|
-
'InputPath': '$.PublishGatherMetadata.details.
|
|
146
|
+
'InputPath': '$.PublishGatherMetadata.details.results[0].output.search',
|
|
149
147
|
'ResultPath': '$.PublishIngest',
|
|
150
148
|
'WaitTime': 300,
|
|
151
149
|
'End': True
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
from gladier import GladierBaseTool
|
|
2
|
+
from typing import Tuple, List, Mapping
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def publishv2_gather_metadata(
|
|
6
|
+
dataset: str,
|
|
7
|
+
destination: str,
|
|
8
|
+
source_collection: str,
|
|
9
|
+
destination_collection: str,
|
|
10
|
+
index: str,
|
|
11
|
+
visible_to: List[str],
|
|
12
|
+
entry_id: str = "metadata",
|
|
13
|
+
metadata: Mapping = None,
|
|
14
|
+
source_collection_basepath: str = None,
|
|
15
|
+
destination_url_hostname: str = None,
|
|
16
|
+
checksum_algorithms: Tuple[str] = ("sha256", "sha512"),
|
|
17
|
+
metadata_dc_validation_schema: str = None,
|
|
18
|
+
enable_publish: bool = True,
|
|
19
|
+
enable_transfer: bool = True,
|
|
20
|
+
enable_meta_dc: bool = True,
|
|
21
|
+
enable_meta_files: bool = True,
|
|
22
|
+
**data,
|
|
23
|
+
):
|
|
24
|
+
import hashlib
|
|
25
|
+
import urllib
|
|
26
|
+
import pathlib
|
|
27
|
+
import datetime
|
|
28
|
+
import mimetypes
|
|
29
|
+
import traceback
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
import puremagic
|
|
33
|
+
except ImportError:
|
|
34
|
+
puremagic = None
|
|
35
|
+
|
|
36
|
+
def translate_guest_collection_path(collection_basepath, path):
|
|
37
|
+
if not collection_basepath:
|
|
38
|
+
return str(path)
|
|
39
|
+
try:
|
|
40
|
+
return f"/{str(pathlib.PosixPath(path).relative_to(collection_basepath))}"
|
|
41
|
+
except ValueError:
|
|
42
|
+
raise ValueError(
|
|
43
|
+
f'POSIX path given "{path}" outside Gloubus Collection '
|
|
44
|
+
f"share path: {collection_basepath}"
|
|
45
|
+
) from None
|
|
46
|
+
|
|
47
|
+
def get_mimetype(filename):
|
|
48
|
+
"""
|
|
49
|
+
Attempt to determine the mimetype of a file with a few different approaches, from
|
|
50
|
+
top to bottom in this list:
|
|
51
|
+
1. Try puremagic if it is installed
|
|
52
|
+
2. Use the built in mimetypes lib
|
|
53
|
+
3. Check for text vs binary by reading a chunk of data
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def detect_mimetype(filename):
|
|
57
|
+
if puremagic is not None:
|
|
58
|
+
try:
|
|
59
|
+
return puremagic.magic_file(str(filename))[0].mime_type
|
|
60
|
+
except (IndexError, ValueError):
|
|
61
|
+
"""Skip puremagic on IndexError (No mimetype could be found) or on ValueError
|
|
62
|
+
(file was empty)."""
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
mt, _ = mimetypes.guess_type(filename, strict=True)
|
|
66
|
+
return mt
|
|
67
|
+
|
|
68
|
+
def detect_text_or_binary(filename):
|
|
69
|
+
"""Read the first 1024 and attempt to decode it in utf-8. If this succeeds,
|
|
70
|
+
the file is determined to be text. If not, its binary.
|
|
71
|
+
|
|
72
|
+
There are better ways to do this, but this should be 'good enough' for most
|
|
73
|
+
use-cases we have.
|
|
74
|
+
"""
|
|
75
|
+
with open(filename, "rb") as f:
|
|
76
|
+
chunk = f.read(1024)
|
|
77
|
+
try:
|
|
78
|
+
chunk.decode("utf-8")
|
|
79
|
+
return "text/plain"
|
|
80
|
+
except UnicodeDecodeError:
|
|
81
|
+
return "application/octet-stream"
|
|
82
|
+
|
|
83
|
+
for func in (detect_mimetype, detect_text_or_binary):
|
|
84
|
+
mimetype = func(filename)
|
|
85
|
+
if mimetype:
|
|
86
|
+
return mimetype
|
|
87
|
+
|
|
88
|
+
def get_remote_file_manifest(filepath, destination_path, url_host, algorithms):
|
|
89
|
+
dataset = pathlib.Path(filepath)
|
|
90
|
+
destination = pathlib.Path(destination_path)
|
|
91
|
+
if not dataset.exists():
|
|
92
|
+
raise ValueError(f"File does not exist: {filepath}")
|
|
93
|
+
|
|
94
|
+
file_list = [dataset] if dataset.is_file() else list(dataset.iterdir())
|
|
95
|
+
file_list = [
|
|
96
|
+
(
|
|
97
|
+
local_abspath,
|
|
98
|
+
destination
|
|
99
|
+
/ str(local_abspath.relative_to(dataset.parent)).lstrip("/"),
|
|
100
|
+
)
|
|
101
|
+
for local_abspath in file_list
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
manifest_entries = []
|
|
105
|
+
for subfile, remote_short_path in file_list:
|
|
106
|
+
rfm = {alg: compute_checksum(subfile, alg) for alg in algorithms}
|
|
107
|
+
# mimetype = analysis.mimetypes.detect_type(subfile)
|
|
108
|
+
rfm.update(
|
|
109
|
+
{
|
|
110
|
+
"filename": subfile.name,
|
|
111
|
+
"url": urllib.parse.urlunsplit(
|
|
112
|
+
(
|
|
113
|
+
"globus",
|
|
114
|
+
destination_collection,
|
|
115
|
+
str(remote_short_path),
|
|
116
|
+
"",
|
|
117
|
+
"",
|
|
118
|
+
)
|
|
119
|
+
),
|
|
120
|
+
"mime_type": get_mimetype(subfile),
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
if url_host:
|
|
124
|
+
url_host_p = urllib.parse.urlparse(url_host)
|
|
125
|
+
if not url_host_p.scheme or not url_host_p.netloc:
|
|
126
|
+
raise ValueError(
|
|
127
|
+
f"destination_url_hostname {url_host} must be of format: https://example.com"
|
|
128
|
+
)
|
|
129
|
+
rfm["https_url"] = urllib.parse.urlunsplit(
|
|
130
|
+
(
|
|
131
|
+
url_host_p.scheme,
|
|
132
|
+
url_host_p.hostname,
|
|
133
|
+
str(remote_short_path),
|
|
134
|
+
"",
|
|
135
|
+
"",
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
if subfile.exists():
|
|
140
|
+
rfm["length"] = subfile.stat().st_size
|
|
141
|
+
manifest_entries.append(rfm)
|
|
142
|
+
return manifest_entries
|
|
143
|
+
|
|
144
|
+
def compute_checksum(file_path, algorithm, block_size=65536):
|
|
145
|
+
alg = getattr(hashlib, algorithm, None)
|
|
146
|
+
if not alg:
|
|
147
|
+
raise ValueError(f"Algorithm {algorithm} is not available in hashlib!")
|
|
148
|
+
alg_instance = alg()
|
|
149
|
+
with open(file_path, "rb") as open_file:
|
|
150
|
+
buf = open_file.read(block_size)
|
|
151
|
+
while len(buf) > 0:
|
|
152
|
+
alg_instance.update(buf)
|
|
153
|
+
buf = open_file.read(block_size)
|
|
154
|
+
return alg_instance.hexdigest()
|
|
155
|
+
|
|
156
|
+
def get_dc(title, subject: str, files: list = None):
|
|
157
|
+
dt = datetime.datetime.now()
|
|
158
|
+
return {
|
|
159
|
+
"identifiers": [
|
|
160
|
+
{
|
|
161
|
+
"identifierType": "GlobusSearchSubject",
|
|
162
|
+
"identifier": subject,
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"creators": [{"name": ""}],
|
|
166
|
+
"dates": [{"date": f"{dt.isoformat()}Z", "dateType": "Created"}],
|
|
167
|
+
"formats": list({f["mime_type"] for f in files}),
|
|
168
|
+
"publicationYear": str(dt.year),
|
|
169
|
+
"publisher": "",
|
|
170
|
+
"types": {"resourceType": "Dataset", "resourceTypeGeneral": "Dataset"},
|
|
171
|
+
"subjects": [],
|
|
172
|
+
"titles": [{"title": dataset.name}],
|
|
173
|
+
"version": "1",
|
|
174
|
+
"schemaVersion": "http://datacite.org/schema/kernel-4",
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
def get_content(title, subject, metadata):
|
|
178
|
+
new_metadata = {}
|
|
179
|
+
if enable_meta_files:
|
|
180
|
+
new_metadata["files"] = get_remote_file_manifest(
|
|
181
|
+
dataset, destination, destination_url_hostname, checksum_algorithms
|
|
182
|
+
)
|
|
183
|
+
if enable_meta_dc:
|
|
184
|
+
new_metadata["dc"] = get_dc(title, subject, new_metadata.get("files", []))
|
|
185
|
+
if metadata and "dc" in metadata:
|
|
186
|
+
new_metadata["dc"].update(metadata.pop("dc"))
|
|
187
|
+
new_metadata.update(metadata if metadata is not None else {})
|
|
188
|
+
if metadata_dc_validation_schema:
|
|
189
|
+
import datacite
|
|
190
|
+
import jsonschema
|
|
191
|
+
|
|
192
|
+
try:
|
|
193
|
+
# Secondary import required due to these not being exposed as public items, even
|
|
194
|
+
# though the docs recommend using them as such. Explicit imports add them to the
|
|
195
|
+
# module listing so getattr() will work properly to choose the correct one.
|
|
196
|
+
from datacite import schema40, schema41, schema42, schema43
|
|
197
|
+
|
|
198
|
+
schema = getattr(datacite, metadata_dc_validation_schema)
|
|
199
|
+
schema.validator.validate(new_metadata["dc"])
|
|
200
|
+
except jsonschema.exceptions.ValidationError:
|
|
201
|
+
raise ValueError(traceback.format_exc()) from None
|
|
202
|
+
return new_metadata
|
|
203
|
+
|
|
204
|
+
dataset = pathlib.Path(dataset)
|
|
205
|
+
destination_path = pathlib.Path(destination) / dataset.name
|
|
206
|
+
subject = urllib.parse.urlunparse(
|
|
207
|
+
("globus", destination_collection, str(destination_path), "", "", "")
|
|
208
|
+
)
|
|
209
|
+
return {
|
|
210
|
+
"search": {
|
|
211
|
+
"id": entry_id,
|
|
212
|
+
"content": get_content(dataset.name, subject, metadata),
|
|
213
|
+
"subject": subject,
|
|
214
|
+
"visible_to": visible_to,
|
|
215
|
+
"search_index": index,
|
|
216
|
+
},
|
|
217
|
+
"transfer": {
|
|
218
|
+
"source_endpoint_id": source_collection,
|
|
219
|
+
"destination_endpoint_id": destination_collection,
|
|
220
|
+
"transfer_items": [
|
|
221
|
+
{
|
|
222
|
+
"source_path": translate_guest_collection_path(
|
|
223
|
+
source_collection_basepath, dataset
|
|
224
|
+
),
|
|
225
|
+
"destination_path": str(destination_path),
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class Publishv2(GladierBaseTool):
|
|
233
|
+
"""Publish tooling is an extension to the original publish gladier tool, and allows
|
|
234
|
+
for similar style publication of files and folders without the globus-pilot requirement.
|
|
235
|
+
|
|
236
|
+
Publishv2 allows for specifying a file or folder on a Globus Collection, and "publishing" the
|
|
237
|
+
data. Publication consists of first gathering metadata on the file or folder, cataloguing the
|
|
238
|
+
metadata with Globus Search, and transferring the file or folder to a Globus Collection. Additional
|
|
239
|
+
metadata may be provided for the ingest step, and several options exist for modifying what
|
|
240
|
+
metadata is automatically gathered.
|
|
241
|
+
|
|
242
|
+
Dependencies:
|
|
243
|
+
|
|
244
|
+
* None!
|
|
245
|
+
|
|
246
|
+
Optional Dependencies:
|
|
247
|
+
|
|
248
|
+
* puremagic -- Better mimetype detection
|
|
249
|
+
* datacite -- Validation of Datacite (dc) metadata
|
|
250
|
+
|
|
251
|
+
FuncX Functions:
|
|
252
|
+
|
|
253
|
+
Publishv2 uses one function called 'publishv2_gather_metadata'. For using custom generated metadata from another
|
|
254
|
+
function, it can be handy to generate the entire 'publishv2_gather_metadata' input block and pass it as flow input
|
|
255
|
+
instead, which can be done via the following:
|
|
256
|
+
|
|
257
|
+
.. code-block::
|
|
258
|
+
|
|
259
|
+
@generate_flow_definition(modifiers={
|
|
260
|
+
'publishv2_gather_metadata': {'payload': '$.MyCustomPayload.details.results[0].output'},
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
This tool nests input under the 'publishv2' keyword. An example is below:
|
|
264
|
+
|
|
265
|
+
.. code-block::
|
|
266
|
+
|
|
267
|
+
'publishv2': {
|
|
268
|
+
'dataset': 'foo.txt',
|
|
269
|
+
'destination': '/~/my-test-dir',
|
|
270
|
+
'source_collection': 'my-source-globus-collection',
|
|
271
|
+
'destination_collection': 'my-destination-globus-collection',
|
|
272
|
+
'index': 'my-globus-search-index-uuid',
|
|
273
|
+
'visible_to': ['public'],
|
|
274
|
+
# Ingest and Transfer are disabled by default, allowing for 'dry-run' testing.
|
|
275
|
+
# 'ingest_enabled': True,
|
|
276
|
+
# 'transfer_enabled': True,
|
|
277
|
+
},
|
|
278
|
+
'funcx_endpoint_non_compute': '4b116d3c-1703-4f8f-9f6f-39921e5864df',
|
|
279
|
+
|
|
280
|
+
:param dataset: Path to file or directory, which will be catalogued in Globus Search and transferred
|
|
281
|
+
to the remote destination
|
|
282
|
+
:param destination: Location on destination collection where data should be stored
|
|
283
|
+
:param source_collection: The source Globus Collection where data is stored
|
|
284
|
+
:param destination_collection: The destination Collection to transfer the ``dataset``
|
|
285
|
+
:param index: The index to ingest this dataset in Globus Search
|
|
286
|
+
:param visible_to: (list[str] Default: ['public']) A list of URN user or group identities for controlling
|
|
287
|
+
access.
|
|
288
|
+
:param entry_id: (str Default:'metadata') The entry id to use in the Globus Search record
|
|
289
|
+
:param metadata: (dict) Extra metadata to include in this search record
|
|
290
|
+
:param source_collection_basepath: Share path if this is a Guest Collection, so that the proper
|
|
291
|
+
source path can be constructed for the transfer document
|
|
292
|
+
:param destination_url_hostname: Adds "https_url" to each file in the 'files' document using this
|
|
293
|
+
provided hostname
|
|
294
|
+
:param checksum_algorithms: (tuple Default:('sha256', 'sha512')) Checksums to use for file metadata
|
|
295
|
+
:param metadata_dc_validation_schema: (str) Schema used to validate datacite (dc) metadata. Possible values
|
|
296
|
+
are (schema40, schema41, schema42, schema43). Recommended schema43. Requires datacite
|
|
297
|
+
package installed on funcx endpoint.
|
|
298
|
+
:param enable_publish: (bool Default: True) Enable the ingest step on the flow. If false, ingest will be
|
|
299
|
+
skipped.
|
|
300
|
+
:param enable_transfer: (bool Default: True) Enable Transfer on the flow. If False, data will not be transferred
|
|
301
|
+
to the remote collection.
|
|
302
|
+
:param enable_meta_dc: (bool Default: True) Generate datacite metadata during the 'gathering' funcx function step.
|
|
303
|
+
datacite metadata is stored under the 'dc' key, and can be valiated using metadata_dc_validation_schema=schema43.
|
|
304
|
+
If additional fields are provided via the ``metadata`` parameter, it will override overlapping fields.
|
|
305
|
+
:param enable_meta_files: (bool Default: True) Generate metadata on all files contained within the dataset. Files
|
|
306
|
+
conforms to BDBag Remote File Manifests, generating a list of entries for each file with keys:
|
|
307
|
+
('url', 'sha256', 'sha512', 'filename', 'length'). Files may also contain extended keys ('mime_type', 'https_url')
|
|
308
|
+
:param funcx_endpoint_non_compute: A funcX endpoint uuid for gathering metadata.
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
flow_definition = {
|
|
312
|
+
"Comment": "Publish metadata to Globus Search, with data from the result.",
|
|
313
|
+
"StartAt": "Publishv2GatherMetadata",
|
|
314
|
+
"States": {
|
|
315
|
+
"Publishv2GatherMetadata": {
|
|
316
|
+
"Comment": "Generate search metadata and a transfer document",
|
|
317
|
+
"Type": "Action",
|
|
318
|
+
"ActionUrl": "https://compute2.dev.funcx.org/fxap",
|
|
319
|
+
"ExceptionOnActionFailure": True,
|
|
320
|
+
"Parameters": {
|
|
321
|
+
"tasks": [
|
|
322
|
+
{
|
|
323
|
+
"endpoint.$": "$.input.funcx_endpoint_non_compute",
|
|
324
|
+
"function.$": "$.input.publishv2_gather_metadata_funcx_id",
|
|
325
|
+
"payload.$": "$.input.publishv2",
|
|
326
|
+
}
|
|
327
|
+
]
|
|
328
|
+
},
|
|
329
|
+
"ResultPath": "$.Publishv2GatherMetadata",
|
|
330
|
+
"WaitTime": 600,
|
|
331
|
+
"Next": "Publishv2ChoiceTransfer",
|
|
332
|
+
},
|
|
333
|
+
"Publishv2ChoiceTransfer": {
|
|
334
|
+
"Comment": "Determine if the document should be cataloged in Globus Search",
|
|
335
|
+
"Type": "Choice",
|
|
336
|
+
"Choices": [
|
|
337
|
+
{
|
|
338
|
+
"And": [
|
|
339
|
+
{
|
|
340
|
+
"Variable": "$.input.publishv2.transfer_enabled",
|
|
341
|
+
"IsPresent": True,
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"Variable": "$.input.publishv2.transfer_enabled",
|
|
345
|
+
"BooleanEquals": True,
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
"Next": "Publishv2Transfer",
|
|
349
|
+
}
|
|
350
|
+
],
|
|
351
|
+
"Default": "Publishv2SkipTransfer",
|
|
352
|
+
},
|
|
353
|
+
"Publishv2Transfer": {
|
|
354
|
+
"Comment": "Transfer files for publication",
|
|
355
|
+
"Type": "Action",
|
|
356
|
+
"ActionUrl": "https://actions.automate.globus.org/transfer/transfer",
|
|
357
|
+
"InputPath": "$.Publishv2GatherMetadata.details.results[0].output.transfer",
|
|
358
|
+
"ResultPath": "$.Publishv2Transfer",
|
|
359
|
+
"WaitTime": 600,
|
|
360
|
+
"Next": "Publishv2ChoiceIngest",
|
|
361
|
+
},
|
|
362
|
+
"Publishv2SkipTransfer": {
|
|
363
|
+
"Comment": "The ingest step has been skipped",
|
|
364
|
+
"Type": "Pass",
|
|
365
|
+
"Next": "Publishv2ChoiceIngest",
|
|
366
|
+
},
|
|
367
|
+
"Publishv2ChoiceIngest": {
|
|
368
|
+
"Comment": "Determine if the document should be cataloged in Globus Search",
|
|
369
|
+
"Type": "Choice",
|
|
370
|
+
"Choices": [
|
|
371
|
+
{
|
|
372
|
+
"And": [
|
|
373
|
+
{
|
|
374
|
+
"Variable": "$.input.publishv2.ingest_enabled",
|
|
375
|
+
"IsPresent": True,
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
"Variable": "$.input.publishv2.ingest_enabled",
|
|
379
|
+
"BooleanEquals": True,
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
"Next": "Publishv2Ingest",
|
|
383
|
+
}
|
|
384
|
+
],
|
|
385
|
+
"Default": "Publishv2SkipIngest",
|
|
386
|
+
},
|
|
387
|
+
"Publishv2Ingest": {
|
|
388
|
+
"Comment": "Ingest the search document",
|
|
389
|
+
"Type": "Action",
|
|
390
|
+
"ActionUrl": "https://actions.globus.org/search/ingest",
|
|
391
|
+
"InputPath": "$.Publishv2GatherMetadata.details.results[0].output.search",
|
|
392
|
+
"ResultPath": "$.Publishv2Ingest",
|
|
393
|
+
"WaitTime": 300,
|
|
394
|
+
"Next": "Publishv2Done",
|
|
395
|
+
},
|
|
396
|
+
"Publishv2SkipIngest": {
|
|
397
|
+
"Comment": "The ingest step has been skipped",
|
|
398
|
+
"Type": "Pass",
|
|
399
|
+
"Next": "Publishv2Done",
|
|
400
|
+
},
|
|
401
|
+
"Publishv2Done": {
|
|
402
|
+
"Comment": "The Publication tool has completed successfully.",
|
|
403
|
+
"Type": "Pass",
|
|
404
|
+
"End": True,
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
required_input = [
|
|
410
|
+
"publishv2",
|
|
411
|
+
"funcx_endpoint_non_compute",
|
|
412
|
+
]
|
|
413
|
+
|
|
414
|
+
flow_input = {}
|
|
415
|
+
|
|
416
|
+
funcx_functions = [
|
|
417
|
+
publishv2_gather_metadata,
|
|
418
|
+
]
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pathlib
|
|
3
|
+
import json
|
|
4
|
+
from datacite import schema42, schema43
|
|
5
|
+
from gladier_tools.publish.publishv2 import publishv2_gather_metadata
|
|
6
|
+
|
|
7
|
+
mock_data = pathlib.Path(__file__).resolve().parent.parent / "mock_data/publish/"
|
|
8
|
+
|
|
9
|
+
minimum_dc_metadata = {
|
|
10
|
+
"creators": [{"name": ""}],
|
|
11
|
+
"identifiers": [
|
|
12
|
+
{
|
|
13
|
+
"identifier": "globus://my_globus_collection/my-new-project/test_dataset_folder",
|
|
14
|
+
"identifierType": "GlobusSearchSubject",
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"dates": [{"date": "2023-03-16T07:44:14.044091", "dateType": "Created"}],
|
|
18
|
+
"formats": ["text/plain"],
|
|
19
|
+
"publicationYear": "2023",
|
|
20
|
+
"publisher": "",
|
|
21
|
+
"types": {"resourceType": "Dataset", "resourceTypeGeneral": "Dataset"},
|
|
22
|
+
"subjects": [],
|
|
23
|
+
"titles": [{"title": "test_dataset_folder"}],
|
|
24
|
+
"version": "1",
|
|
25
|
+
"schemaVersion": "http://datacite.org/schema/kernel-4",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture
|
|
30
|
+
def publish_input():
|
|
31
|
+
return {
|
|
32
|
+
"dataset": mock_data / "test_dataset_folder",
|
|
33
|
+
"destination": "/my-new-project",
|
|
34
|
+
"source_collection": "my_transfer_endpoint",
|
|
35
|
+
"destination_collection": "my_globus_collection",
|
|
36
|
+
"destination_collection_basepath": "/my-new-project/",
|
|
37
|
+
"index": "my_index",
|
|
38
|
+
"visible_to": ["public"],
|
|
39
|
+
"enable_metadata_dc": True,
|
|
40
|
+
"groups": [],
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_publish(publish_input):
|
|
45
|
+
publishv2_gather_metadata(**publish_input).keys() == ("search", "transfer")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_json_serializable(publish_input):
|
|
49
|
+
assert json.dumps(publishv2_gather_metadata(**publish_input))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_publish_dc(publish_input):
|
|
53
|
+
output = publishv2_gather_metadata(**publish_input)
|
|
54
|
+
content = output["search"]["content"]
|
|
55
|
+
assert "dc" in content
|
|
56
|
+
partial_dc = content["dc"].copy()
|
|
57
|
+
partial_dc.pop("dates")
|
|
58
|
+
assert partial_dc == {
|
|
59
|
+
"creators": [{"name": ""}],
|
|
60
|
+
"identifiers": [
|
|
61
|
+
{
|
|
62
|
+
"identifier": "globus://my_globus_collection/my-new-project/test_dataset_folder",
|
|
63
|
+
"identifierType": "GlobusSearchSubject",
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
# timestamp contains seconds, which is hard to check. Skip it!
|
|
67
|
+
# '2023-03-17T17:14:31.832955Z'
|
|
68
|
+
# 'dates': [{'date': '2023-03-16T07:44:14.044091', 'dateType': 'Created'}],
|
|
69
|
+
"formats": ["text/plain"],
|
|
70
|
+
"publicationYear": "2023",
|
|
71
|
+
"publisher": "",
|
|
72
|
+
"types": {"resourceType": "Dataset", "resourceTypeGeneral": "Dataset"},
|
|
73
|
+
"subjects": [],
|
|
74
|
+
"titles": [{"title": "test_dataset_folder"}],
|
|
75
|
+
"version": "1",
|
|
76
|
+
"schemaVersion": "http://datacite.org/schema/kernel-4",
|
|
77
|
+
}
|
|
78
|
+
assert "dates" in content["dc"]
|
|
79
|
+
assert content["dc"]["dates"][0]["dateType"] == "Created"
|
|
80
|
+
assert "date" in content["dc"]["dates"][0]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_validate_dc(publish_input):
|
|
84
|
+
dc = publishv2_gather_metadata(**publish_input)["search"]["content"]["dc"]
|
|
85
|
+
schema42.validator.validate(dc)
|
|
86
|
+
schema43.validator.validate(dc)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.mark.parametrize(
|
|
90
|
+
"schema,metadata",
|
|
91
|
+
[
|
|
92
|
+
(
|
|
93
|
+
"schema40",
|
|
94
|
+
{
|
|
95
|
+
"identifier": {
|
|
96
|
+
"identifier": "https://doi.org/10.14454/3w3z-sa82",
|
|
97
|
+
"identifierType": "DOI",
|
|
98
|
+
},
|
|
99
|
+
"creators": [{"creatorName": "foo"}],
|
|
100
|
+
"publicationYear": "2023",
|
|
101
|
+
"publisher": "FOO",
|
|
102
|
+
"resourceType": {
|
|
103
|
+
"resourceType": "Dataset",
|
|
104
|
+
"resourceTypeGeneral": "Dataset",
|
|
105
|
+
},
|
|
106
|
+
"titles": [{"title": "test_dataset_folder"}],
|
|
107
|
+
},
|
|
108
|
+
),
|
|
109
|
+
(
|
|
110
|
+
"schema41",
|
|
111
|
+
{
|
|
112
|
+
"identifier": {
|
|
113
|
+
"identifier": "https://doi.org/10.14454/3w3z-sa82",
|
|
114
|
+
"identifierType": "DOI",
|
|
115
|
+
},
|
|
116
|
+
"creators": [{"creatorName": "foo"}],
|
|
117
|
+
"publicationYear": "2023",
|
|
118
|
+
"publisher": "FOO",
|
|
119
|
+
"resourceType": {
|
|
120
|
+
"resourceType": "Dataset",
|
|
121
|
+
"resourceTypeGeneral": "Dataset",
|
|
122
|
+
},
|
|
123
|
+
"titles": [{"title": "test_dataset_folder"}],
|
|
124
|
+
},
|
|
125
|
+
),
|
|
126
|
+
("schema42", minimum_dc_metadata),
|
|
127
|
+
("schema43", minimum_dc_metadata),
|
|
128
|
+
],
|
|
129
|
+
)
|
|
130
|
+
def test_eval(schema, metadata, publish_input):
|
|
131
|
+
publish_input["metadata"] = {"dc": metadata}
|
|
132
|
+
publish_input["enable_meta_dc"] = False
|
|
133
|
+
publish_input["metadata_dc_validation_schema"] = schema
|
|
134
|
+
publishv2_gather_metadata(**publish_input)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_datacite_override(publish_input):
|
|
138
|
+
extra_input = {
|
|
139
|
+
"metadata": {"dc": {"creators": [{"name": "nick"}]}},
|
|
140
|
+
"metadata_dc_validation_schema": "schema43",
|
|
141
|
+
}
|
|
142
|
+
publish_input.update(extra_input)
|
|
143
|
+
output = publishv2_gather_metadata(**publish_input)["search"]["content"]["dc"]
|
|
144
|
+
assert output["creators"] == [{"name": "nick"}]
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def test_datacite_validator(publish_input):
|
|
148
|
+
extra_input = {
|
|
149
|
+
"metadata": {"dc": {"authors": ["invalid_bob"]}},
|
|
150
|
+
"metadata_dc_validation_schema": "schema43",
|
|
151
|
+
}
|
|
152
|
+
publish_input.update(extra_input)
|
|
153
|
+
with pytest.raises(ValueError):
|
|
154
|
+
publishv2_gather_metadata(**publish_input)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_publish_files(publish_input):
|
|
158
|
+
output = publishv2_gather_metadata(**publish_input)
|
|
159
|
+
files = output["search"]["content"]["files"]
|
|
160
|
+
files.sort(key=lambda x: x["filename"])
|
|
161
|
+
assert files == [
|
|
162
|
+
{
|
|
163
|
+
"sha256": "49606feb430b0ca35c4099c1e84fe81b5634039ecbeb408d76fa5e44f93c1d9a",
|
|
164
|
+
"sha512": "3a9db7ddff3f83902624832a74ba5559e83ef66cb471d14d79a2b89fa981f47b9a0f27ef83f4f266ee5ecf22f817fe58da6f4323c0eb5557fea9152fb4465e04",
|
|
165
|
+
"filename": "bar.txt",
|
|
166
|
+
"url": "globus://my_globus_collection/my-new-project/test_dataset_folder/bar.txt",
|
|
167
|
+
"mime_type": "text/plain",
|
|
168
|
+
"length": 16,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"sha256": "ef04ad1ddb694bcf461bef6668d387117c63d1648589d55413d4266dc0372dbd",
|
|
172
|
+
"sha512": "aa650e6a730cc73c6d967d9a5c3549dd1bdc94a0128c1ea1fcb9506b5e9c099583e979892af75e2930fb33a84c0c7eb2be5e3e508809f4269cba01ff22847a03",
|
|
173
|
+
"filename": "foo.txt",
|
|
174
|
+
"url": "globus://my_globus_collection/my-new-project/test_dataset_folder/foo.txt",
|
|
175
|
+
"mime_type": "text/plain",
|
|
176
|
+
"length": 16,
|
|
177
|
+
},
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_publish_mimetype_csv(publish_input):
|
|
182
|
+
publish_input["dataset"] = mock_data / "1951.csv"
|
|
183
|
+
files = publishv2_gather_metadata(**publish_input)["search"]["content"]["files"]
|
|
184
|
+
assert len(files) == 1
|
|
185
|
+
assert files[0]["mime_type"] == "text/csv"
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def test_publish_mimetype_tsv(publish_input):
|
|
189
|
+
publish_input["dataset"] = mock_data / "1951.tsv"
|
|
190
|
+
files = publishv2_gather_metadata(**publish_input)["search"]["content"]["files"]
|
|
191
|
+
assert len(files) == 1
|
|
192
|
+
assert files[0]["mime_type"] == "text/tab-separated-values"
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def test_publish_mimetype_bin(publish_input):
|
|
196
|
+
publish_input["dataset"] = mock_data / "random.dat"
|
|
197
|
+
files = publishv2_gather_metadata(**publish_input)["search"]["content"]["files"]
|
|
198
|
+
assert len(files) == 1
|
|
199
|
+
assert files[0]["mime_type"] == "application/octet-stream"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def test_publish_mimetype_bin(publish_input):
|
|
203
|
+
publish_input["dataset"] = mock_data / "test_file.txt"
|
|
204
|
+
files = publishv2_gather_metadata(**publish_input)["search"]["content"]["files"]
|
|
205
|
+
assert len(files) == 1
|
|
206
|
+
assert files[0]["mime_type"] == "text/plain"
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def test_https_url(publish_input):
|
|
210
|
+
publish_input["dataset"] = mock_data / "test_file.txt"
|
|
211
|
+
publish_input["destination_url_hostname"] = "https://example.com"
|
|
212
|
+
files = publishv2_gather_metadata(**publish_input)["search"]["content"]["files"]
|
|
213
|
+
assert len(files) == 1
|
|
214
|
+
assert files[0]["https_url"] == "https://example.com/my-new-project/test_file.txt"
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_https_invalid_dest_hostname(publish_input):
|
|
218
|
+
publish_input["dataset"] = mock_data / "test_file.txt"
|
|
219
|
+
publish_input["destination_url_hostname"] = "example.com"
|
|
220
|
+
with pytest.raises(ValueError):
|
|
221
|
+
publishv2_gather_metadata(**publish_input)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_invalid_checksums(publish_input):
|
|
225
|
+
publish_input["checksum_algorithms"] = ["md3"]
|
|
226
|
+
with pytest.raises(ValueError):
|
|
227
|
+
publishv2_gather_metadata(**publish_input)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_publish_transfer(publish_input):
|
|
231
|
+
output = publishv2_gather_metadata(**publish_input)
|
|
232
|
+
dataset = publish_input["dataset"]
|
|
233
|
+
assert output["transfer"] == {
|
|
234
|
+
"destination_endpoint_id": "my_globus_collection",
|
|
235
|
+
"source_endpoint_id": "my_transfer_endpoint",
|
|
236
|
+
"transfer_items": [
|
|
237
|
+
{
|
|
238
|
+
"destination_path": str(pathlib.Path("/my-new-project") / dataset.name),
|
|
239
|
+
"source_path": str(dataset),
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def test_publish_collection_valid_basepath(publish_input):
|
|
246
|
+
"""Test Guest Collection basepath where the share point is the parent of the source
|
|
247
|
+
dataset being published."""
|
|
248
|
+
publish_input["source_collection_basepath"] = publish_input["dataset"].parent
|
|
249
|
+
source_file = publishv2_gather_metadata(**publish_input)["transfer"]["transfer_items"][0]
|
|
250
|
+
assert source_file["source_path"] == f"/{publish_input['dataset'].name}"
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def test_publish_collection_source_basepath_mismatch(publish_input):
|
|
254
|
+
"""Test Guest Collection basepath where the share point is the parent of the source
|
|
255
|
+
dataset being published."""
|
|
256
|
+
publish_input["source_collection_basepath"] = (
|
|
257
|
+
publish_input["dataset"].parent / "foo"
|
|
258
|
+
)
|
|
259
|
+
with pytest.raises(ValueError):
|
|
260
|
+
publishv2_gather_metadata(**publish_input)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def test_non_existent_dataset(publish_input):
|
|
264
|
+
publish_input["dataset"] = "/does/not/exist"
|
|
265
|
+
with pytest.raises(ValueError):
|
|
266
|
+
publishv2_gather_metadata(**publish_input)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.4.4'
|
|
@@ -11,6 +11,10 @@ gladier_tools.egg-info/SOURCES.txt
|
|
|
11
11
|
gladier_tools.egg-info/dependency_links.txt
|
|
12
12
|
gladier_tools.egg-info/requires.txt
|
|
13
13
|
gladier_tools.egg-info/top_level.txt
|
|
14
|
+
gladier_tools/experimental/__init__.py
|
|
15
|
+
gladier_tools/experimental/base.py
|
|
16
|
+
gladier_tools/experimental/globus/__init__.py
|
|
17
|
+
gladier_tools/experimental/globus/mkdir.py
|
|
14
18
|
gladier_tools/globus/__init__.py
|
|
15
19
|
gladier_tools/globus/transfer.py
|
|
16
20
|
gladier_tools/posix/__init__.py
|
|
@@ -24,6 +28,7 @@ gladier_tools/posix/tar.py
|
|
|
24
28
|
gladier_tools/posix/untar.py
|
|
25
29
|
gladier_tools/publish/__init__.py
|
|
26
30
|
gladier_tools/publish/publish.py
|
|
31
|
+
gladier_tools/publish/publishv2.py
|
|
27
32
|
gladier_tools/tests/__init__.py
|
|
28
33
|
gladier_tools/tests/posix/__init__.py
|
|
29
34
|
gladier_tools/tests/posix/conftest.py
|
|
@@ -34,4 +39,5 @@ gladier_tools/tests/posix/test_shell_cmd.py
|
|
|
34
39
|
gladier_tools/tests/posix/test_tar.py
|
|
35
40
|
gladier_tools/tests/posix/test_untar.py
|
|
36
41
|
gladier_tools/tests/publish/__init__.py
|
|
37
|
-
gladier_tools/tests/publish/test_publish.py
|
|
42
|
+
gladier_tools/tests/publish/test_publish.py
|
|
43
|
+
gladier_tools/tests/publish/test_publishv2.py
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from .tar import Tar
|
|
2
|
-
from .untar import UnTar
|
|
3
|
-
from .https_download_file import HttpsDownloadFile
|
|
4
|
-
from .encrypt import Encrypt
|
|
5
|
-
from .decrypt import Decrypt
|
|
6
|
-
from .asymmetric_decrypt import AsymmetricDecrypt
|
|
7
|
-
from .asymmetric_encrypt import AsymmetricEncrypt
|
|
8
|
-
__all__ = ['UnTar',
|
|
9
|
-
'Tar',
|
|
10
|
-
'HttpsDownloadFile',
|
|
11
|
-
'Encrypt',
|
|
12
|
-
'Decrypt',
|
|
13
|
-
'AsymmetricDecrypt',
|
|
14
|
-
'AsymmetricEncrypt']
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.4.2'
|
|
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
|
|
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
|