rucio-clients 37.0.0rc1__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.

Potentially problematic release.


This version of rucio-clients might be problematic. Click here for more details.

Files changed (104) hide show
  1. rucio/__init__.py +17 -0
  2. rucio/alembicrevision.py +15 -0
  3. rucio/cli/__init__.py +14 -0
  4. rucio/cli/account.py +216 -0
  5. rucio/cli/bin_legacy/__init__.py +13 -0
  6. rucio/cli/bin_legacy/rucio.py +2825 -0
  7. rucio/cli/bin_legacy/rucio_admin.py +2500 -0
  8. rucio/cli/command.py +272 -0
  9. rucio/cli/config.py +72 -0
  10. rucio/cli/did.py +191 -0
  11. rucio/cli/download.py +128 -0
  12. rucio/cli/lifetime_exception.py +33 -0
  13. rucio/cli/replica.py +162 -0
  14. rucio/cli/rse.py +293 -0
  15. rucio/cli/rule.py +158 -0
  16. rucio/cli/scope.py +40 -0
  17. rucio/cli/subscription.py +73 -0
  18. rucio/cli/upload.py +60 -0
  19. rucio/cli/utils.py +226 -0
  20. rucio/client/__init__.py +15 -0
  21. rucio/client/accountclient.py +432 -0
  22. rucio/client/accountlimitclient.py +183 -0
  23. rucio/client/baseclient.py +983 -0
  24. rucio/client/client.py +120 -0
  25. rucio/client/configclient.py +126 -0
  26. rucio/client/credentialclient.py +59 -0
  27. rucio/client/didclient.py +868 -0
  28. rucio/client/diracclient.py +56 -0
  29. rucio/client/downloadclient.py +1783 -0
  30. rucio/client/exportclient.py +44 -0
  31. rucio/client/fileclient.py +50 -0
  32. rucio/client/importclient.py +42 -0
  33. rucio/client/lifetimeclient.py +90 -0
  34. rucio/client/lockclient.py +109 -0
  35. rucio/client/metaconventionsclient.py +140 -0
  36. rucio/client/pingclient.py +44 -0
  37. rucio/client/replicaclient.py +452 -0
  38. rucio/client/requestclient.py +125 -0
  39. rucio/client/richclient.py +317 -0
  40. rucio/client/rseclient.py +746 -0
  41. rucio/client/ruleclient.py +294 -0
  42. rucio/client/scopeclient.py +90 -0
  43. rucio/client/subscriptionclient.py +173 -0
  44. rucio/client/touchclient.py +82 -0
  45. rucio/client/uploadclient.py +969 -0
  46. rucio/common/__init__.py +13 -0
  47. rucio/common/bittorrent.py +234 -0
  48. rucio/common/cache.py +111 -0
  49. rucio/common/checksum.py +168 -0
  50. rucio/common/client.py +122 -0
  51. rucio/common/config.py +788 -0
  52. rucio/common/constants.py +217 -0
  53. rucio/common/constraints.py +17 -0
  54. rucio/common/didtype.py +237 -0
  55. rucio/common/exception.py +1208 -0
  56. rucio/common/extra.py +31 -0
  57. rucio/common/logging.py +420 -0
  58. rucio/common/pcache.py +1409 -0
  59. rucio/common/plugins.py +185 -0
  60. rucio/common/policy.py +93 -0
  61. rucio/common/schema/__init__.py +200 -0
  62. rucio/common/schema/generic.py +416 -0
  63. rucio/common/schema/generic_multi_vo.py +395 -0
  64. rucio/common/stomp_utils.py +423 -0
  65. rucio/common/stopwatch.py +55 -0
  66. rucio/common/test_rucio_server.py +154 -0
  67. rucio/common/types.py +483 -0
  68. rucio/common/utils.py +1688 -0
  69. rucio/rse/__init__.py +96 -0
  70. rucio/rse/protocols/__init__.py +13 -0
  71. rucio/rse/protocols/bittorrent.py +194 -0
  72. rucio/rse/protocols/cache.py +111 -0
  73. rucio/rse/protocols/dummy.py +100 -0
  74. rucio/rse/protocols/gfal.py +708 -0
  75. rucio/rse/protocols/globus.py +243 -0
  76. rucio/rse/protocols/http_cache.py +82 -0
  77. rucio/rse/protocols/mock.py +123 -0
  78. rucio/rse/protocols/ngarc.py +209 -0
  79. rucio/rse/protocols/posix.py +250 -0
  80. rucio/rse/protocols/protocol.py +361 -0
  81. rucio/rse/protocols/rclone.py +365 -0
  82. rucio/rse/protocols/rfio.py +145 -0
  83. rucio/rse/protocols/srm.py +338 -0
  84. rucio/rse/protocols/ssh.py +414 -0
  85. rucio/rse/protocols/storm.py +195 -0
  86. rucio/rse/protocols/webdav.py +594 -0
  87. rucio/rse/protocols/xrootd.py +302 -0
  88. rucio/rse/rsemanager.py +881 -0
  89. rucio/rse/translation.py +260 -0
  90. rucio/vcsversion.py +11 -0
  91. rucio/version.py +45 -0
  92. rucio_clients-37.0.0rc1.data/data/etc/rse-accounts.cfg.template +25 -0
  93. rucio_clients-37.0.0rc1.data/data/etc/rucio.cfg.atlas.client.template +43 -0
  94. rucio_clients-37.0.0rc1.data/data/etc/rucio.cfg.template +241 -0
  95. rucio_clients-37.0.0rc1.data/data/requirements.client.txt +19 -0
  96. rucio_clients-37.0.0rc1.data/data/rucio_client/merge_rucio_configs.py +144 -0
  97. rucio_clients-37.0.0rc1.data/scripts/rucio +133 -0
  98. rucio_clients-37.0.0rc1.data/scripts/rucio-admin +97 -0
  99. rucio_clients-37.0.0rc1.dist-info/METADATA +54 -0
  100. rucio_clients-37.0.0rc1.dist-info/RECORD +104 -0
  101. rucio_clients-37.0.0rc1.dist-info/WHEEL +5 -0
  102. rucio_clients-37.0.0rc1.dist-info/licenses/AUTHORS.rst +100 -0
  103. rucio_clients-37.0.0rc1.dist-info/licenses/LICENSE +201 -0
  104. rucio_clients-37.0.0rc1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,317 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+ import pydoc
