rucio-clients 35.8.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.
Files changed (88) hide show
  1. rucio/__init__.py +17 -0
  2. rucio/alembicrevision.py +15 -0
  3. rucio/client/__init__.py +15 -0
  4. rucio/client/accountclient.py +433 -0
  5. rucio/client/accountlimitclient.py +183 -0
  6. rucio/client/baseclient.py +974 -0
  7. rucio/client/client.py +76 -0
  8. rucio/client/configclient.py +126 -0
  9. rucio/client/credentialclient.py +59 -0
  10. rucio/client/didclient.py +866 -0
  11. rucio/client/diracclient.py +56 -0
  12. rucio/client/downloadclient.py +1785 -0
  13. rucio/client/exportclient.py +44 -0
  14. rucio/client/fileclient.py +50 -0
  15. rucio/client/importclient.py +42 -0
  16. rucio/client/lifetimeclient.py +90 -0
  17. rucio/client/lockclient.py +109 -0
  18. rucio/client/metaconventionsclient.py +140 -0
  19. rucio/client/pingclient.py +44 -0
  20. rucio/client/replicaclient.py +454 -0
  21. rucio/client/requestclient.py +125 -0
  22. rucio/client/rseclient.py +746 -0
  23. rucio/client/ruleclient.py +294 -0
  24. rucio/client/scopeclient.py +90 -0
  25. rucio/client/subscriptionclient.py +173 -0
  26. rucio/client/touchclient.py +82 -0
  27. rucio/client/uploadclient.py +955 -0
  28. rucio/common/__init__.py +13 -0
  29. rucio/common/cache.py +74 -0
  30. rucio/common/config.py +801 -0
  31. rucio/common/constants.py +159 -0
  32. rucio/common/constraints.py +17 -0
  33. rucio/common/didtype.py +189 -0
  34. rucio/common/exception.py +1151 -0
  35. rucio/common/extra.py +36 -0
  36. rucio/common/logging.py +420 -0
  37. rucio/common/pcache.py +1408 -0
  38. rucio/common/plugins.py +153 -0
  39. rucio/common/policy.py +84 -0
  40. rucio/common/schema/__init__.py +150 -0
  41. rucio/common/schema/atlas.py +413 -0
  42. rucio/common/schema/belleii.py +408 -0
  43. rucio/common/schema/domatpc.py +401 -0
  44. rucio/common/schema/escape.py +426 -0
  45. rucio/common/schema/generic.py +433 -0
  46. rucio/common/schema/generic_multi_vo.py +412 -0
  47. rucio/common/schema/icecube.py +406 -0
  48. rucio/common/stomp_utils.py +159 -0
  49. rucio/common/stopwatch.py +55 -0
  50. rucio/common/test_rucio_server.py +148 -0
  51. rucio/common/types.py +403 -0
  52. rucio/common/utils.py +2238 -0
  53. rucio/rse/__init__.py +96 -0
  54. rucio/rse/protocols/__init__.py +13 -0
  55. rucio/rse/protocols/bittorrent.py +184 -0
  56. rucio/rse/protocols/cache.py +122 -0
  57. rucio/rse/protocols/dummy.py +111 -0
  58. rucio/rse/protocols/gfal.py +703 -0
  59. rucio/rse/protocols/globus.py +243 -0
  60. rucio/rse/protocols/gsiftp.py +92 -0
  61. rucio/rse/protocols/http_cache.py +82 -0
  62. rucio/rse/protocols/mock.py +123 -0
  63. rucio/rse/protocols/ngarc.py +209 -0
  64. rucio/rse/protocols/posix.py +250 -0
  65. rucio/rse/protocols/protocol.py +594 -0
  66. rucio/rse/protocols/rclone.py +364 -0
  67. rucio/rse/protocols/rfio.py +136 -0
  68. rucio/rse/protocols/srm.py +338 -0
  69. rucio/rse/protocols/ssh.py +413 -0
  70. rucio/rse/protocols/storm.py +206 -0
  71. rucio/rse/protocols/webdav.py +550 -0
  72. rucio/rse/protocols/xrootd.py +301 -0
  73. rucio/rse/rsemanager.py +764 -0
  74. rucio/vcsversion.py +11 -0
  75. rucio/version.py +38 -0
  76. rucio_clients-35.8.2.data/data/etc/rse-accounts.cfg.template +25 -0
  77. rucio_clients-35.8.2.data/data/etc/rucio.cfg.atlas.client.template +42 -0
  78. rucio_clients-35.8.2.data/data/etc/rucio.cfg.template +257 -0
  79. rucio_clients-35.8.2.data/data/requirements.client.txt +15 -0
  80. rucio_clients-35.8.2.data/data/rucio_client/merge_rucio_configs.py +144 -0
  81. rucio_clients-35.8.2.data/scripts/rucio +2542 -0
  82. rucio_clients-35.8.2.data/scripts/rucio-admin +2447 -0
  83. rucio_clients-35.8.2.dist-info/METADATA +50 -0
  84. rucio_clients-35.8.2.dist-info/RECORD +88 -0
  85. rucio_clients-35.8.2.dist-info/WHEEL +5 -0
  86. rucio_clients-35.8.2.dist-info/licenses/AUTHORS.rst +97 -0
  87. rucio_clients-35.8.2.dist-info/licenses/LICENSE +201 -0
  88. rucio_clients-35.8.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,364 @@
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 json
16
+ import logging
17
+ import os
18
+
19
+ from rucio.common import exception
20
+ from rucio.common.config import get_config_dirs
21
+ from rucio.common.utils import PREFERRED_CHECKSUM, execute
22
+ from rucio.rse.protocols import protocol
23
+
24
+
25
+ def load_conf_file(file_name):
26
+ config_dir = next(filter(lambda d: os.path.exists(os.path.join(d, file_name)), get_config_dirs()))
27
+ with open(os.path.join(config_dir, file_name)) as f:
28
+ return json.load(f)
29
+
30
+
31
+ class Default(protocol.RSEProtocol):
32
+ """ Implementing access to RSEs using the rclone protocol."""
33
+
34
+ def __init__(self, protocol_attr, rse_settings, logger=logging.log):
35
+ """ Initializes the object with information about the referred RSE.
36
+
37
+ :param props: Properties derived from the RSE Repository
38
+ """
39
+ super(Default, self).__init__(protocol_attr, rse_settings, logger=logger)
40
+ if len(rse_settings['protocols']) == 1:
41
+ raise exception.RucioException('rclone initialization requires at least one other protocol defined on the RSE. (from ssh, sftp, posix, webdav)')
42
+ self.scheme = self.attributes['scheme']
43
+ setuprclone = False
44
+ for protocols in reversed(rse_settings['protocols']):
45
+ if protocol_attr['impl'] == protocols['impl']:
46
+ continue
47
+ else:
48
+ setuprclone = self.setuphostname(protocols)
49
+ if setuprclone:
50
+ break
51
+
52
+ if not setuprclone:
53
+ raise exception.RucioException('rclone could not be initialized.')
54
+ self.logger = logger
55
+
56
+ def setuphostname(self, protocols):
57
+ """ Initializes the rclone object with information about protocols in the referred RSE.
58
+
59
+ :param protocols: Protocols in the RSE
60
+ """
61
+ if protocols['scheme'] in ['scp', 'rsync', 'sftp']:
62
+ self.hostname = 'ssh_rclone_rse'
63
+ self.host = protocols['hostname']
64
+ self.port = str(protocols['port'])
65
+ if protocols['extended_attributes'] is not None and 'user' in list(protocols['extended_attributes'].keys()):
66
+ self.user = protocols['extended_attributes']['user']
67
+ else:
68
+ self.user = None
69
+ try:
70
+ data = load_conf_file('rclone-init.cfg')
71
+ key_file = data[self.host + '_ssh']['key_file']
72
+ except KeyError:
73
+ self.logger(logging.ERROR, 'rclone.init: rclone-init.cfg:- Field value missing for "{}_ssh: key_file"'.format(self.host))
74
+ return False
75
+ try:
76
+ if self.user:
77
+ cmd = 'rclone config create {0} sftp host {1} user {2} port {3} key_file {4}'.format(self.hostname, self.host, self.user, str(self.port), key_file)
78
+ self.logger(logging.DEBUG, 'rclone.init: cmd: {}'.format(cmd))
79
+ status, out, err = execute(cmd)
80
+ if status:
81
+ return False
82
+ else:
83
+ cmd = 'rclone config create {0} sftp host {1} port {2} key_file {3}'.format(self.hostname, self.host, str(self.port), key_file)
84
+ self.logger(logging.DEBUG, 'rclone.init: cmd: {}'.format(cmd))
85
+ status, out, err = execute(cmd)
86
+ if status:
87
+ return False
88
+ except Exception as e:
89
+ raise exception.ServiceUnavailable(e)
90
+
91
+ elif protocols['scheme'] == 'file':
92
+ self.hostname = '%s_rclone_rse' % (protocols['scheme'])
93
+ self.host = 'localhost'
94
+ try:
95
+ cmd = 'rclone config create {0} local'.format(self.hostname)
96
+ self.logger(logging.DEBUG, 'rclone.init: cmd: {}'.format(cmd))
97
+ status, out, err = execute(cmd)
98
+ if status:
99
+ return False
100
+ except Exception as e:
101
+ raise exception.ServiceUnavailable(e)
102
+
103
+ elif protocols['scheme'] in ['davs', 'https']:
104
+ self.hostname = '%s_rclone_rse' % (protocols['scheme'])
105
+ self.host = protocols['hostname']
106
+ url = '%s://%s:%s%s' % (protocols['scheme'], protocols['hostname'], str(protocols['port']), protocols['prefix'])
107
+ try:
108
+ data = load_conf_file('rclone-init.cfg')
109
+ bearer_token = data[self.host + '_webdav']['bearer_token']
110
+ except KeyError:
111
+ self.logger(logging.ERROR, 'rclone.init: rclone-init.cfg:- Field value missing for "{}_webdav: bearer_token"'.format(self.host))
112
+ return False
113
+ try:
114
+ cmd = 'rclone config create {0} webdav url {1} vendor other bearer_token {2}'.format(self.hostname, url, bearer_token)
115
+ self.logger(logging.DEBUG, 'rclone.init: cmd: {}'.format(cmd))
116
+ status, out, err = execute(cmd)
117
+ if status:
118
+ return False
119
+ except Exception as e:
120
+ raise exception.ServiceUnavailable(e)
121
+
122
+ else:
123
+ self.logger(logging.DEBUG, 'rclone.init: {} protocol impl not supported by rucio rclone'.format(protocols['impl']))
124
+ return False
125
+
126
+ return True
127
+
128
+ def path2pfn(self, path):
129
+ """
130
+ Returns a fully qualified PFN for the file referred by path.
131
+
132
+ :param path: The path to the file.
133
+
134
+ :returns: Fully qualified PFN.
135
+
136
+ """
137
+ self.logger(logging.DEBUG, 'rclone.path2pfn: path: {}'.format(path))
138
+ if not path.startswith('rclone://'):
139
+ return '%s://%s/%s' % (self.scheme, self.host, path)
140
+ else:
141
+ return path
142
+
143
+ def exists(self, pfn):
144
+ """ Checks if the requested file is known by the referred RSE.
145
+
146
+ :param pfn: Physical file name
147
+
148
+ :returns: True if the file exists, False if it doesn't
149
+
150
+ :raise ServiceUnavailable
151
+ """
152
+ self.logger(logging.DEBUG, 'rclone.exists: pfn: {}'.format(pfn))
153
+ try:
154
+ path = self.pfn2path(pfn)
155
+ cmd = 'rclone lsf %s:%s' % (self.hostname, path)
156
+ self.logger(logging.DEBUG, 'rclone.exists: cmd: {}'.format(cmd))
157
+ status, out, err = execute(cmd)
158
+ if status:
159
+ return False
160
+ except Exception as e:
161
+ raise exception.ServiceUnavailable(e)
162
+
163
+ return True
164
+
165
+ def stat(self, path):
166
+ """
167
+ Returns the stats of a file.
168
+
169
+ :param path: path to file
170
+
171
+ :raises ServiceUnavailable: if some generic error occurred in the library.
172
+
173
+ :returns: a dict with two keys, filesize and an element of GLOBALLY_SUPPORTED_CHECKSUMS.
174
+ """
175
+ self.logger(logging.DEBUG, 'rclone.stat: path: {}'.format(path))
176
+ ret = {}
177
+ chsum = None
178
+ if path.startswith('rclone://'):
179
+ path = self.pfn2path(path)
180
+
181
+ try:
182
+ # rclone stat for getting filesize
183
+ cmd = 'rclone size {0}:{1}'.format(self.hostname, path)
184
+ self.logger(logging.DEBUG, 'rclone.stat: filesize cmd: {}'.format(cmd))
185
+ status_stat, out, err = execute(cmd)
186
+ if status_stat == 0:
187
+ fsize = (out.split('\n')[1]).split(' ')[4][1:]
188
+ ret['filesize'] = fsize
189
+
190
+ # rclone query checksum for getting md5 checksum
191
+ cmd = 'rclone md5sum %s:%s' % (self.hostname, path)
192
+ self.logger(logging.DEBUG, 'rclone.stat: checksum cmd: {}'.format(cmd))
193
+ status_query, out, err = execute(cmd)
194
+
195
+ if status_query == 0:
196
+ chsum = 'md5'
197
+ val = out.strip(' ').split()
198
+ ret[chsum] = val[0]
199
+
200
+ except Exception as e:
201
+ raise exception.ServiceUnavailable(e)
202
+
203
+ if 'filesize' not in ret:
204
+ raise exception.ServiceUnavailable('Filesize could not be retrieved.')
205
+ if PREFERRED_CHECKSUM != chsum or not chsum:
206
+ msg = '{} does not match with {}'.format(chsum, PREFERRED_CHECKSUM)
207
+ raise exception.RSEChecksumUnavailable(msg)
208
+
209
+ return ret
210
+
211
+ def pfn2path(self, pfn):
212
+ """
213
+ Returns the path of a file given the pfn, i.e. scheme, user and hostname are subtracted from the pfn.
214
+
215
+ :param path: pfn of a file
216
+
217
+ :returns: path.
218
+ """
219
+ path = pfn
220
+ if pfn.startswith('rclone://'):
221
+ self.logger(logging.DEBUG, 'rclone.pfn2path: pfn: {}'.format(pfn))
222
+ prefix = self.attributes['prefix']
223
+ path = pfn.partition(self.attributes['prefix'])[2]
224
+ path = prefix + path
225
+ return path
226
+
227
+ def lfns2pfns(self, lfns):
228
+ """
229
+ Returns a fully qualified PFN for the file referred by path.
230
+
231
+ :param path: The path to the file.
232
+
233
+ :returns: Fully qualified PFN.
234
+ """
235
+ self.logger(logging.DEBUG, 'rclone.lfns2pfns: lfns: {}'.format(lfns))
236
+ pfns = {}
237
+ prefix = self.attributes['prefix']
238
+
239
+ if not prefix.startswith('/'):
240
+ prefix = ''.join(['/', prefix])
241
+ if not prefix.endswith('/'):
242
+ prefix = ''.join([prefix, '/'])
243
+
244
+ lfns = [lfns] if isinstance(lfns, dict) else lfns
245
+ for lfn in lfns:
246
+ scope, name = lfn['scope'], lfn['name']
247
+ if 'path' in lfn and lfn['path'] is not None:
248
+ pfns['%s:%s' % (scope, name)] = ''.join([self.attributes['scheme'], '://', self.host, ':', prefix, lfn['path']])
249
+ else:
250
+ pfns['%s:%s' % (scope, name)] = ''.join([self.attributes['scheme'], '://', self.host, ':', prefix, self._get_path(scope=scope, name=name)])
251
+ return pfns
252
+
253
+ def connect(self):
254
+ """ Establishes the actual connection to the referred RSE.
255
+
256
+ :raises RSEAccessDenied
257
+ """
258
+ self.logger(logging.DEBUG, 'rclone.connect: hostname {}'.format(self.hostname))
259
+ try:
260
+ cmd = 'rclone lsd %s:' % (self.hostname)
261
+ status, out, err = execute(cmd)
262
+ if status:
263
+ raise exception.RSEAccessDenied(err)
264
+ except Exception as e:
265
+ raise exception.RSEAccessDenied(e)
266
+
267
+ def close(self):
268
+ """ Closes the connection to RSE."""
269
+ pass
270
+
271
+ def get(self, pfn, dest, transfer_timeout=None):
272
+ """ Provides access to files stored inside connected the RSE.
273
+
274
+ :param pfn: Physical file name of requested file
275
+ :param dest: Name and path of the files when stored at the client
276
+ :param transfer_timeout: Transfer timeout (in seconds) - dummy
277
+
278
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound
279
+ """
280
+ self.logger(logging.DEBUG, 'rclone.get: pfn: {}'.format(pfn))
281
+ try:
282
+ path = self.pfn2path(pfn)
283
+ cmd = 'rclone copyto %s:%s %s' % (self.hostname, path, dest)
284
+ self.logger(logging.DEBUG, 'rclone.get: cmd: {}'.format(cmd))
285
+ status, out, err = execute(cmd)
286
+ if status:
287
+ raise exception.RucioException(err)
288
+ except Exception as e:
289
+ raise exception.ServiceUnavailable(e)
290
+
291
+ def put(self, filename, target, source_dir, transfer_timeout=None):
292
+ """
293
+ Allows to store files inside the referred RSE.
294
+
295
+ :param source: path to the source file on the client file system
296
+ :param target: path to the destination file on the storage
297
+ :param source_dir: Path where the to be transferred files are stored in the local file system
298
+ :param transfer_timeout: Transfer timeout (in seconds) - dummy
299
+
300
+ :raises DestinationNotAccessible: if the destination storage was not accessible.
301
+ :raises ServiceUnavailable: if some generic error occurred in the library.
302
+ :raises SourceNotFound: if the source file was not found on the referred storage.
303
+ """
304
+ self.logger(logging.DEBUG, 'rclone.put: filename: {} target: {}'.format(filename, target))
305
+ source_dir = source_dir or '.'
306
+ source_url = '%s/%s' % (source_dir, filename)
307
+ self.logger(logging.DEBUG, 'rclone.put: source url: {}'.format(source_url))
308
+
309
+ path = self.pfn2path(target)
310
+ if not os.path.exists(source_url):
311
+ raise exception.SourceNotFound()
312
+ try:
313
+ cmd = 'rclone copyto %s %s:%s' % (source_url, self.hostname, path)
314
+ self.logger(logging.DEBUG, 'rclone.put: cmd: {}'.format(cmd))
315
+ status, out, err = execute(cmd)
316
+ if status:
317
+ raise exception.RucioException(err)
318
+ except Exception as e:
319
+ raise exception.ServiceUnavailable(e)
320
+
321
+ def delete(self, pfn):
322
+ """
323
+ Deletes a file from the connected RSE.
324
+
325
+ :param pfn: Physical file name
326
+
327
+ :raises ServiceUnavailable: if some generic error occurred in the library.
328
+ :raises SourceNotFound: if the source file was not found on the referred storage.
329
+ """
330
+ self.logger(logging.DEBUG, 'rclone.delete: pfn: {}'.format(pfn))
331
+ if not self.exists(pfn):
332
+ raise exception.SourceNotFound()
333
+ try:
334
+ path = self.pfn2path(pfn)
335
+ cmd = 'rclone delete %s:%s' % (self.hostname, path)
336
+ self.logger(logging.DEBUG, 'rclone.delete: cmd: {}'.format(cmd))
337
+ status, out, err = execute(cmd)
338
+ if status != 0:
339
+ raise exception.RucioException(err)
340
+ except Exception as e:
341
+ raise exception.ServiceUnavailable(e)
342
+
343
+ def rename(self, pfn, new_pfn):
344
+ """ Allows to rename a file stored inside the connected RSE.
345
+
346
+ :param pfn: Current physical file name
347
+ :param new_pfn New physical file name
348
+ :raises DestinationNotAccessible: if the destination storage was not accessible.
349
+ :raises ServiceUnavailable: if some generic error occurred in the library.
350
+ :raises SourceNotFound: if the source file was not found on the referred storage.
351
+ """
352
+ self.logger(logging.DEBUG, 'rclone.rename: pfn: {}'.format(pfn))
353
+ if not self.exists(pfn):
354
+ raise exception.SourceNotFound()
355
+ try:
356
+ path = self.pfn2path(pfn)
357
+ new_path = self.pfn2path(new_pfn)
358
+ cmd = 'rclone moveto %s:%s %s:%s' % (self.hostname, path, self.hostname, new_path)
359
+ self.logger(logging.DEBUG, 'rclone.stat: rename cmd: {}'.format(cmd))
360
+ status, out, err = execute(cmd)
361
+ if status != 0:
362
+ raise exception.RucioException(err)
363
+ except Exception as e:
364
+ raise exception.ServiceUnavailable(e)
@@ -0,0 +1,136 @@
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
+ """
16
+ RFIO protocol
17
+ """
18
+
19
+ import os
20
+ from os.path import dirname
21
+ from urllib.parse import urlparse
22
+
23
+ from rucio.common import exception
24
+ from rucio.common.utils import execute
25
+ from rucio.rse.protocols import protocol
26
+
27
+
28
+ class Default(protocol.RSEProtocol):
29
+ """ Implementing access to RSEs using the RFIO protocol. """
30
+
31
+ def connect(self, credentials):
32
+ """
33
+ Establishes the actual connection to the referred RSE.
34
+
35
+ :param credentials: needed to establish a connection with the storage.
36
+
37
+ :raises RSEAccessDenied: if no connection could be established.
38
+ """
39
+ extended_attributes = self.rse['protocol']['extended_attributes']
40
+ if 'STAGE_SVCCLASS' in extended_attributes:
41
+ os.environ['STAGE_SVCCLASS'] = extended_attributes['STAGE_SVCCLASS']
42
+
43
+ def path2pfn(self, path):
44
+ """
45
+ Returns a fully qualified PFN for the file referred by path.
46
+
47
+ :param path: The path to the file.
48
+
49
+ :returns: Fully qualified PFN.
50
+
51
+ """
52
+ return ''.join([self.rse['scheme'], '://', path])
53
+
54
+ def exists(self, path):
55
+ """
56
+ Checks if the requested file is known by the referred RSE.
57
+
58
+ :param path: Physical file name
59
+
60
+ :returns: True if the file exists, False if it doesn't
61
+
62
+ :raises SourceNotFound: if the source file was not found on the referred storage.
63
+ """
64
+ cmd = f'rfstat {path}'
65
+ status, out, err = execute(cmd)
66
+ return status == 0
67
+
68
+ def close(self):
69
+ """ Closes the connection to RSE."""
70
+ if 'STAGE_SVCCLASS' in os.environ:
71
+ del os.environ['STAGE_SVCCLASS']
72
+
73
+ def put(self, source, target, source_dir, transfer_timeout=None):
74
+ """
75
+ Allows to store files inside the referred RSE.
76
+
77
+ :param source: path to the source file on the client file system
78
+ :param target: path to the destination file on the storage
79
+ :param source_dir: Path where the to be transferred files are stored in the local file system
80
+ :param transfer_timeout: Transfer timeout (in seconds) - dummy
81
+
82
+ :raises DestinationNotAccessible: if the destination storage was not accessible.
83
+ :raises ServiceUnavailable: if some generic error occurred in the library.
84
+ :raises SourceNotFound: if the source file was not found on the referred storage.
85
+ """
86
+ if not self.exists(dirname(target)):
87
+ self.mkdir(dirname(target))
88
+
89
+ cmd = f'rfcp {source} {target}'
90
+ status, out, err = execute(cmd)
91
+ return status == 0
92
+
93
+ def mkdir(self, directory):
94
+ """ Create new directory. """
95
+ cmd = f'rfmkdir -p {directory}'
96
+ status, out, err = execute(cmd)
97
+ return status == 0
98
+
99
+ def split_pfn(self, pfn):
100
+ """
101
+ Splits the given PFN into the parts known by the protocol. During parsing the PFN is also checked for
102
+ validity on the given RSE with the given protocol.
103
+
104
+ :param pfn: a fully qualified PFN
105
+
106
+ :returns: a dict containing all known parts of the PFN for the protocol e.g. scheme, hostname, port, prefix, path, filename
107
+
108
+ :raises RSEFileNameNotSupported: if the provided PFN doesn't match with the protocol settings
109
+ """
110
+ parsed = urlparse(pfn)
111
+ ret = dict()
112
+ ret['scheme'] = parsed.scheme
113
+ ret['hostname'] = parsed.netloc.partition(':')[0]
114
+ ret['port'] = int(parsed.netloc.partition(':')[2]) if parsed.netloc.partition(':')[2] != '' else 0
115
+ ret['path'] = parsed.path
116
+
117
+ # Protect against 'lazy' defined prefixes for RSEs in the repository
118
+ self.rse['prefix'] = '' if self.rse['prefix'] is None else self.rse['prefix']
119
+ if not self.rse['prefix'].startswith('/'):
120
+ self.rse['prefix'] = '/' + self.rse['prefix']
121
+ if not self.rse['prefix'].endswith('/'):
122
+ self.rse['prefix'] += '/'
123
+
124
+ if self.rse['hostname'] != ret['hostname']:
125
+ raise exception.RSEFileNameNotSupported('Invalid hostname: provided \'%s\', expected \'%s\'' % (ret['hostname'], self.rse['hostname']))
126
+
127
+ if not ret['path'].startswith(self.rse['prefix']):
128
+ raise exception.RSEFileNameNotSupported('Invalid prefix: provided \'%s\', expected \'%s\'' % ('/'.join(ret['path'].split('/')[0:len(self.rse['prefix'].split('/')) - 1]),
129
+ self.rse['prefix'])) # len(...)-1 due to the leading '/
130
+ # Splitting parsed.path into prefix, path, filename
131
+ ret['prefix'] = self.rse['prefix']
132
+ ret['path'] = ret['path'].partition(self.rse['prefix'])[2]
133
+ ret['name'] = ret['path'].split('/')[-1]
134
+ ret['path'] = ret['path'].partition(ret['name'])[0]
135
+
136
+ return ret