dtool-config 0.4.2__py3-none-any.whl

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.
@@ -0,0 +1,9 @@
1
+ """dtool_config package."""
2
+
3
+ from importlib.metadata import version, PackageNotFoundError
4
+
5
+ try:
6
+ __version__ = version("dtool-config")
7
+ except PackageNotFoundError:
8
+ # Package is not installed.
9
+ __version__ = "unknown"
dtool_config/cli.py ADDED
@@ -0,0 +1,179 @@
1
+ """dtool_config.cli module."""
2
+
3
+ import click
4
+
5
+ import dtoolcore.utils
6
+
7
+ import dtool_config.utils
8
+
9
+
10
+ CONFIG_PATH = dtoolcore.utils.DEFAULT_CONFIG_PATH
11
+
12
+
13
+ @click.group()
14
+ def config():
15
+ """Configure dtool settings."""
16
+
17
+
18
+ @config.group()
19
+ def user():
20
+ """Configure user settings."""
21
+
22
+
23
+ @user.command()
24
+ @click.argument("username", nargs=-1, required=False)
25
+ def name(username):
26
+ """Display / set / update the user name."""
27
+ if not username:
28
+ click.secho(dtool_config.utils.get_username(CONFIG_PATH))
29
+ else:
30
+ username_str = " ".join(username)
31
+ click.secho(dtool_config.utils.set_username(CONFIG_PATH, username_str))
32
+
33
+
34
+ @user.command()
35
+ @click.argument("email_address", required=False)
36
+ def email(email_address):
37
+ """Display / set / update the user email."""
38
+ if not email_address:
39
+ click.secho(dtool_config.utils.get_user_email(CONFIG_PATH))
40
+ else:
41
+ click.secho(dtool_config.utils.set_user_email(
42
+ CONFIG_PATH,
43
+ email_address
44
+ ))
45
+
46
+
47
+ @config.command()
48
+ @click.argument(
49
+ "readme_template_file",
50
+ required=False,
51
+ type=click.Path(exists=True, dir_okay=False)
52
+ )
53
+ def readme_template(readme_template_file):
54
+ """Display / set / update the readme template file."""
55
+ if not readme_template_file:
56
+ click.secho(dtool_config.utils.get_readme_template_fpath(
57
+ CONFIG_PATH,
58
+ ))
59
+ else:
60
+ click.secho(dtool_config.utils.set_readme_template_fpath(
61
+ CONFIG_PATH,
62
+ readme_template_file
63
+ ))
64
+
65
+
66
+ @config.group()
67
+ def ecs():
68
+ """Configure ECS S3 object storage."""
69
+
70
+
71
+ @ecs.command()
72
+ @click.argument("bucket_name")
73
+ @click.argument("url", required=False)
74
+ def endpoint(bucket_name, url):
75
+ """Display / set / update the ECS endpoint URL."""
76
+ if not url:
77
+ click.secho(
78
+ dtool_config.utils.get_ecs_endpoint(CONFIG_PATH, bucket_name)
79
+ )
80
+ else:
81
+ click.secho(
82
+ dtool_config.utils.set_ecs_endpoint(CONFIG_PATH, bucket_name, url)
83
+ )
84
+
85
+
86
+ @ecs.command()
87
+ @click.argument("bucket_name")
88
+ @click.argument("ecs_access_key_id", required=False)
89
+ def access_key_id(bucket_name, ecs_access_key_id):
90
+ """Display / set / update the ECS access key id (username)."""
91
+ if not ecs_access_key_id:
92
+ click.secho(
93
+ dtool_config.utils.get_ecs_access_key_id(CONFIG_PATH, bucket_name)
94
+ )
95
+ else:
96
+ click.secho(dtool_config.utils.set_ecs_access_key_id(
97
+ CONFIG_PATH,
98
+ bucket_name,
99
+ ecs_access_key_id
100
+ ))
101
+
102
+
103
+ @ecs.command()
104
+ @click.argument("bucket_name")
105
+ @click.argument("ecs_secret_access_key", required=False)
106
+ def secret_access_key(bucket_name, ecs_secret_access_key):
107
+ """Display / set / update the ECS secret access key."""
108
+ if not ecs_secret_access_key:
109
+ click.secho(dtool_config.utils.get_ecs_secret_access_key(
110
+ CONFIG_PATH,
111
+ bucket_name
112
+ )
113
+ )
114
+ else:
115
+ click.secho(dtool_config.utils.set_ecs_secret_access_key(
116
+ CONFIG_PATH,
117
+ bucket_name,
118
+ ecs_secret_access_key
119
+ ))
120
+
121
+
122
+ @ecs.command(name="ls")
123
+ def list_ecs_base_uris():
124
+ """List the configured ECS base URIs."""
125
+ for base_uri in dtool_config.utils.list_ecs_base_uris(CONFIG_PATH):
126
+ click.secho(base_uri)
127
+
128
+
129
+ @config.command()
130
+ @click.argument(
131
+ "cache_directory_path",
132
+ required=False,
133
+ type=click.Path(exists=True, file_okay=False)
134
+ )
135
+ def cache(cache_directory_path):
136
+ """Display / set / update the dtool cache directory."""
137
+ if not cache_directory_path:
138
+ click.secho(dtool_config.utils.get_cache(
139
+ CONFIG_PATH,
140
+ ))
141
+ else:
142
+ click.secho(dtool_config.utils.set_cache(
143
+ CONFIG_PATH,
144
+ cache_directory_path
145
+ ))
146
+
147
+
148
+ @config.group()
149
+ def azure():
150
+ """Configure Azure Storage."""
151
+
152
+
153
+ @azure.command() # NOQA
154
+ @click.argument("container")
155
+ def get(container):
156
+ """Print the secret access key of the specified Azure storage container."""
157
+ click.secho(dtool_config.utils.get_azure_secret_access_key(
158
+ CONFIG_PATH,
159
+ container,
160
+ ))
161
+
162
+
163
+ @azure.command() # NOQA
164
+ @click.argument("container")
165
+ @click.argument("azure_secret_access_key")
166
+ def set(container, azure_secret_access_key):
167
+ """Set/update the access key for the specified Azure storage container."""
168
+ click.secho(dtool_config.utils.set_azure_secret_access_key(
169
+ CONFIG_PATH,
170
+ container,
171
+ azure_secret_access_key
172
+ ))
173
+
174
+
175
+ @azure.command() # NOQA
176
+ def ls():
177
+ """List the configured Azure base URIs."""
178
+ for base_uri in dtool_config.utils.list_azure_base_uris(CONFIG_PATH):
179
+ click.secho(base_uri)
dtool_config/utils.py ADDED
@@ -0,0 +1,248 @@
1
+ """Helper functions for getting and setting config values."""
2
+
3
+ import os
4
+
5
+ from dtoolcore.utils import (
6
+ _get_config_dict_from_file,
7
+ get_config_value_from_file,
8
+ write_config_value_to_file,
9
+ )
10
+
11
+ USERNAME_KEY = "DTOOL_USER_FULL_NAME"
12
+ USER_EMAIL_KEY = "DTOOL_USER_EMAIL"
13
+
14
+ README_TEMPLATE_KEY = "DTOOL_README_TEMPLATE_FPATH"
15
+
16
+ CACHE_DIRECTORY_KEY = "DTOOL_CACHE_DIRECTORY"
17
+
18
+ ECS_ENDPOINT_KEY_PREFIX = "DTOOL_ECS_ENDPOINT_"
19
+ ECS_ACCESS_KEY_ID_KEY_PREFIX = "DTOOL_ECS_ACCESS_KEY_ID_"
20
+ ECS_SECRET_ACCESS_KEY_KEY_PREFIX = "DTOOL_ECS_SECRET_ACCESS_KEY_"
21
+
22
+ AZURE_KEY_PREFIX = "DTOOL_AZURE_ACCOUNT_KEY_"
23
+
24
+
25
+ def get_username(config_fpath):
26
+ """Return the user name.
27
+
28
+ :param config_fpath: path to the dtool config file
29
+ :returns: the user name or an empty string
30
+ """
31
+ return get_config_value_from_file(USERNAME_KEY, config_fpath, "")
32
+
33
+
34
+ def set_username(config_fpath, username):
35
+ """Write the user name to the dtool config file.
36
+
37
+ :param config_fpath: path to the dtool config file
38
+ :param username: user name
39
+ """
40
+ return write_config_value_to_file(USERNAME_KEY, username, config_fpath)
41
+
42
+
43
+ def get_user_email(config_fpath):
44
+ """Return the user email.
45
+
46
+ :param config_fpath: path to the dtool config file
47
+ :returns: the user email or an empty string
48
+ """
49
+ return get_config_value_from_file(USER_EMAIL_KEY, config_fpath, "")
50
+
51
+
52
+ def set_user_email(config_fpath, email):
53
+ """Write the user email to the dtool config file.
54
+
55
+ :param config_fpath: path to the dtool config file
56
+ :param email: user email
57
+ """
58
+ return write_config_value_to_file(USER_EMAIL_KEY, email, config_fpath)
59
+
60
+
61
+ def get_readme_template_fpath(config_fpath):
62
+ """Return the readme template path.
63
+
64
+ :param config_fpath: path to the dtool config file
65
+ :returns: path to the readme template file
66
+ """
67
+ return get_config_value_from_file(README_TEMPLATE_KEY, config_fpath, "")
68
+
69
+
70
+ def set_readme_template_fpath(config_fpath, readme_template_fpath):
71
+ """Write the user email to the dtool config file.
72
+
73
+ :param config_fpath: path to the dtool config file
74
+ :param readme_template_fpath: path to the readme template file
75
+ """
76
+ return write_config_value_to_file(
77
+ README_TEMPLATE_KEY,
78
+ readme_template_fpath,
79
+ config_fpath
80
+ )
81
+
82
+
83
+ def get_ecs_endpoint(config_fpath, bucket_name):
84
+ """Return the ECS endpoint URL.
85
+
86
+ :param config_fpath: path to the dtool config file
87
+ :param bucket_name: name of the bucket in a ECS namespace
88
+ :returns: the ECS endpoint URL or an empty string
89
+ """
90
+ key = ECS_ENDPOINT_KEY_PREFIX + bucket_name
91
+ return get_config_value_from_file(key, config_fpath, "")
92
+
93
+
94
+ def set_ecs_endpoint(config_fpath, bucket_name, ecs_endpoint):
95
+ """Write the ECS endpoint URL to the dtool config file.
96
+
97
+ :param config_fpath: path to the dtool config file
98
+ :param bucket_name: name of the bucket in a ECS namespace
99
+ :param ecs_endpoint: ECS endpoint URL
100
+ """
101
+ key = ECS_ENDPOINT_KEY_PREFIX + bucket_name
102
+ return write_config_value_to_file(
103
+ key,
104
+ ecs_endpoint,
105
+ config_fpath
106
+ )
107
+
108
+
109
+ def get_ecs_access_key_id(config_fpath, bucket_name):
110
+ """Return the ECS access key id.
111
+
112
+ :param config_fpath: path to the dtool config file
113
+ :param bucket_name: name of the bucket in a ECS namespace
114
+ :returns: the ECS access key id or an empty string
115
+ """
116
+ key = ECS_ACCESS_KEY_ID_KEY_PREFIX + bucket_name
117
+ return get_config_value_from_file(key, config_fpath, "")
118
+
119
+
120
+ def set_ecs_access_key_id(config_fpath, bucket_name, ecs_access_key_id):
121
+ """Write the ECS access key id to the dtool config file.
122
+
123
+ :param config_fpath: path to the dtool config file
124
+ :param bucket_name: name of the bucket in a ECS namespace
125
+ :param ecs_access_key_id: ECS access key id
126
+ """
127
+ key = ECS_ACCESS_KEY_ID_KEY_PREFIX + bucket_name
128
+ return write_config_value_to_file(
129
+ key,
130
+ ecs_access_key_id,
131
+ config_fpath
132
+ )
133
+
134
+
135
+ def get_ecs_secret_access_key(config_fpath, bucket_name):
136
+ """Return the ECS secret access key.
137
+
138
+ :param config_fpath: path to the dtool config file
139
+ :param bucket_name: name of the bucket in a ECS namespace
140
+ :returns: the ECS secret access key or an empty string
141
+ """
142
+ key = ECS_SECRET_ACCESS_KEY_KEY_PREFIX + bucket_name
143
+ return get_config_value_from_file(
144
+ key,
145
+ config_fpath,
146
+ ""
147
+ )
148
+
149
+
150
+ def set_ecs_secret_access_key(
151
+ config_fpath,
152
+ bucket_name,
153
+ ecs_secret_access_key
154
+ ):
155
+ """Write the ECS access key id to the dtool config file.
156
+
157
+ :param config_fpath: path to the dtool config file
158
+ :param bucket_name: name of the bucket in a ECS namespace
159
+ :param ecs_secret_access_key: ECS secret access key
160
+ """
161
+ key = ECS_SECRET_ACCESS_KEY_KEY_PREFIX + bucket_name
162
+ return write_config_value_to_file(
163
+ key,
164
+ ecs_secret_access_key,
165
+ config_fpath
166
+ )
167
+
168
+
169
+ def list_ecs_base_uris(config_fpath):
170
+ """List the ECS buckets in the config file.
171
+
172
+ :param config_fpath: path to the dtool config file
173
+ :returns: the list of azure storage container names
174
+ """
175
+ config_content = _get_config_dict_from_file(config_fpath)
176
+ ecs_bucket_base_uris = []
177
+ for key in config_content.keys():
178
+ if key.startswith(ECS_ACCESS_KEY_ID_KEY_PREFIX):
179
+ name = key[len(ECS_ACCESS_KEY_ID_KEY_PREFIX):]
180
+ base_uri = "ecs://{}".format(name)
181
+ ecs_bucket_base_uris.append(base_uri)
182
+ return sorted(ecs_bucket_base_uris)
183
+
184
+
185
+ def get_cache(config_fpath):
186
+ """Return the cache directory specified in the dtool config file.
187
+
188
+ :param config_fpath: path to the dtool config file
189
+ :returns: the path to the dtool cache directory
190
+ """
191
+
192
+ return get_config_value_from_file(
193
+ CACHE_DIRECTORY_KEY,
194
+ config_fpath,
195
+ ""
196
+ )
197
+
198
+
199
+ def set_cache(config_fpath, cache_dir):
200
+ """Write the cache directory to the dtool config file.
201
+
202
+ :param config_fpath: path to the dtool config file
203
+ :param cache_dir: the path to the dtool cache direcotory
204
+ """
205
+ cache_dir = os.path.abspath(cache_dir)
206
+ return write_config_value_to_file(
207
+ CACHE_DIRECTORY_KEY,
208
+ cache_dir,
209
+ config_fpath
210
+ )
211
+
212
+
213
+ def get_azure_secret_access_key(config_fpath, container):
214
+ """Return the Azure storage container secret access key.
215
+
216
+ :param config_fpath: path to the dtool config file
217
+ :param container: azure storage container name
218
+ :returns: the Azure container secret access key or an empty string
219
+ """
220
+ key = AZURE_KEY_PREFIX + container
221
+ return get_config_value_from_file(key, config_fpath, "")
222
+
223
+
224
+ def set_azure_secret_access_key(config_fpath, container, az_secret_access_key):
225
+ """Write the ECS access key id to the dtool config file.
226
+
227
+ :param config_fpath: path to the dtool config file
228
+ :param container: azure storage container name
229
+ :param az_secret_access_key: azure secret access key for the container
230
+ """
231
+ key = AZURE_KEY_PREFIX + container
232
+ return write_config_value_to_file(key, az_secret_access_key, config_fpath)
233
+
234
+
235
+ def list_azure_base_uris(config_fpath):
236
+ """List the configured azure base URIs.
237
+
238
+ :param config_fpath: path to the dtool config file
239
+ :returns: the list of azure base URs
240
+ """
241
+ config_content = _get_config_dict_from_file(config_fpath)
242
+ az_base_uris = []
243
+ for key in config_content.keys():
244
+ if key.startswith(AZURE_KEY_PREFIX):
245
+ name = key[len(AZURE_KEY_PREFIX):]
246
+ base_uri = "azure://{}".format(name)
247
+ az_base_uris.append(base_uri)
248
+ return sorted(az_base_uris)
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.5
2
+ Name: dtool-config
3
+ Version: 0.4.2
4
+ Summary: Plugin to make configuration of dtool easier
5
+ Project-URL: Repository, https://github.com/jic-dtool/dtool-config
6
+ Author-email: Tjelvar Olsson <tjelvar.olsson@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE.rst
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: click
11
+ Requires-Dist: dtoolcore>=3.9.0
12
+ Description-Content-Type: text/x-rst
13
+
14
+ dtool CLI commands for configuring dtool settings
15
+ =================================================
16
+
17
+ .. image:: https://badge.fury.io/py/dtool-config.svg
18
+ :target: http://badge.fury.io/py/dtool-config
19
+ :alt: PyPi package
20
+
21
+ .. image:: https://github.com/jic-dtool/dtool-config/actions/workflows/test.yml/badge.svg?branch=main
22
+ :target: https://github.com/jic-dtool/dtool-config/actions/workflows/test.yml
23
+ :alt: Tests
24
+
25
+ .. image:: https://codecov.io/github/jic-dtool/dtool-config/coverage.svg?branch=main
26
+ :target: https://codecov.io/github/jic-dtool/dtool-config?branch=main
27
+ :alt: Code Coverage
28
+
29
+
30
+ Installation
31
+ ------------
32
+
33
+ Installation using ``pip``::
34
+
35
+ pip install dtool-config
36
+
37
+ Example usage
38
+ -------------
39
+
40
+ Setting the user name and email::
41
+
42
+ dtool config user name "Marie Curie"
43
+ dtool config user email marie.curie@sorbonne-universite.fr
44
+
45
+ Setting the download cache::
46
+
47
+ mkdir /tmp/dtool
48
+ dtool config cache /tmp/dtool
49
+
50
+
51
+ Related packages
52
+ ----------------
53
+
54
+ - `dtoolcore <https://github.com/jic-dtool/dtoolcore>`_
55
+ - `dtool-cli <https://github.com/jic-dtool/dtool-cli>`_
56
+ - `dtool-info <https://github.com/jic-dtool/dtool-create>`_
57
+ - `dtool-create <https://github.com/jic-dtool/dtool-create>`_
@@ -0,0 +1,8 @@
1
+ dtool_config/__init__.py,sha256=5A5H5MOyWzp_rQMoLM4WZcnmEoeqqtcLqSY7H_1PHY8,227
2
+ dtool_config/cli.py,sha256=ClPiNNhe26SWt8pdaC4hhfOgcGSIV5Gnr-F7TDWwv0Y,4669
3
+ dtool_config/utils.py,sha256=bNmpx-Rzarr8EV2049ZV8dn40l6HZItpypm6jELvMTk,7581
4
+ dtool_config-0.4.2.dist-info/METADATA,sha256=O77f8olELvIiqaIFq5qB9r92hjhanII6AmcgYRrPbGk,1618
5
+ dtool_config-0.4.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
6
+ dtool_config-0.4.2.dist-info/entry_points.txt,sha256=C6ncvMNaYkXFKFNhtQW3_O8yHa0AGzIUXmhacOjeHZU,45
7
+ dtool_config-0.4.2.dist-info/licenses/LICENSE.rst,sha256=UedyOiE3-MK9IJc1Fuh-THjZGhIR9FWkB2t0Ki7-P1U,1083
8
+ dtool_config-0.4.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [dtool.cli]
2
+ config = dtool_config.cli:config
@@ -0,0 +1,22 @@
1
+ MIT License
2
+ ===========
3
+
4
+ Copyright (c) 2018 Tjelvar Olsson
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.