17
+ import re
18
+ import shutil
19
+ import sys
20
+ from datetime import datetime
21
+ from typing import TYPE_CHECKING, Any, Optional, Union
22
+
23
+ from rich import box
24
+ from rich.console import Console, JustifyMethod, RenderableType
25
+ from rich.logging import RichHandler
26
+ from rich.table import Table
27
+ from rich.text import Text
28
+
29
+ from rucio.common.config import config_get
30
+
31
+ if TYPE_CHECKING:
32
+ from collections.abc import Callable, Sequence
33
+
34
+ from rich.style import StyleType
35
+
36
+
37
+ MIN_CONSOLE_WIDTH = 80
38
+ MAX_TRACEBACK_WIDTH = 120 # Slightly higher than default width of rich.traceback (100).
39
+
40
+
41
+ class CLITheme:
42
+ """
43
+ Class to define styles for Rich widgets and prints in the CLI.
44
+ """
45
+ TABLE_FMT = box.SQUARE
46
+
47
+ TEXT_HIGHLIGHT = 'grey50' # Used to highlight prints between tables, e.g. get_metadata or stat.
48
+ SUBHEADER_HIGHLIGHT = 'cyan' # Used to highlight prints between tables for a section, e.g. protocols or usage per account.
49
+ SPINNER = 'dots2'
50
+ SPINNER_STYLE = 'green'
51
+
52
+ JSON_STR = 'green'
53
+ JSON_NUM = 'bold cyan'
54
+
55
+ SUCCESS_ICON = '[bold green]\u2714[/]'
56
+ FAILURE_ICON = '[bold red]\u2717[/]'
57
+
58
+ LOG_THEMES = {
59
+ 'logging.level.info': 'default',
60
+ 'logging.level.warning': 'bold yellow',
61
+ 'logging.level.debug': 'dim',
62
+ 'logging.level.critical': 'default on red',
63
+ 'repr.bool_true': 'green',
64
+ 'repr.bool_false': 'red',
65
+ 'log.time': 'turquoise4'
66
+ }
67
+
68
+ DID_TYPE = {
69
+ 'CONTAINER': 'bold dodger_blue1',
70
+ 'DATASET': 'bold orange3',
71
+ 'FILE': 'bold default',
72
+ 'COLLECTION': 'bold green',
73
+ 'ALL': 'bold magenta',
74
+ 'DERIVED': 'bold magenta'
75
+ }
76
+
77
+ BOOLEAN = {
78
+ 'True': 'green',
79
+ 'False': 'red'
80
+ }
81
+
82
+ RULE_STATE = {
83
+ 'OK': 'bold green',
84
+ 'REPLICATING': 'bold default',
85
+ 'STUCK': 'bold orange3',
86
+ 'WAITING APPROVAL': 'bold dodger_blue1',
87
+ 'INJECT': 'bold medium_purple3',
88
+ 'SUSPENDED': 'bold red'
89
+ }
90
+
91
+ RSE_TYPE = {
92
+ 'DISK': 'bold dodger_blue1',
93
+ 'TAPE': 'bold orange3',
94
+ 'UNKNOWN': 'bold'
95
+ }
96
+
97
+ SUBSCRIPTION_STATE = {
98
+ 'ACTIVE': 'bold green',
99
+ 'INACTIVE': 'bold',
100
+ 'NEW': 'bold dodger_blue1',
101
+ 'UPDATED': 'bold green',
102
+ 'BROKEN': 'bold red',
103
+ 'UNKNOWN': 'bold orange3'
104
+ }
105
+
106
+ AVAILABILITY = {
107
+ 'AVAILABLE': 'bold green',
108
+ 'DELETED': 'bold',
109
+ 'LOST': 'bold red',
110
+ 'UNKNOWN': 'bold orange3'
111
+ }
112
+
113
+ ACCOUNT_STATUS = {
114
+ 'ACTIVE': 'bold green',
115
+ 'SUSPENDED': 'bold red',
116
+ 'DELETED': 'bold'
117
+ }
118
+
119
+ REPLICA_STATE = {
120
+ 'A': 'bold green',
121
+ 'U': 'bold red',
122
+ 'C': 'bold default',
123
+ 'B': 'bold dodger_blue1',
124
+ 'D': 'bold red',
125
+ 'T': 'bold orange3'
126
+ }
127
+
128
+ ACCOUNT_TYPE = {
129
+ 'USER': 'default',
130
+ 'GROUP': 'medium_purple3',
131
+ 'SERVICE': 'yellow'
132
+ }
133
+
134
+
135
+ def setup_rich_logger(
136
+ module_name: Optional[str] = None,
137
+ logger_name: Optional[str] = None,
138
+ logger_level: Optional[int] = None,
139
+ verbose: bool = False,
140
+ console: Optional[Console] = None
141
+ ) -> logging.Logger:
142
+ """
143
+ Factory method to set logger with RichHandler.
144
+
145
+ The function is a copy of the method in rucio.common.utils setup_logger() with minor changes.
146
+
147
+ :param module_name: __name__ of the module that is calling this method
148
+ :param logger_name: name of the logger, typically name of the module.
149
+ :param logger_level: if not given, fetched from config.
150
+ :param verbose: verbose option set in bin/rucio
151
+ :param console: Rich console object
152
+ :returns: logger with RichHandler
153
+ """
154
+ # Helper method for cfg check.
155
+ def _force_cfg_log_level(cfg_option: str) -> bool:
156
+ cfg_forced_modules = config_get('logging', cfg_option, raise_exception=False, default=None, clean_cached=True, check_config_table=False)
157
+ if cfg_forced_modules and module_name is not None:
158
+ if re.match(str(cfg_forced_modules), module_name):
159
+ return True
160
+ return False
161
+
162
+ if not logger_name:
163
+ if not module_name:
164
+ logger_name = 'user'
165
+ else:
166
+ logger_name = module_name.split('.')[-1]
167
+ logger = logging.getLogger(logger_name)
168
+
169
+ # Extracting the log level.
170
+ if not logger_level:
171
+ logger_level = logging.INFO
172
+ if verbose:
173
+ logger_level = logging.DEBUG
174
+
175
+ # Overriding by the config.
176
+ cfg_levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR)
177
+ for level in cfg_levels:
178
+ cfg_opt = 'forceloglevel' + logging.getLevelName(level)
179
+ if _force_cfg_log_level(cfg_opt):
180
+ logger_level = level
181
+
182
+ logger.setLevel(logger_level)
183
+
184
+ def add_handler(logger: logging.Logger,
185
+ console: Optional[Console] = None,
186
+ verbose: bool = False) -> None:
187
+
188
+ def time_formatter(timestamp: datetime) -> Text:
189
+ return Text(f"[{timestamp.isoformat(sep=' ', timespec='milliseconds')}]")
190
+
191
+ console = console or Console()
192
+ handler = RichHandler(rich_tracebacks=True, markup=True, show_path=verbose, show_time=verbose, console=console, tracebacks_width=min(console.width, MAX_TRACEBACK_WIDTH),
193
+ tracebacks_word_wrap=True, log_time_format=time_formatter)
194
+ logger.addHandler(handler)
195
+
196
+ # Setting handler and formatter.
197
+ if not logger.handlers:
198
+ add_handler(logger, console, verbose)
199
+
200
+ return logger
201
+
202
+
203
+ def _format_value(value: Optional[Union[RenderableType, int, float, bool, datetime]] = None) -> RenderableType:
204
+ """
205
+ Formats the value based on its type for Rich Table.
206
+
207
+ A helper function to format the value to Rich RenderableType.
208
+
209
+ :param value: value to format
210
+ :returns: formatted value
211
+ """
212
+ if value is None or str(value) == 'None':
213
+ return ''
214
+ if isinstance(value, bool):
215
+ return CLITheme.BOOLEAN[str(value)]
216
+ if isinstance(value, (int, float, datetime)):
217
+ return str(value)
218
+ return value
219
+
220
+
221
+ def generate_table(
222
+ rows: 'Sequence[Sequence[Union[RenderableType, int, float, bool, datetime]]]',
223
+ headers: Optional['Sequence[RenderableType]'] = None,
224
+ row_styles: Optional['Sequence[StyleType]'] = None,
225
+ col_alignments: Optional[list[JustifyMethod]] = None,
226
+ table_format: box.Box = CLITheme.TABLE_FMT,
227
+ ) -> Table:
228
+ """
229
+ Generates a Rich Table object from given input rows.
230
+
231
+ The elements in each row can be either plain strings or Rich renderable objects.
232
+ Passing strings will display them as simple text, while using Rich objects
233
+ allows you to introduce additional structure, styling, and widgets (e.g. Text, Trees) into
234
+ the table. Strings with style markup will be rendered as styled text.
235
+
236
+ :param table_format: style of the table
237
+ :param headers: list of headers
238
+ :param rows: list of rows
239
+ :param col_alignments: list of column alignments
240
+ :param row_styles: list of row styles
241
+ :returns: a Rich Table object
242
+ """
243
+ table = Table(box=table_format, show_header=headers is not None and len(headers) > 0)
244
+ table.row_styles = row_styles or ['none', 'dim']
245
+
246
+ if len(rows) == 0:
247
+ if headers:
248
+ for header in headers:
249
+ table.add_column(header)
250
+ return table
251
+
252
+ # Auto-detect on first row, numerical values on the right.
253
+ col_alignments = col_alignments or ['right' if str(col).isnumeric() else 'left' for col in rows[0]]
254
+ headers = headers or [''] * len(rows[0])
255
+ while len(headers) > len(col_alignments):
256
+ col_alignments.append('left')
257
+
258
+ for header, alignment in zip(headers, col_alignments):
259
+ table.add_column(header, overflow='fold', justify=alignment)
260
+
261
+ for row in rows:
262
+ row = [_format_value(col) for col in row]
263
+ table.add_row(*row)
264
+ return table
265
+
266
+
267
+ def print_output(
268
+ *output: Any,
269
+ console: Console,
270
+ no_pager: bool = False
271
+ ) -> None:
272
+ """
273
+ Prints the objects using the specified Rich console object. Optionally disables the pager if specified.
274
+
275
+ The function works similarly to Rich's `console.print()` method but provides additional control over the pager feature.
276
+
277
+ :param output: objects to print to the terminal
278
+ :param console: Rich console object
279
+ :param no_pager: flag to disable the pager
280
+ """
281
+ if console.is_terminal:
282
+ if no_pager:
283
+ console.print(*output)
284
+ else:
285
+ console.width = sys.maxsize # Overwrite auto-detected console width.
286
+ console.begin_capture()
287
+ console.print(*output)
288
+ else:
289
+ console.width = sys.maxsize
290
+ console.print(*output)
291
+
292
+
293
+ def get_cli_config() -> str:
294
+ """
295
+ Returns the CLI type from the config file.
296
+
297
+ :returns: CLI type (Rich or tabulate)
298
+ """
299
+ cli_type = config_get('experimental', 'cli', raise_exception=False, default='tabulate').lower()
300
+ if cli_type not in ['rich', 'tabulate']:
301
+ cli_type = 'tabulate'
302
+ return cli_type
303
+
304
+
305
+ def get_pager() -> 'Callable[[str], None]':
306
+ """
307
+ Returns the pager function based on the terminal availability.
308
+
309
+ :returns: pager
310
+ """
311
+ default_pager = 'less'
312
+ # Attempt to use the default pager if available.
313
+ if shutil.which(default_pager) is not None:
314
+ return lambda text: pydoc.pipepager(text, f'{default_pager} -FRSXKM')
315
+
316
+ # Fall back to pydoc.pager if the default pager is not available.
317
+ return pydoc.pager