root / kamaki / cli / commands / pithos.py @ 00b1248e
History | View | Annotate | Download (80.2 kB)
1 | e3f01d64 | Stavros Sachtouris | # Copyright 2011-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 7493ccb6 | Stavros Sachtouris | #
|
3 | 7493ccb6 | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | 7493ccb6 | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | 7493ccb6 | Stavros Sachtouris | # conditions are met:
|
6 | 7493ccb6 | Stavros Sachtouris | #
|
7 | 7493ccb6 | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | 7493ccb6 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | 7493ccb6 | Stavros Sachtouris | # disclaimer.
|
10 | 7493ccb6 | Stavros Sachtouris | #
|
11 | 7493ccb6 | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | 7493ccb6 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | 7493ccb6 | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | 7493ccb6 | Stavros Sachtouris | # provided with the distribution.
|
15 | 7493ccb6 | Stavros Sachtouris | #
|
16 | 7493ccb6 | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 7493ccb6 | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 7493ccb6 | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 7493ccb6 | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 7493ccb6 | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 7493ccb6 | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 7493ccb6 | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 7493ccb6 | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 7493ccb6 | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 7493ccb6 | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 7493ccb6 | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 7493ccb6 | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 7493ccb6 | Stavros Sachtouris | #
|
29 | 7493ccb6 | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | 7493ccb6 | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | 7493ccb6 | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | 7493ccb6 | Stavros Sachtouris | # or implied, of GRNET S.A.command
|
33 | 7493ccb6 | Stavros Sachtouris | |
34 | 1395c40e | Stavros Sachtouris | from time import localtime, strftime |
35 | b666ef82 | Stavros Sachtouris | from os import path, makedirs, walk |
36 | fa9c0c38 | Stavros Sachtouris | from io import StringIO |
37 | 76f58e2e | Stavros Sachtouris | from pydoc import pager |
38 | 1395c40e | Stavros Sachtouris | |
39 | 234954d1 | Stavros Sachtouris | from kamaki.cli import command |
40 | d486baec | Stavros Sachtouris | from kamaki.cli.command_tree import CommandTree |
41 | 8694bdad | Stavros Sachtouris | from kamaki.cli.errors import ( |
42 | 8694bdad | Stavros Sachtouris | raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument) |
43 | 7147e1ca | Stavros Sachtouris | from kamaki.cli.utils import ( |
44 | 76f58e2e | Stavros Sachtouris | format_size, to_bytes, bold, get_path_size, guess_mime_type) |
45 | e3d4d442 | Stavros Sachtouris | from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
46 | 04d01cd4 | Stavros Sachtouris | from kamaki.cli.argument import KeyValueArgument, DateArgument |
47 | fd1f1d96 | Stavros Sachtouris | from kamaki.cli.argument import ProgressBarArgument |
48 | 545c6c29 | Stavros Sachtouris | from kamaki.cli.commands import _command_init, errors |
49 | b4f69041 | Stavros Sachtouris | from kamaki.cli.commands import addLogSettings, DontRaiseKeyError |
50 | 6d190dd1 | Stavros Sachtouris | from kamaki.cli.commands import ( |
51 | 6d190dd1 | Stavros Sachtouris | _optional_output_cmd, _optional_json, _name_filter) |
52 | 7493ccb6 | Stavros Sachtouris | from kamaki.clients.pithos import PithosClient, ClientError |
53 | 1f5debf7 | Stavros Sachtouris | from kamaki.clients.astakos import AstakosClient |
54 | 1395c40e | Stavros Sachtouris | |
55 | a29d2f88 | Stavros Sachtouris | pithos_cmds = CommandTree('file', 'Pithos+/Storage API commands') |
56 | d486baec | Stavros Sachtouris | _commands = [pithos_cmds] |
57 | 234954d1 | Stavros Sachtouris | |
58 | 7493ccb6 | Stavros Sachtouris | |
59 | 234954d1 | Stavros Sachtouris | # Argument functionality
|
60 | 234954d1 | Stavros Sachtouris | |
61 | 234954d1 | Stavros Sachtouris | |
62 | befed235 | Stavros Sachtouris | class SharingArgument(ValueArgument): |
63 | befed235 | Stavros Sachtouris | """Set sharing (read and/or write) groups
|
64 | 439826ec | Stavros Sachtouris | .
|
65 | befed235 | Stavros Sachtouris | :value type: "read=term1,term2,... write=term1,term2,..."
|
66 | 439826ec | Stavros Sachtouris | .
|
67 | befed235 | Stavros Sachtouris | :value returns: {'read':['term1', 'term2', ...],
|
68 | 439826ec | Stavros Sachtouris | . 'write':['term1', 'term2', ...]}
|
69 | befed235 | Stavros Sachtouris | """
|
70 | 234954d1 | Stavros Sachtouris | |
71 | 234954d1 | Stavros Sachtouris | @property
|
72 | e3d4d442 | Stavros Sachtouris | def value(self): |
73 | e3d4d442 | Stavros Sachtouris | return getattr(self, '_value', self.default) |
74 | 234954d1 | Stavros Sachtouris | |
75 | e3d4d442 | Stavros Sachtouris | @value.setter
|
76 | e3d4d442 | Stavros Sachtouris | def value(self, newvalue): |
77 | e3d4d442 | Stavros Sachtouris | perms = {} |
78 | e3d4d442 | Stavros Sachtouris | try:
|
79 | e3d4d442 | Stavros Sachtouris | permlist = newvalue.split(' ')
|
80 | e3d4d442 | Stavros Sachtouris | except AttributeError: |
81 | e3d4d442 | Stavros Sachtouris | return
|
82 | e3d4d442 | Stavros Sachtouris | for p in permlist: |
83 | e3d4d442 | Stavros Sachtouris | try:
|
84 | 234954d1 | Stavros Sachtouris | (key, val) = p.split('=')
|
85 | 83ba5545 | Stavros Sachtouris | except ValueError as err: |
86 | 24ff0a35 | Stavros Sachtouris | raiseCLIError( |
87 | 24ff0a35 | Stavros Sachtouris | err, |
88 | 24ff0a35 | Stavros Sachtouris | 'Error in --sharing',
|
89 | 234954d1 | Stavros Sachtouris | details='Incorrect format',
|
90 | 234954d1 | Stavros Sachtouris | importance=1)
|
91 | e3d4d442 | Stavros Sachtouris | if key.lower() not in ('read', 'write'): |
92 | de73876b | Stavros Sachtouris | msg = 'Error in --sharing'
|
93 | de73876b | Stavros Sachtouris | raiseCLIError(err, msg, importance=1, details=[
|
94 | de73876b | Stavros Sachtouris | 'Invalid permission key %s' % key])
|
95 | e3d4d442 | Stavros Sachtouris | val_list = val.split(',')
|
96 | 234954d1 | Stavros Sachtouris | if not key in perms: |
97 | 234954d1 | Stavros Sachtouris | perms[key] = [] |
98 | e3d4d442 | Stavros Sachtouris | for item in val_list: |
99 | e3d4d442 | Stavros Sachtouris | if item not in perms[key]: |
100 | e3d4d442 | Stavros Sachtouris | perms[key].append(item) |
101 | e3d4d442 | Stavros Sachtouris | self._value = perms
|
102 | e3d4d442 | Stavros Sachtouris | |
103 | 234954d1 | Stavros Sachtouris | |
104 | e3d4d442 | Stavros Sachtouris | class RangeArgument(ValueArgument): |
105 | befed235 | Stavros Sachtouris | """
|
106 | 439826ec | Stavros Sachtouris | :value type: string of the form <start>-<end> where <start> and <end> are
|
107 | 439826ec | Stavros Sachtouris | integers
|
108 | befed235 | Stavros Sachtouris | :value returns: the input string, after type checking <start> and <end>
|
109 | befed235 | Stavros Sachtouris | """
|
110 | befed235 | Stavros Sachtouris | |
111 | 234954d1 | Stavros Sachtouris | @property
|
112 | e3d4d442 | Stavros Sachtouris | def value(self): |
113 | e3d4d442 | Stavros Sachtouris | return getattr(self, '_value', self.default) |
114 | 234954d1 | Stavros Sachtouris | |
115 | e3d4d442 | Stavros Sachtouris | @value.setter
|
116 | 776b275c | Stavros Sachtouris | def value(self, newvalues): |
117 | 776b275c | Stavros Sachtouris | if not newvalues: |
118 | e3d4d442 | Stavros Sachtouris | self._value = self.default |
119 | e3d4d442 | Stavros Sachtouris | return
|
120 | 776b275c | Stavros Sachtouris | self._value = '' |
121 | 776b275c | Stavros Sachtouris | for newvalue in newvalues.split(','): |
122 | 776b275c | Stavros Sachtouris | self._value = ('%s,' % self._value) if self._value else '' |
123 | 776b275c | Stavros Sachtouris | start, sep, end = newvalue.partition('-')
|
124 | 776b275c | Stavros Sachtouris | if sep:
|
125 | 776b275c | Stavros Sachtouris | if start:
|
126 | 776b275c | Stavros Sachtouris | start, end = (int(start), int(end)) |
127 | 776b275c | Stavros Sachtouris | assert start <= end, 'Invalid range value %s' % newvalue |
128 | 776b275c | Stavros Sachtouris | self._value += '%s-%s' % (int(start), int(end)) |
129 | 776b275c | Stavros Sachtouris | else:
|
130 | 776b275c | Stavros Sachtouris | self._value += '-%s' % int(end) |
131 | 7806f19d | Stavros Sachtouris | else:
|
132 | 776b275c | Stavros Sachtouris | self._value += '%s' % int(start) |
133 | 234954d1 | Stavros Sachtouris | |
134 | 201baa17 | Stavros Sachtouris | |
135 | 234954d1 | Stavros Sachtouris | # Command specs
|
136 | 234954d1 | Stavros Sachtouris | |
137 | e3d4d442 | Stavros Sachtouris | |
138 | 5eae854d | Stavros Sachtouris | class _pithos_init(_command_init): |
139 | befed235 | Stavros Sachtouris | """Initialize a pithos+ kamaki client"""
|
140 | befed235 | Stavros Sachtouris | |
141 | ece4ae4b | Stavros Sachtouris | @staticmethod
|
142 | ece4ae4b | Stavros Sachtouris | def _is_dir(remote_dict): |
143 | ece4ae4b | Stavros Sachtouris | return 'application/directory' == remote_dict.get( |
144 | 8cec3671 | Stavros Sachtouris | 'content_type', remote_dict.get('content-type', '')) |
145 | ece4ae4b | Stavros Sachtouris | |
146 | b4f69041 | Stavros Sachtouris | @DontRaiseKeyError
|
147 | b4f69041 | Stavros Sachtouris | def _custom_container(self): |
148 | 144b3551 | Stavros Sachtouris | return self.config.get_cloud(self.cloud, 'pithos_container') |
149 | b4f69041 | Stavros Sachtouris | |
150 | b4f69041 | Stavros Sachtouris | @DontRaiseKeyError
|
151 | b4f69041 | Stavros Sachtouris | def _custom_uuid(self): |
152 | 144b3551 | Stavros Sachtouris | return self.config.get_cloud(self.cloud, 'pithos_uuid') |
153 | b4f69041 | Stavros Sachtouris | |
154 | b4f69041 | Stavros Sachtouris | def _set_account(self): |
155 | b4f69041 | Stavros Sachtouris | self.account = self._custom_uuid() |
156 | b4f69041 | Stavros Sachtouris | if self.account: |
157 | b4f69041 | Stavros Sachtouris | return
|
158 | b4f69041 | Stavros Sachtouris | if getattr(self, 'auth_base', False): |
159 | b4f69041 | Stavros Sachtouris | self.account = self.auth_base.user_term('id', self.token) |
160 | b4f69041 | Stavros Sachtouris | else:
|
161 | b4f69041 | Stavros Sachtouris | astakos_url = self._custom_url('astakos') |
162 | b4f69041 | Stavros Sachtouris | astakos_token = self._custom_token('astakos') or self.token |
163 | b4f69041 | Stavros Sachtouris | if not astakos_url: |
164 | b4f69041 | Stavros Sachtouris | raise CLIBaseUrlError(service='astakos') |
165 | b4f69041 | Stavros Sachtouris | astakos = AstakosClient(astakos_url, astakos_token) |
166 | b4f69041 | Stavros Sachtouris | self.account = astakos.user_term('id') |
167 | b4f69041 | Stavros Sachtouris | |
168 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
169 | b4f69041 | Stavros Sachtouris | @addLogSettings
|
170 | 1395c40e | Stavros Sachtouris | def _run(self): |
171 | b4f69041 | Stavros Sachtouris | self.base_url = None |
172 | b4f69041 | Stavros Sachtouris | if getattr(self, 'cloud', None): |
173 | b4f69041 | Stavros Sachtouris | self.base_url = self._custom_url('pithos') |
174 | b4f69041 | Stavros Sachtouris | else:
|
175 | b4f69041 | Stavros Sachtouris | self.cloud = 'default' |
176 | b4f69041 | Stavros Sachtouris | self.token = self._custom_token('pithos') |
177 | b4f69041 | Stavros Sachtouris | self.container = self._custom_container() |
178 | 8cec3671 | Stavros Sachtouris | |
179 | 8cec3671 | Stavros Sachtouris | if getattr(self, 'auth_base', False): |
180 | b4f69041 | Stavros Sachtouris | self.token = self.token or self.auth_base.token |
181 | b4f69041 | Stavros Sachtouris | if not self.base_url: |
182 | b4f69041 | Stavros Sachtouris | pithos_endpoints = self.auth_base.get_service_endpoints(
|
183 | b4f69041 | Stavros Sachtouris | self._custom_type('pithos') or 'object-store', |
184 | b4f69041 | Stavros Sachtouris | self._custom_version('pithos') or '') |
185 | b4f69041 | Stavros Sachtouris | self.base_url = pithos_endpoints['publicURL'] |
186 | b4f69041 | Stavros Sachtouris | elif not self.base_url: |
187 | 8cec3671 | Stavros Sachtouris | raise CLIBaseUrlError(service='pithos') |
188 | 8cec3671 | Stavros Sachtouris | |
189 | 1f5debf7 | Stavros Sachtouris | self._set_account()
|
190 | de73876b | Stavros Sachtouris | self.client = PithosClient(
|
191 | de73876b | Stavros Sachtouris | base_url=self.base_url,
|
192 | 234954d1 | Stavros Sachtouris | token=self.token,
|
193 | 234954d1 | Stavros Sachtouris | account=self.account,
|
194 | 7493ccb6 | Stavros Sachtouris | container=self.container)
|
195 | 7493ccb6 | Stavros Sachtouris | |
196 | 1395c40e | Stavros Sachtouris | def main(self): |
197 | 1395c40e | Stavros Sachtouris | self._run()
|
198 | 1395c40e | Stavros Sachtouris | |
199 | 234954d1 | Stavros Sachtouris | |
200 | 3ae60112 | Stavros Sachtouris | class _file_account_command(_pithos_init): |
201 | 7493ccb6 | Stavros Sachtouris | """Base class for account level storage commands"""
|
202 | 7493ccb6 | Stavros Sachtouris | |
203 | b4f69041 | Stavros Sachtouris | def __init__(self, arguments={}, auth_base=None, cloud=None): |
204 | b4f69041 | Stavros Sachtouris | super(_file_account_command, self).__init__( |
205 | b4f69041 | Stavros Sachtouris | arguments, auth_base, cloud) |
206 | 439826ec | Stavros Sachtouris | self['account'] = ValueArgument( |
207 | 201baa17 | Stavros Sachtouris | 'Set user account (not permanent)', ('-A', '--account')) |
208 | 7493ccb6 | Stavros Sachtouris | |
209 | 3ed6dbde | Stavros Sachtouris | def _run(self, custom_account=None): |
210 | 3ae60112 | Stavros Sachtouris | super(_file_account_command, self)._run() |
211 | 3ed6dbde | Stavros Sachtouris | if custom_account:
|
212 | 3ed6dbde | Stavros Sachtouris | self.client.account = custom_account
|
213 | 3ed6dbde | Stavros Sachtouris | elif self['account']: |
214 | 47ae7577 | Stavros Sachtouris | self.client.account = self['account'] |
215 | 7493ccb6 | Stavros Sachtouris | |
216 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
217 | 1395c40e | Stavros Sachtouris | def main(self): |
218 | 1395c40e | Stavros Sachtouris | self._run()
|
219 | 1395c40e | Stavros Sachtouris | |
220 | 234954d1 | Stavros Sachtouris | |
221 | 3ae60112 | Stavros Sachtouris | class _file_container_command(_file_account_command): |
222 | 7493ccb6 | Stavros Sachtouris | """Base class for container level storage commands"""
|
223 | 7493ccb6 | Stavros Sachtouris | |
224 | 47ae7577 | Stavros Sachtouris | container = None
|
225 | 47ae7577 | Stavros Sachtouris | path = None
|
226 | 2d7ce81e | Stavros Sachtouris | |
227 | b4f69041 | Stavros Sachtouris | def __init__(self, arguments={}, auth_base=None, cloud=None): |
228 | b4f69041 | Stavros Sachtouris | super(_file_container_command, self).__init__( |
229 | b4f69041 | Stavros Sachtouris | arguments, auth_base, cloud) |
230 | 439826ec | Stavros Sachtouris | self['container'] = ValueArgument( |
231 | 201baa17 | Stavros Sachtouris | 'Set container to work with (temporary)', ('-C', '--container')) |
232 | 7493ccb6 | Stavros Sachtouris | |
233 | de73876b | Stavros Sachtouris | def extract_container_and_path( |
234 | b8352ce4 | Stavros Sachtouris | self, container_with_path, path_is_optional=True): |
235 | 1395c40e | Stavros Sachtouris | """Contains all heuristics for deciding what should be used as
|
236 | 1395c40e | Stavros Sachtouris | container or path. Options are:
|
237 | 1395c40e | Stavros Sachtouris | * user string of the form container:path
|
238 | 1395c40e | Stavros Sachtouris | * self.container, self.path variables set by super constructor, or
|
239 | 1395c40e | Stavros Sachtouris | explicitly by the caller application
|
240 | 1395c40e | Stavros Sachtouris | Error handling is explicit as these error cases happen only here
|
241 | 1395c40e | Stavros Sachtouris | """
|
242 | 83ba5545 | Stavros Sachtouris | try:
|
243 | 83ba5545 | Stavros Sachtouris | assert isinstance(container_with_path, str) |
244 | 83ba5545 | Stavros Sachtouris | except AssertionError as err: |
245 | edab7ba7 | Stavros Sachtouris | if self['container'] and path_is_optional: |
246 | edab7ba7 | Stavros Sachtouris | self.container = self['container'] |
247 | edab7ba7 | Stavros Sachtouris | self.client.container = self['container'] |
248 | edab7ba7 | Stavros Sachtouris | return
|
249 | 83ba5545 | Stavros Sachtouris | raiseCLIError(err) |
250 | 447c9568 | Stavros Sachtouris | |
251 | 1395c40e | Stavros Sachtouris | user_cont, sep, userpath = container_with_path.partition(':')
|
252 | 447c9568 | Stavros Sachtouris | |
253 | 447c9568 | Stavros Sachtouris | if sep:
|
254 | 1395c40e | Stavros Sachtouris | if not user_cont: |
255 | 2005b18e | Stavros Sachtouris | raiseCLIError(CLISyntaxError( |
256 | 2005b18e | Stavros Sachtouris | 'Container is missing\n',
|
257 | 1395c40e | Stavros Sachtouris | details=errors.pithos.container_howto)) |
258 | 47ae7577 | Stavros Sachtouris | alt_cont = self['container'] |
259 | 1395c40e | Stavros Sachtouris | if alt_cont and user_cont != alt_cont: |
260 | c1558584 | Stavros Sachtouris | raiseCLIError(CLISyntaxError( |
261 | 1395c40e | Stavros Sachtouris | 'Conflict: 2 containers (%s, %s)' % (user_cont, alt_cont),
|
262 | 1395c40e | Stavros Sachtouris | details=errors.pithos.container_howto) |
263 | 47ae7577 | Stavros Sachtouris | ) |
264 | 1395c40e | Stavros Sachtouris | self.container = user_cont
|
265 | 1395c40e | Stavros Sachtouris | if not userpath: |
266 | c1558584 | Stavros Sachtouris | raiseCLIError(CLISyntaxError( |
267 | 1395c40e | Stavros Sachtouris | 'Path is missing for object in container %s' % user_cont,
|
268 | 1395c40e | Stavros Sachtouris | details=errors.pithos.container_howto) |
269 | 47ae7577 | Stavros Sachtouris | ) |
270 | 1395c40e | Stavros Sachtouris | self.path = userpath
|
271 | 447c9568 | Stavros Sachtouris | else:
|
272 | 47ae7577 | Stavros Sachtouris | alt_cont = self['container'] or self.client.container |
273 | 447c9568 | Stavros Sachtouris | if alt_cont:
|
274 | 447c9568 | Stavros Sachtouris | self.container = alt_cont
|
275 | 1395c40e | Stavros Sachtouris | self.path = user_cont
|
276 | 447c9568 | Stavros Sachtouris | elif path_is_optional:
|
277 | 1395c40e | Stavros Sachtouris | self.container = user_cont
|
278 | 7493ccb6 | Stavros Sachtouris | self.path = None |
279 | 7493ccb6 | Stavros Sachtouris | else:
|
280 | 1395c40e | Stavros Sachtouris | self.container = user_cont
|
281 | 447c9568 | Stavros Sachtouris | raiseCLIError(CLISyntaxError( |
282 | c1558584 | Stavros Sachtouris | 'Both container and path are required',
|
283 | 1395c40e | Stavros Sachtouris | details=errors.pithos.container_howto) |
284 | 47ae7577 | Stavros Sachtouris | ) |
285 | 7493ccb6 | Stavros Sachtouris | |
286 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
287 | 1395c40e | Stavros Sachtouris | def _run(self, container_with_path=None, path_is_optional=True): |
288 | 3ae60112 | Stavros Sachtouris | super(_file_container_command, self)._run() |
289 | edab7ba7 | Stavros Sachtouris | if self['container']: |
290 | edab7ba7 | Stavros Sachtouris | self.client.container = self['container'] |
291 | edab7ba7 | Stavros Sachtouris | if container_with_path:
|
292 | edab7ba7 | Stavros Sachtouris | self.path = container_with_path
|
293 | edab7ba7 | Stavros Sachtouris | elif not path_is_optional: |
294 | edab7ba7 | Stavros Sachtouris | raise CLISyntaxError(
|
295 | edab7ba7 | Stavros Sachtouris | 'Both container and path are required',
|
296 | edab7ba7 | Stavros Sachtouris | details=errors.pithos.container_howto) |
297 | edab7ba7 | Stavros Sachtouris | elif container_with_path:
|
298 | 47ae7577 | Stavros Sachtouris | self.extract_container_and_path(
|
299 | 47ae7577 | Stavros Sachtouris | container_with_path, |
300 | 234954d1 | Stavros Sachtouris | path_is_optional) |
301 | 7493ccb6 | Stavros Sachtouris | self.client.container = self.container |
302 | 7493ccb6 | Stavros Sachtouris | self.container = self.client.container |
303 | 7493ccb6 | Stavros Sachtouris | |
304 | 1395c40e | Stavros Sachtouris | def main(self, container_with_path=None, path_is_optional=True): |
305 | 1395c40e | Stavros Sachtouris | self._run(container_with_path, path_is_optional)
|
306 | 1395c40e | Stavros Sachtouris | |
307 | 7493ccb6 | Stavros Sachtouris | |
308 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
309 | 6d190dd1 | Stavros Sachtouris | class file_list(_file_container_command, _optional_json, _name_filter): |
310 | 7493ccb6 | Stavros Sachtouris | """List containers, object trees or objects in a directory
|
311 | 2703cceb | Stavros Sachtouris | Use with:
|
312 | 7ae842c2 | Stavros Sachtouris | 1 no parameters : containers in current account
|
313 | 2703cceb | Stavros Sachtouris | 2. one parameter (container) or --container : contents of container
|
314 | 2703cceb | Stavros Sachtouris | 3. <container>:<prefix> or --container=<container> <prefix>: objects in
|
315 | 439826ec | Stavros Sachtouris | . container starting with prefix
|
316 | 7493ccb6 | Stavros Sachtouris | """
|
317 | 7493ccb6 | Stavros Sachtouris | |
318 | 47ae7577 | Stavros Sachtouris | arguments = dict(
|
319 | f40f0cb7 | Stavros Sachtouris | detail=FlagArgument('detailed output', ('-l', '--list')), |
320 | f40f0cb7 | Stavros Sachtouris | limit=IntArgument('limit number of listed items', ('-n', '--number')), |
321 | f40f0cb7 | Stavros Sachtouris | marker=ValueArgument('output greater that marker', '--marker'), |
322 | 47ae7577 | Stavros Sachtouris | delimiter=ValueArgument('show output up to delimiter', '--delimiter'), |
323 | 47ae7577 | Stavros Sachtouris | path=ValueArgument( |
324 | 201baa17 | Stavros Sachtouris | 'show output starting with prefix up to /', '--path'), |
325 | 47ae7577 | Stavros Sachtouris | meta=ValueArgument( |
326 | 201baa17 | Stavros Sachtouris | 'show output with specified meta keys', '--meta', |
327 | 47ae7577 | Stavros Sachtouris | default=[]), |
328 | 47ae7577 | Stavros Sachtouris | if_modified_since=ValueArgument( |
329 | 201baa17 | Stavros Sachtouris | 'show output modified since then', '--if-modified-since'), |
330 | 47ae7577 | Stavros Sachtouris | if_unmodified_since=ValueArgument( |
331 | 201baa17 | Stavros Sachtouris | 'show output not modified since then', '--if-unmodified-since'), |
332 | 47ae7577 | Stavros Sachtouris | until=DateArgument('show metadata until then', '--until'), |
333 | 47ae7577 | Stavros Sachtouris | format=ValueArgument( |
334 | 201baa17 | Stavros Sachtouris | 'format to parse until data (default: d/m/Y H:M:S )', '--format'), |
335 | 47ae7577 | Stavros Sachtouris | shared=FlagArgument('show only shared', '--shared'), |
336 | fa9c0c38 | Stavros Sachtouris | more=FlagArgument('read long results', '--more'), |
337 | eb18b8a7 | Stavros Sachtouris | exact_match=FlagArgument( |
338 | eb18b8a7 | Stavros Sachtouris | 'Show only objects that match exactly with path',
|
339 | ed9af02c | Stavros Sachtouris | '--exact-match'),
|
340 | 8694bdad | Stavros Sachtouris | enum=FlagArgument('Enumerate results', '--enumerate'), |
341 | 8694bdad | Stavros Sachtouris | recursive=FlagArgument( |
342 | 8694bdad | Stavros Sachtouris | 'Recursively list containers and their contents',
|
343 | 8694bdad | Stavros Sachtouris | ('-R', '--recursive')) |
344 | 47ae7577 | Stavros Sachtouris | ) |
345 | c41a86b2 | Stavros Sachtouris | |
346 | 1757c616 | Stavros Sachtouris | def print_objects(self, object_list): |
347 | 234954d1 | Stavros Sachtouris | for index, obj in enumerate(object_list): |
348 | 24ff0a35 | Stavros Sachtouris | if self['exact_match'] and self.path and not ( |
349 | 2005b18e | Stavros Sachtouris | obj['name'] == self.path or 'content_type' in obj): |
350 | 2005b18e | Stavros Sachtouris | continue
|
351 | 7493ccb6 | Stavros Sachtouris | pretty_obj = obj.copy() |
352 | 7493ccb6 | Stavros Sachtouris | index += 1
|
353 | 234954d1 | Stavros Sachtouris | empty_space = ' ' * (len(str(len(object_list))) - len(str(index))) |
354 | a339a3ee | Stavros Sachtouris | if 'subdir' in obj: |
355 | a339a3ee | Stavros Sachtouris | continue
|
356 | 7493ccb6 | Stavros Sachtouris | if obj['content_type'] == 'application/directory': |
357 | 7493ccb6 | Stavros Sachtouris | isDir = True
|
358 | 7493ccb6 | Stavros Sachtouris | size = 'D'
|
359 | 7493ccb6 | Stavros Sachtouris | else:
|
360 | 7493ccb6 | Stavros Sachtouris | isDir = False
|
361 | 7493ccb6 | Stavros Sachtouris | size = format_size(obj['bytes'])
|
362 | 234954d1 | Stavros Sachtouris | pretty_obj['bytes'] = '%s (%s)' % (obj['bytes'], size) |
363 | fa9c0c38 | Stavros Sachtouris | oname = obj['name'] if self['more'] else bold(obj['name']) |
364 | 1757c616 | Stavros Sachtouris | prfx = ( |
365 | 1757c616 | Stavros Sachtouris | '%s%s. ' % (empty_space, index)) if self['enum'] else '' |
366 | 47ae7577 | Stavros Sachtouris | if self['detail']: |
367 | ff1c0296 | Stavros Sachtouris | self.writeln('%s%s' % (prfx, oname)) |
368 | 76f58e2e | Stavros Sachtouris | self.print_dict(pretty_obj, exclude=('name')) |
369 | ff1c0296 | Stavros Sachtouris | self.writeln()
|
370 | 7493ccb6 | Stavros Sachtouris | else:
|
371 | ff1c0296 | Stavros Sachtouris | oname = '%s%9s %s' % (prfx, size, oname)
|
372 | ff1c0296 | Stavros Sachtouris | oname += '/' if isDir else u'' |
373 | ff1c0296 | Stavros Sachtouris | self.writeln(oname)
|
374 | 7493ccb6 | Stavros Sachtouris | |
375 | 1757c616 | Stavros Sachtouris | def print_containers(self, container_list): |
376 | 234954d1 | Stavros Sachtouris | for index, container in enumerate(container_list): |
377 | 234954d1 | Stavros Sachtouris | if 'bytes' in container: |
378 | 234954d1 | Stavros Sachtouris | size = format_size(container['bytes'])
|
379 | ed9af02c | Stavros Sachtouris | prfx = ('%s. ' % (index + 1)) if self['enum'] else '' |
380 | fa9c0c38 | Stavros Sachtouris | _cname = container['name'] if ( |
381 | fa9c0c38 | Stavros Sachtouris | self['more']) else bold(container['name']) |
382 | fa9c0c38 | Stavros Sachtouris | cname = u'%s%s' % (prfx, _cname)
|
383 | 47ae7577 | Stavros Sachtouris | if self['detail']: |
384 | ff1c0296 | Stavros Sachtouris | self.writeln(cname)
|
385 | 7493ccb6 | Stavros Sachtouris | pretty_c = container.copy() |
386 | 234954d1 | Stavros Sachtouris | if 'bytes' in container: |
387 | 234954d1 | Stavros Sachtouris | pretty_c['bytes'] = '%s (%s)' % (container['bytes'], size) |
388 | 76f58e2e | Stavros Sachtouris | self.print_dict(pretty_c, exclude=('name')) |
389 | ff1c0296 | Stavros Sachtouris | self.writeln()
|
390 | 7493ccb6 | Stavros Sachtouris | else:
|
391 | 234954d1 | Stavros Sachtouris | if 'count' in container and 'bytes' in container: |
392 | ff1c0296 | Stavros Sachtouris | self.writeln('%s (%s, %s objects)' % ( |
393 | fa9c0c38 | Stavros Sachtouris | cname, size, container['count']))
|
394 | 7493ccb6 | Stavros Sachtouris | else:
|
395 | ff1c0296 | Stavros Sachtouris | self.writeln(cname)
|
396 | 7afb2611 | Stavros Sachtouris | objects = container.get('objects', [])
|
397 | 7afb2611 | Stavros Sachtouris | if objects:
|
398 | 7afb2611 | Stavros Sachtouris | self.print_objects(objects)
|
399 | 7afb2611 | Stavros Sachtouris | self.writeln('') |
400 | 7493ccb6 | Stavros Sachtouris | |
401 | 8694bdad | Stavros Sachtouris | def _argument_context_check(self): |
402 | 8694bdad | Stavros Sachtouris | container_level_only = ('recursive', )
|
403 | 8694bdad | Stavros Sachtouris | object_level_only = ('delimiter', 'path', 'exact_match') |
404 | 8694bdad | Stavros Sachtouris | details, mistake = [], ''
|
405 | 8694bdad | Stavros Sachtouris | if self.container: |
406 | 8694bdad | Stavros Sachtouris | for term in container_level_only: |
407 | 8694bdad | Stavros Sachtouris | if self[term]: |
408 | 8694bdad | Stavros Sachtouris | details = [ |
409 | 8694bdad | Stavros Sachtouris | 'This is a container-level argument',
|
410 | 8694bdad | Stavros Sachtouris | 'Use it without a <container> parameter']
|
411 | 8694bdad | Stavros Sachtouris | mistake = self.arguments[term]
|
412 | 8694bdad | Stavros Sachtouris | else:
|
413 | 8694bdad | Stavros Sachtouris | for term in object_level_only: |
414 | 7afb2611 | Stavros Sachtouris | if not self['recursive'] and self[term]: |
415 | 8694bdad | Stavros Sachtouris | details = [ |
416 | 8694bdad | Stavros Sachtouris | 'This is an opbject-level argument',
|
417 | 7afb2611 | Stavros Sachtouris | 'Use it with a <container> parameter',
|
418 | 7afb2611 | Stavros Sachtouris | 'or with the -R/--recursive argument']
|
419 | 8694bdad | Stavros Sachtouris | mistake = self.arguments[term]
|
420 | 8694bdad | Stavros Sachtouris | if mistake and details: |
421 | 8694bdad | Stavros Sachtouris | raise CLIInvalidArgument(
|
422 | 8694bdad | Stavros Sachtouris | 'Invalid use of %s argument' % '/'.join(mistake.parsed_name), |
423 | 8694bdad | Stavros Sachtouris | details=details + ['Try --help for more details'])
|
424 | 8694bdad | Stavros Sachtouris | |
425 | 7afb2611 | Stavros Sachtouris | def _create_object_forest(self, container_list): |
426 | 7afb2611 | Stavros Sachtouris | try:
|
427 | 7afb2611 | Stavros Sachtouris | for container in container_list: |
428 | 7afb2611 | Stavros Sachtouris | self.client.container = container['name'] |
429 | 7afb2611 | Stavros Sachtouris | objects = self.client.container_get(
|
430 | 7afb2611 | Stavros Sachtouris | limit=False if self['more'] else self['limit'], |
431 | 7afb2611 | Stavros Sachtouris | marker=self['marker'], |
432 | 7afb2611 | Stavros Sachtouris | delimiter=self['delimiter'], |
433 | 7afb2611 | Stavros Sachtouris | path=self['path'], |
434 | 7afb2611 | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
435 | 7afb2611 | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since'], |
436 | 7afb2611 | Stavros Sachtouris | until=self['until'], |
437 | 7afb2611 | Stavros Sachtouris | meta=self['meta'], |
438 | 7afb2611 | Stavros Sachtouris | show_only_shared=self['shared']) |
439 | 7afb2611 | Stavros Sachtouris | container['objects'] = objects.json
|
440 | 7afb2611 | Stavros Sachtouris | finally:
|
441 | 7afb2611 | Stavros Sachtouris | self.client.container = None |
442 | 7afb2611 | Stavros Sachtouris | |
443 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
444 | 1395c40e | Stavros Sachtouris | @errors.pithos.connection
|
445 | 1395c40e | Stavros Sachtouris | @errors.pithos.object_path
|
446 | 1395c40e | Stavros Sachtouris | @errors.pithos.container
|
447 | 1395c40e | Stavros Sachtouris | def _run(self): |
448 | 1757c616 | Stavros Sachtouris | files, prnt = None, None |
449 | 8694bdad | Stavros Sachtouris | self._argument_context_check()
|
450 | 8694bdad | Stavros Sachtouris | if not self.container: |
451 | 1395c40e | Stavros Sachtouris | r = self.client.account_get(
|
452 | 1395c40e | Stavros Sachtouris | limit=False if self['more'] else self['limit'], |
453 | 1395c40e | Stavros Sachtouris | marker=self['marker'], |
454 | 1395c40e | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
455 | 1395c40e | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since'], |
456 | 1395c40e | Stavros Sachtouris | until=self['until'], |
457 | 1395c40e | Stavros Sachtouris | show_only_shared=self['shared']) |
458 | 1757c616 | Stavros Sachtouris | files, prnt = self._filter_by_name(r.json), self.print_containers |
459 | 7afb2611 | Stavros Sachtouris | if self['recursive']: |
460 | 7afb2611 | Stavros Sachtouris | self._create_object_forest(files)
|
461 | 1395c40e | Stavros Sachtouris | else:
|
462 | 2d7278d0 | Stavros Sachtouris | prefix = ( |
463 | 2d7278d0 | Stavros Sachtouris | self.path if not self['name'] else '') or self['name_pref'] |
464 | 1395c40e | Stavros Sachtouris | r = self.client.container_get(
|
465 | 1395c40e | Stavros Sachtouris | limit=False if self['more'] else self['limit'], |
466 | 1395c40e | Stavros Sachtouris | marker=self['marker'], |
467 | 1395c40e | Stavros Sachtouris | prefix=prefix, |
468 | 1395c40e | Stavros Sachtouris | delimiter=self['delimiter'], |
469 | 1395c40e | Stavros Sachtouris | path=self['path'], |
470 | 1395c40e | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
471 | 1395c40e | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since'], |
472 | 1395c40e | Stavros Sachtouris | until=self['until'], |
473 | 1395c40e | Stavros Sachtouris | meta=self['meta'], |
474 | 1395c40e | Stavros Sachtouris | show_only_shared=self['shared']) |
475 | 1757c616 | Stavros Sachtouris | files, prnt = self._filter_by_name(r.json), self.print_objects |
476 | 1757c616 | Stavros Sachtouris | if self['more']: |
477 | 1757c616 | Stavros Sachtouris | outbu, self._out = self._out, StringIO() |
478 | 1757c616 | Stavros Sachtouris | try:
|
479 | f76c6bbc | Stavros Sachtouris | if self['json_output'] or self['output_format']: |
480 | 1757c616 | Stavros Sachtouris | self._print(files)
|
481 | 1757c616 | Stavros Sachtouris | else:
|
482 | 1757c616 | Stavros Sachtouris | prnt(files) |
483 | 1757c616 | Stavros Sachtouris | finally:
|
484 | 1757c616 | Stavros Sachtouris | if self['more']: |
485 | 1757c616 | Stavros Sachtouris | pager(self._out.getvalue())
|
486 | 1757c616 | Stavros Sachtouris | self._out = outbu
|
487 | 1395c40e | Stavros Sachtouris | |
488 | 7493ccb6 | Stavros Sachtouris | def main(self, container____path__=None): |
489 | 1395c40e | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
490 | 1395c40e | Stavros Sachtouris | self._run()
|
491 | 7493ccb6 | Stavros Sachtouris | |
492 | 234954d1 | Stavros Sachtouris | |
493 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
494 | 915b99b5 | Stavros Sachtouris | class file_mkdir(_file_container_command, _optional_output_cmd): |
495 | f17d6cb5 | Stavros Sachtouris | """Create a directory
|
496 | f17d6cb5 | Stavros Sachtouris | Kamaki hanldes directories the same way as OOS Storage and Pithos+:
|
497 | f17d6cb5 | Stavros Sachtouris | A directory is an object with type "application/directory"
|
498 | f17d6cb5 | Stavros Sachtouris | An object with path dir/name can exist even if dir does not exist
|
499 | f17d6cb5 | Stavros Sachtouris | or even if dir is a non directory object. Users can modify dir '
|
500 | f17d6cb5 | Stavros Sachtouris | without affecting the dir/name object in any way.
|
501 | f17d6cb5 | Stavros Sachtouris | """
|
502 | 7493ccb6 | Stavros Sachtouris | |
503 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
504 | 1395c40e | Stavros Sachtouris | @errors.pithos.connection
|
505 | 1395c40e | Stavros Sachtouris | @errors.pithos.container
|
506 | 1395c40e | Stavros Sachtouris | def _run(self): |
507 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.create_directory(self.path)) |
508 | 1395c40e | Stavros Sachtouris | |
509 | 7493ccb6 | Stavros Sachtouris | def main(self, container___directory): |
510 | 1395c40e | Stavros Sachtouris | super(self.__class__, self)._run( |
511 | ff1c0296 | Stavros Sachtouris | container___directory, path_is_optional=False)
|
512 | 1395c40e | Stavros Sachtouris | self._run()
|
513 | 7493ccb6 | Stavros Sachtouris | |
514 | 234954d1 | Stavros Sachtouris | |
515 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
516 | 915b99b5 | Stavros Sachtouris | class file_touch(_file_container_command, _optional_output_cmd): |
517 | 1e29b9f6 | Stavros Sachtouris | """Create an empty object (file)
|
518 | 1e29b9f6 | Stavros Sachtouris | If object exists, this command will reset it to 0 length
|
519 | 1e29b9f6 | Stavros Sachtouris | """
|
520 | 1e29b9f6 | Stavros Sachtouris | |
521 | 1e29b9f6 | Stavros Sachtouris | arguments = dict(
|
522 | 1e29b9f6 | Stavros Sachtouris | content_type=ValueArgument( |
523 | 1e29b9f6 | Stavros Sachtouris | 'Set content type (default: application/octet-stream)',
|
524 | 1e29b9f6 | Stavros Sachtouris | '--content-type',
|
525 | 915b99b5 | Stavros Sachtouris | default='application/octet-stream')
|
526 | 1e29b9f6 | Stavros Sachtouris | ) |
527 | 1e29b9f6 | Stavros Sachtouris | |
528 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
529 | 1395c40e | Stavros Sachtouris | @errors.pithos.connection
|
530 | 1395c40e | Stavros Sachtouris | @errors.pithos.container
|
531 | 1395c40e | Stavros Sachtouris | def _run(self): |
532 | 915b99b5 | Stavros Sachtouris | self._optional_output(
|
533 | 915b99b5 | Stavros Sachtouris | self.client.create_object(self.path, self['content_type'])) |
534 | 1395c40e | Stavros Sachtouris | |
535 | 1e29b9f6 | Stavros Sachtouris | def main(self, container___path): |
536 | ff1c0296 | Stavros Sachtouris | super(file_touch, self)._run(container___path, path_is_optional=False) |
537 | 1395c40e | Stavros Sachtouris | self._run()
|
538 | 1e29b9f6 | Stavros Sachtouris | |
539 | 1e29b9f6 | Stavros Sachtouris | |
540 | 1e29b9f6 | Stavros Sachtouris | @command(pithos_cmds)
|
541 | 915b99b5 | Stavros Sachtouris | class file_create(_file_container_command, _optional_output_cmd): |
542 | 1e29b9f6 | Stavros Sachtouris | """Create a container"""
|
543 | 7493ccb6 | Stavros Sachtouris | |
544 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
545 | 2fe2672e | Stavros Sachtouris | versioning=ValueArgument( |
546 | 201baa17 | Stavros Sachtouris | 'set container versioning (auto/none)', '--versioning'), |
547 | 3ed6dbde | Stavros Sachtouris | limit=IntArgument('set default container limit', '--limit'), |
548 | 2fe2672e | Stavros Sachtouris | meta=KeyValueArgument( |
549 | 201baa17 | Stavros Sachtouris | 'set container metadata (can be repeated)', '--meta') |
550 | 2fe2672e | Stavros Sachtouris | ) |
551 | 7493ccb6 | Stavros Sachtouris | |
552 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
553 | 1395c40e | Stavros Sachtouris | @errors.pithos.connection
|
554 | 1395c40e | Stavros Sachtouris | @errors.pithos.container
|
555 | 94bedc5b | Stavros Sachtouris | def _run(self, container): |
556 | 6c068db6 | Stavros Sachtouris | try:
|
557 | 6c068db6 | Stavros Sachtouris | self._optional_output(self.client.create_container( |
558 | 6c068db6 | Stavros Sachtouris | container=container, |
559 | 6c068db6 | Stavros Sachtouris | sizelimit=self['limit'], |
560 | 6c068db6 | Stavros Sachtouris | versioning=self['versioning'], |
561 | 6c068db6 | Stavros Sachtouris | metadata=self['meta'], |
562 | 6c068db6 | Stavros Sachtouris | success=(201, )))
|
563 | 6c068db6 | Stavros Sachtouris | except ClientError as ce: |
564 | 6c068db6 | Stavros Sachtouris | if ce.status in (202, ): |
565 | 6c068db6 | Stavros Sachtouris | raiseCLIError(ce, 'Container %s alread exists' % container)
|
566 | 1395c40e | Stavros Sachtouris | |
567 | edab7ba7 | Stavros Sachtouris | def main(self, container=None): |
568 | 1395c40e | Stavros Sachtouris | super(self.__class__, self)._run(container) |
569 | edab7ba7 | Stavros Sachtouris | if container and self.container != container: |
570 | 1395c40e | Stavros Sachtouris | raiseCLIError('Invalid container name %s' % container, details=[
|
571 | edab7ba7 | Stavros Sachtouris | 'Did you mean "%s" ?' % self.container, |
572 | 52edad0a | Stavros Sachtouris | 'Use --container for names containing :'])
|
573 | 94bedc5b | Stavros Sachtouris | self._run(container)
|
574 | 7493ccb6 | Stavros Sachtouris | |
575 | 234954d1 | Stavros Sachtouris | |
576 | 3ae60112 | Stavros Sachtouris | class _source_destination_command(_file_container_command): |
577 | 2fe2672e | Stavros Sachtouris | |
578 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
579 | f17d6cb5 | Stavros Sachtouris | destination_account=ValueArgument('', ('-a', '--dst-account')), |
580 | f40f0cb7 | Stavros Sachtouris | recursive=FlagArgument('', ('-R', '--recursive')), |
581 | 761e0cbf | Stavros Sachtouris | prefix=FlagArgument('', '--with-prefix', default=''), |
582 | 761e0cbf | Stavros Sachtouris | suffix=ValueArgument('', '--with-suffix', default=''), |
583 | 761e0cbf | Stavros Sachtouris | add_prefix=ValueArgument('', '--add-prefix', default=''), |
584 | 761e0cbf | Stavros Sachtouris | add_suffix=ValueArgument('', '--add-suffix', default=''), |
585 | 761e0cbf | Stavros Sachtouris | prefix_replace=ValueArgument('', '--prefix-to-replace', default=''), |
586 | 1d3f006b | Stavros Sachtouris | suffix_replace=ValueArgument('', '--suffix-to-replace', default=''), |
587 | 2fe2672e | Stavros Sachtouris | ) |
588 | 7493ccb6 | Stavros Sachtouris | |
589 | b4f69041 | Stavros Sachtouris | def __init__(self, arguments={}, auth_base=None, cloud=None): |
590 | 761e0cbf | Stavros Sachtouris | self.arguments.update(arguments)
|
591 | f724cd35 | Stavros Sachtouris | super(_source_destination_command, self).__init__( |
592 | b4f69041 | Stavros Sachtouris | self.arguments, auth_base, cloud)
|
593 | 761e0cbf | Stavros Sachtouris | |
594 | 300da0fb | Stavros Sachtouris | def _run(self, source_container___path, path_is_optional=False): |
595 | 300da0fb | Stavros Sachtouris | super(_source_destination_command, self)._run( |
596 | ff1c0296 | Stavros Sachtouris | source_container___path, path_is_optional) |
597 | 300da0fb | Stavros Sachtouris | self.dst_client = PithosClient(
|
598 | 300da0fb | Stavros Sachtouris | base_url=self.client.base_url,
|
599 | 300da0fb | Stavros Sachtouris | token=self.client.token,
|
600 | 300da0fb | Stavros Sachtouris | account=self['destination_account'] or self.client.account) |
601 | 300da0fb | Stavros Sachtouris | |
602 | 300da0fb | Stavros Sachtouris | @errors.generic.all
|
603 | 300da0fb | Stavros Sachtouris | @errors.pithos.account
|
604 | 300da0fb | Stavros Sachtouris | def _dest_container_path(self, dest_container_path): |
605 | 300da0fb | Stavros Sachtouris | if self['destination_container']: |
606 | 300da0fb | Stavros Sachtouris | self.dst_client.container = self['destination_container'] |
607 | 300da0fb | Stavros Sachtouris | return (self['destination_container'], dest_container_path) |
608 | 300da0fb | Stavros Sachtouris | if dest_container_path:
|
609 | 300da0fb | Stavros Sachtouris | dst = dest_container_path.split(':')
|
610 | 300da0fb | Stavros Sachtouris | if len(dst) > 1: |
611 | 300da0fb | Stavros Sachtouris | try:
|
612 | 300da0fb | Stavros Sachtouris | self.dst_client.container = dst[0] |
613 | 300da0fb | Stavros Sachtouris | self.dst_client.get_container_info(dst[0]) |
614 | 300da0fb | Stavros Sachtouris | except ClientError as err: |
615 | 300da0fb | Stavros Sachtouris | if err.status in (404, 204): |
616 | 300da0fb | Stavros Sachtouris | raiseCLIError( |
617 | 300da0fb | Stavros Sachtouris | 'Destination container %s not found' % dst[0]) |
618 | 300da0fb | Stavros Sachtouris | raise
|
619 | 300da0fb | Stavros Sachtouris | else:
|
620 | 300da0fb | Stavros Sachtouris | self.dst_client.container = dst[0] |
621 | 300da0fb | Stavros Sachtouris | return (dst[0], dst[1]) |
622 | 300da0fb | Stavros Sachtouris | return(None, dst[0]) |
623 | 300da0fb | Stavros Sachtouris | raiseCLIError('No destination container:path provided')
|
624 | 300da0fb | Stavros Sachtouris | |
625 | ece4ae4b | Stavros Sachtouris | def _get_all(self, prefix): |
626 | ece4ae4b | Stavros Sachtouris | return self.client.container_get(prefix=prefix).json |
627 | ece4ae4b | Stavros Sachtouris | |
628 | 1d3f006b | Stavros Sachtouris | def _get_src_objects(self, src_path, source_version=None): |
629 | 6736f171 | Stavros Sachtouris | """Get a list of the source objects to be called
|
630 | 6736f171 | Stavros Sachtouris |
|
631 | 6736f171 | Stavros Sachtouris | :param src_path: (str) source path
|
632 | 6736f171 | Stavros Sachtouris |
|
633 | 6736f171 | Stavros Sachtouris | :returns: (method, params) a method that returns a list when called
|
634 | 6736f171 | Stavros Sachtouris | or (object) if it is a single object
|
635 | 6736f171 | Stavros Sachtouris | """
|
636 | ece4ae4b | Stavros Sachtouris | if src_path and src_path[-1] == '/': |
637 | ece4ae4b | Stavros Sachtouris | src_path = src_path[:-1]
|
638 | ece4ae4b | Stavros Sachtouris | |
639 | 6736f171 | Stavros Sachtouris | if self['prefix']: |
640 | 6736f171 | Stavros Sachtouris | return (self._get_all, dict(prefix=src_path)) |
641 | ece4ae4b | Stavros Sachtouris | try:
|
642 | 1d3f006b | Stavros Sachtouris | srcobj = self.client.get_object_info(
|
643 | 1d3f006b | Stavros Sachtouris | src_path, version=source_version) |
644 | ece4ae4b | Stavros Sachtouris | except ClientError as srcerr: |
645 | 6736f171 | Stavros Sachtouris | if srcerr.status == 404: |
646 | 6736f171 | Stavros Sachtouris | raiseCLIError( |
647 | 300da0fb | Stavros Sachtouris | 'Source object %s not in source container %s' % (
|
648 | 201baa17 | Stavros Sachtouris | src_path, self.client.container),
|
649 | 6736f171 | Stavros Sachtouris | details=['Hint: --with-prefix to match multiple objects'])
|
650 | 6736f171 | Stavros Sachtouris | elif srcerr.status not in (204,): |
651 | ece4ae4b | Stavros Sachtouris | raise
|
652 | 6736f171 | Stavros Sachtouris | return (self.client.list_objects, {}) |
653 | 300da0fb | Stavros Sachtouris | |
654 | 6736f171 | Stavros Sachtouris | if self._is_dir(srcobj): |
655 | 6736f171 | Stavros Sachtouris | if not self['recursive']: |
656 | 6736f171 | Stavros Sachtouris | raiseCLIError( |
657 | 300da0fb | Stavros Sachtouris | 'Object %s of cont. %s is a dir' % (
|
658 | 201baa17 | Stavros Sachtouris | src_path, self.client.container),
|
659 | 6736f171 | Stavros Sachtouris | details=['Use --recursive to access directories'])
|
660 | 6736f171 | Stavros Sachtouris | return (self._get_all, dict(prefix=src_path)) |
661 | 6736f171 | Stavros Sachtouris | srcobj['name'] = src_path
|
662 | 6736f171 | Stavros Sachtouris | return srcobj
|
663 | 6736f171 | Stavros Sachtouris | |
664 | 1d3f006b | Stavros Sachtouris | def src_dst_pairs(self, dst_path, source_version=None): |
665 | 1d3f006b | Stavros Sachtouris | src_iter = self._get_src_objects(self.path, source_version) |
666 | 6736f171 | Stavros Sachtouris | src_N = isinstance(src_iter, tuple) |
667 | 6736f171 | Stavros Sachtouris | add_prefix = self['add_prefix'].strip('/') |
668 | 6736f171 | Stavros Sachtouris | |
669 | 6736f171 | Stavros Sachtouris | if dst_path and dst_path.endswith('/'): |
670 | ece4ae4b | Stavros Sachtouris | dst_path = dst_path[:-1]
|
671 | ece4ae4b | Stavros Sachtouris | |
672 | 6736f171 | Stavros Sachtouris | try:
|
673 | 300da0fb | Stavros Sachtouris | dstobj = self.dst_client.get_object_info(dst_path)
|
674 | 6736f171 | Stavros Sachtouris | except ClientError as trgerr: |
675 | 6736f171 | Stavros Sachtouris | if trgerr.status in (404,): |
676 | 6736f171 | Stavros Sachtouris | if src_N:
|
677 | 6736f171 | Stavros Sachtouris | raiseCLIError( |
678 | 6736f171 | Stavros Sachtouris | 'Cannot merge multiple paths to path %s' % dst_path,
|
679 | 6736f171 | Stavros Sachtouris | details=[ |
680 | 6736f171 | Stavros Sachtouris | 'Try to use / or a directory as destination',
|
681 | 3ae60112 | Stavros Sachtouris | 'or create the destination dir (/file mkdir)',
|
682 | 6736f171 | Stavros Sachtouris | 'or use a single object as source'])
|
683 | 6736f171 | Stavros Sachtouris | elif trgerr.status not in (204,): |
684 | 6736f171 | Stavros Sachtouris | raise
|
685 | 6736f171 | Stavros Sachtouris | else:
|
686 | 6736f171 | Stavros Sachtouris | if self._is_dir(dstobj): |
687 | 6736f171 | Stavros Sachtouris | add_prefix = '%s/%s' % (dst_path.strip('/'), add_prefix) |
688 | 6736f171 | Stavros Sachtouris | elif src_N:
|
689 | 6736f171 | Stavros Sachtouris | raiseCLIError( |
690 | 6736f171 | Stavros Sachtouris | 'Cannot merge multiple paths to path' % dst_path,
|
691 | 6736f171 | Stavros Sachtouris | details=[ |
692 | 6736f171 | Stavros Sachtouris | 'Try to use / or a directory as destination',
|
693 | 3ae60112 | Stavros Sachtouris | 'or create the destination dir (/file mkdir)',
|
694 | 6736f171 | Stavros Sachtouris | 'or use a single object as source'])
|
695 | 6736f171 | Stavros Sachtouris | |
696 | 6736f171 | Stavros Sachtouris | if src_N:
|
697 | 6736f171 | Stavros Sachtouris | (method, kwargs) = src_iter |
698 | 6736f171 | Stavros Sachtouris | for obj in method(**kwargs): |
699 | 6736f171 | Stavros Sachtouris | name = obj['name']
|
700 | 6736f171 | Stavros Sachtouris | if name.endswith(self['suffix']): |
701 | 6736f171 | Stavros Sachtouris | yield (name, self._get_new_object(name, add_prefix)) |
702 | 6736f171 | Stavros Sachtouris | elif src_iter['name'].endswith(self['suffix']): |
703 | 6736f171 | Stavros Sachtouris | name = src_iter['name']
|
704 | 6736f171 | Stavros Sachtouris | yield (name, self._get_new_object(dst_path or name, add_prefix)) |
705 | 6736f171 | Stavros Sachtouris | else:
|
706 | 6736f171 | Stavros Sachtouris | raiseCLIError('Source path %s conflicts with suffix %s' % (
|
707 | 201baa17 | Stavros Sachtouris | src_iter['name'], self['suffix'])) |
708 | ece4ae4b | Stavros Sachtouris | |
709 | 6736f171 | Stavros Sachtouris | def _get_new_object(self, obj, add_prefix): |
710 | 6736f171 | Stavros Sachtouris | if self['prefix_replace'] and obj.startswith(self['prefix_replace']): |
711 | 6736f171 | Stavros Sachtouris | obj = obj[len(self['prefix_replace']):] |
712 | 6736f171 | Stavros Sachtouris | if self['suffix_replace'] and obj.endswith(self['suffix_replace']): |
713 | 6736f171 | Stavros Sachtouris | obj = obj[:-len(self['suffix_replace'])] |
714 | 6736f171 | Stavros Sachtouris | return add_prefix + obj + self['add_suffix'] |
715 | efdee310 | Stavros Sachtouris | |
716 | 761e0cbf | Stavros Sachtouris | |
717 | 761e0cbf | Stavros Sachtouris | @command(pithos_cmds)
|
718 | 915b99b5 | Stavros Sachtouris | class file_copy(_source_destination_command, _optional_output_cmd): |
719 | 761e0cbf | Stavros Sachtouris | """Copy objects from container to (another) container
|
720 | 761e0cbf | Stavros Sachtouris | Semantics:
|
721 | 761e0cbf | Stavros Sachtouris | copy cont:path dir
|
722 | 761e0cbf | Stavros Sachtouris | . transfer path as dir/path
|
723 | 761e0cbf | Stavros Sachtouris | copy cont:path cont2:
|
724 | 761e0cbf | Stavros Sachtouris | . trasnfer all <obj> prefixed with path to container cont2
|
725 | 761e0cbf | Stavros Sachtouris | copy cont:path [cont2:]path2
|
726 | 761e0cbf | Stavros Sachtouris | . transfer path to path2
|
727 | 761e0cbf | Stavros Sachtouris | Use options:
|
728 | 761e0cbf | Stavros Sachtouris | 1. <container1>:<path1> [container2:]<path2> : if container2 is not given,
|
729 | 761e0cbf | Stavros Sachtouris | destination is container1:path2
|
730 | 761e0cbf | Stavros Sachtouris | 2. <container>:<path1> <path2> : make a copy in the same container
|
731 | 761e0cbf | Stavros Sachtouris | 3. Can use --container= instead of <container1>
|
732 | 761e0cbf | Stavros Sachtouris | """
|
733 | 761e0cbf | Stavros Sachtouris | |
734 | 761e0cbf | Stavros Sachtouris | arguments = dict(
|
735 | 300da0fb | Stavros Sachtouris | destination_account=ValueArgument( |
736 | 201baa17 | Stavros Sachtouris | 'Account to copy to', ('-a', '--dst-account')), |
737 | 761e0cbf | Stavros Sachtouris | destination_container=ValueArgument( |
738 | 761e0cbf | Stavros Sachtouris | 'use it if destination container name contains a : character',
|
739 | f40f0cb7 | Stavros Sachtouris | ('-D', '--dst-container')), |
740 | 761e0cbf | Stavros Sachtouris | public=ValueArgument('make object publicly accessible', '--public'), |
741 | 761e0cbf | Stavros Sachtouris | content_type=ValueArgument( |
742 | 201baa17 | Stavros Sachtouris | 'change object\'s content type', '--content-type'), |
743 | 761e0cbf | Stavros Sachtouris | recursive=FlagArgument( |
744 | 201baa17 | Stavros Sachtouris | 'copy directory and contents', ('-R', '--recursive')), |
745 | 761e0cbf | Stavros Sachtouris | prefix=FlagArgument( |
746 | 761e0cbf | Stavros Sachtouris | 'Match objects prefixed with src path (feels like src_path*)',
|
747 | 761e0cbf | Stavros Sachtouris | '--with-prefix',
|
748 | 761e0cbf | Stavros Sachtouris | default=''),
|
749 | 761e0cbf | Stavros Sachtouris | suffix=ValueArgument( |
750 | 201baa17 | Stavros Sachtouris | 'Suffix of source objects (feels like *suffix)', '--with-suffix', |
751 | 761e0cbf | Stavros Sachtouris | default=''),
|
752 | 761e0cbf | Stavros Sachtouris | add_prefix=ValueArgument('Prefix targets', '--add-prefix', default=''), |
753 | 761e0cbf | Stavros Sachtouris | add_suffix=ValueArgument('Suffix targets', '--add-suffix', default=''), |
754 | 761e0cbf | Stavros Sachtouris | prefix_replace=ValueArgument( |
755 | 761e0cbf | Stavros Sachtouris | 'Prefix of src to replace with dst path + add_prefix, if matched',
|
756 | 761e0cbf | Stavros Sachtouris | '--prefix-to-replace',
|
757 | 761e0cbf | Stavros Sachtouris | default=''),
|
758 | 761e0cbf | Stavros Sachtouris | suffix_replace=ValueArgument( |
759 | 761e0cbf | Stavros Sachtouris | 'Suffix of src to replace with add_suffix, if matched',
|
760 | 761e0cbf | Stavros Sachtouris | '--suffix-to-replace',
|
761 | 1d3f006b | Stavros Sachtouris | default=''),
|
762 | 1d3f006b | Stavros Sachtouris | source_version=ValueArgument( |
763 | 201baa17 | Stavros Sachtouris | 'copy specific version', ('-S', '--source-version')) |
764 | 761e0cbf | Stavros Sachtouris | ) |
765 | 761e0cbf | Stavros Sachtouris | |
766 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
767 | 1395c40e | Stavros Sachtouris | @errors.pithos.connection
|
768 | 1395c40e | Stavros Sachtouris | @errors.pithos.container
|
769 | 300da0fb | Stavros Sachtouris | @errors.pithos.account
|
770 | 300da0fb | Stavros Sachtouris | def _run(self, dst_path): |
771 | 1395c40e | Stavros Sachtouris | no_source_object = True
|
772 | 300da0fb | Stavros Sachtouris | src_account = self.client.account if ( |
773 | 300da0fb | Stavros Sachtouris | self['destination_account']) else None |
774 | 1d3f006b | Stavros Sachtouris | for src_obj, dst_obj in self.src_dst_pairs( |
775 | 1d3f006b | Stavros Sachtouris | dst_path, self['source_version']): |
776 | 1395c40e | Stavros Sachtouris | no_source_object = False
|
777 | 55c75058 | Stavros Sachtouris | r = self.dst_client.copy_object(
|
778 | 300da0fb | Stavros Sachtouris | src_container=self.client.container,
|
779 | 3a066af4 | Stavros Sachtouris | src_object=src_obj, |
780 | 300da0fb | Stavros Sachtouris | dst_container=self.dst_client.container,
|
781 | 300da0fb | Stavros Sachtouris | dst_object=dst_obj, |
782 | 300da0fb | Stavros Sachtouris | source_account=src_account, |
783 | 1395c40e | Stavros Sachtouris | source_version=self['source_version'], |
784 | 1395c40e | Stavros Sachtouris | public=self['public'], |
785 | 1395c40e | Stavros Sachtouris | content_type=self['content_type']) |
786 | 1395c40e | Stavros Sachtouris | if no_source_object:
|
787 | 1395c40e | Stavros Sachtouris | raiseCLIError('No object %s in container %s' % (
|
788 | 201baa17 | Stavros Sachtouris | self.path, self.container)) |
789 | 915b99b5 | Stavros Sachtouris | self._optional_output(r)
|
790 | 1395c40e | Stavros Sachtouris | |
791 | de73876b | Stavros Sachtouris | def main( |
792 | e2d7b883 | Stavros Sachtouris | self, source_container___path,
|
793 | 24ff0a35 | Stavros Sachtouris | destination_container___path=None):
|
794 | 3ae60112 | Stavros Sachtouris | super(file_copy, self)._run( |
795 | ff1c0296 | Stavros Sachtouris | source_container___path, path_is_optional=False)
|
796 | 1395c40e | Stavros Sachtouris | (dst_cont, dst_path) = self._dest_container_path(
|
797 | 0e4ee6d1 | Stavros Sachtouris | destination_container___path) |
798 | 300da0fb | Stavros Sachtouris | self.dst_client.container = dst_cont or self.container |
799 | 300da0fb | Stavros Sachtouris | self._run(dst_path=dst_path or '') |
800 | 7493ccb6 | Stavros Sachtouris | |
801 | 234954d1 | Stavros Sachtouris | |
802 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
803 | 915b99b5 | Stavros Sachtouris | class file_move(_source_destination_command, _optional_output_cmd): |
804 | 761e0cbf | Stavros Sachtouris | """Move/rename objects from container to (another) container
|
805 | 8249ee0f | Stavros Sachtouris | Semantics:
|
806 | 761e0cbf | Stavros Sachtouris | move cont:path dir
|
807 | 761e0cbf | Stavros Sachtouris | . rename path as dir/path
|
808 | 8249ee0f | Stavros Sachtouris | move cont:path cont2:
|
809 | 761e0cbf | Stavros Sachtouris | . trasnfer all <obj> prefixed with path to container cont2
|
810 | 761e0cbf | Stavros Sachtouris | move cont:path [cont2:]path2
|
811 | 761e0cbf | Stavros Sachtouris | . transfer path to path2
|
812 | 2fe2672e | Stavros Sachtouris | Use options:
|
813 | 761e0cbf | Stavros Sachtouris | 1. <container1>:<path1> [container2:]<path2> : if container2 is not given,
|
814 | 795bf206 | Stavros Sachtouris | destination is container1:path2
|
815 | 761e0cbf | Stavros Sachtouris | 2. <container>:<path1> <path2> : move in the same container
|
816 | 8249ee0f | Stavros Sachtouris | 3. Can use --container= instead of <container1>
|
817 | 2fe2672e | Stavros Sachtouris | """
|
818 | 2fe2672e | Stavros Sachtouris | |
819 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
820 | 300da0fb | Stavros Sachtouris | destination_account=ValueArgument( |
821 | 201baa17 | Stavros Sachtouris | 'Account to move to', ('-a', '--dst-account')), |
822 | 0e4ee6d1 | Stavros Sachtouris | destination_container=ValueArgument( |
823 | 0e4ee6d1 | Stavros Sachtouris | 'use it if destination container name contains a : character',
|
824 | f40f0cb7 | Stavros Sachtouris | ('-D', '--dst-container')), |
825 | 761e0cbf | Stavros Sachtouris | public=ValueArgument('make object publicly accessible', '--public'), |
826 | 761e0cbf | Stavros Sachtouris | content_type=ValueArgument( |
827 | 201baa17 | Stavros Sachtouris | 'change object\'s content type', '--content-type'), |
828 | 761e0cbf | Stavros Sachtouris | recursive=FlagArgument( |
829 | 201baa17 | Stavros Sachtouris | 'copy directory and contents', ('-R', '--recursive')), |
830 | 761e0cbf | Stavros Sachtouris | prefix=FlagArgument( |
831 | 761e0cbf | Stavros Sachtouris | 'Match objects prefixed with src path (feels like src_path*)',
|
832 | 761e0cbf | Stavros Sachtouris | '--with-prefix',
|
833 | 761e0cbf | Stavros Sachtouris | default=''),
|
834 | 761e0cbf | Stavros Sachtouris | suffix=ValueArgument( |
835 | 201baa17 | Stavros Sachtouris | 'Suffix of source objects (feels like *suffix)', '--with-suffix', |
836 | 761e0cbf | Stavros Sachtouris | default=''),
|
837 | 761e0cbf | Stavros Sachtouris | add_prefix=ValueArgument('Prefix targets', '--add-prefix', default=''), |
838 | 761e0cbf | Stavros Sachtouris | add_suffix=ValueArgument('Suffix targets', '--add-suffix', default=''), |
839 | 761e0cbf | Stavros Sachtouris | prefix_replace=ValueArgument( |
840 | 761e0cbf | Stavros Sachtouris | 'Prefix of src to replace with dst path + add_prefix, if matched',
|
841 | 761e0cbf | Stavros Sachtouris | '--prefix-to-replace',
|
842 | 761e0cbf | Stavros Sachtouris | default=''),
|
843 | 761e0cbf | Stavros Sachtouris | suffix_replace=ValueArgument( |
844 | 761e0cbf | Stavros Sachtouris | 'Suffix of src to replace with add_suffix, if matched',
|
845 | 761e0cbf | Stavros Sachtouris | '--suffix-to-replace',
|
846 | 915b99b5 | Stavros Sachtouris | default='')
|
847 | 2fe2672e | Stavros Sachtouris | ) |
848 | 7493ccb6 | Stavros Sachtouris | |
849 | 1395c40e | Stavros Sachtouris | @errors.generic.all
|
850 | 1395c40e | Stavros Sachtouris | @errors.pithos.connection
|
851 | 1395c40e | Stavros Sachtouris | @errors.pithos.container
|
852 | 300da0fb | Stavros Sachtouris | def _run(self, dst_path): |
853 | 1395c40e | Stavros Sachtouris | no_source_object = True
|
854 | 300da0fb | Stavros Sachtouris | src_account = self.client.account if ( |
855 | 300da0fb | Stavros Sachtouris | self['destination_account']) else None |
856 | 300da0fb | Stavros Sachtouris | for src_obj, dst_obj in self.src_dst_pairs(dst_path): |
857 | 1395c40e | Stavros Sachtouris | no_source_object = False
|
858 | 55c75058 | Stavros Sachtouris | r = self.dst_client.move_object(
|
859 | 1395c40e | Stavros Sachtouris | src_container=self.container,
|
860 | 300da0fb | Stavros Sachtouris | src_object=src_obj, |
861 | 300da0fb | Stavros Sachtouris | dst_container=self.dst_client.container,
|
862 | 300da0fb | Stavros Sachtouris | dst_object=dst_obj, |
863 | 4f266635 | Stavros Sachtouris | source_account=src_account, |
864 | 1395c40e | Stavros Sachtouris | public=self['public'], |
865 | 1395c40e | Stavros Sachtouris | content_type=self['content_type']) |
866 | 1395c40e | Stavros Sachtouris | if no_source_object:
|
867 | 1395c40e | Stavros Sachtouris | raiseCLIError('No object %s in container %s' % (
|
868 | ff1c0296 | Stavros Sachtouris | self.path, self.container)) |
869 | 915b99b5 | Stavros Sachtouris | self._optional_output(r)
|
870 | 1395c40e | Stavros Sachtouris | |
871 | de73876b | Stavros Sachtouris | def main( |
872 | e2d7b883 | Stavros Sachtouris | self, source_container___path,
|
873 | 24ff0a35 | Stavros Sachtouris | destination_container___path=None):
|
874 | 1395c40e | Stavros Sachtouris | super(self.__class__, self)._run( |
875 | 1395c40e | Stavros Sachtouris | source_container___path, |
876 | 1395c40e | Stavros Sachtouris | path_is_optional=False)
|
877 | 45b70023 | Stavros Sachtouris | (dst_cont, dst_path) = self._dest_container_path(
|
878 | 1395c40e | Stavros Sachtouris | destination_container___path) |
879 | 300da0fb | Stavros Sachtouris | (dst_cont, dst_path) = self._dest_container_path(
|
880 | 300da0fb | Stavros Sachtouris | destination_container___path) |
881 | 300da0fb | Stavros Sachtouris | self.dst_client.container = dst_cont or self.container |
882 | 300da0fb | Stavros Sachtouris | self._run(dst_path=dst_path or '') |
883 | 7493ccb6 | Stavros Sachtouris | |
884 | 234954d1 | Stavros Sachtouris | |
885 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
886 | 915b99b5 | Stavros Sachtouris | class file_append(_file_container_command, _optional_output_cmd): |
887 | aaca2ef4 | Stavros Sachtouris | """Append local file to (existing) remote object
|
888 | aaca2ef4 | Stavros Sachtouris | The remote object should exist.
|
889 | aaca2ef4 | Stavros Sachtouris | If the remote object is a directory, it is transformed into a file.
|
890 | aaca2ef4 | Stavros Sachtouris | In the later case, objects under the directory remain intact.
|
891 | aaca2ef4 | Stavros Sachtouris | """
|
892 | 7493ccb6 | Stavros Sachtouris | |
893 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
894 | 2fe2672e | Stavros Sachtouris | progress_bar=ProgressBarArgument( |
895 | ff1c0296 | Stavros Sachtouris | 'do not show progress bar', ('-N', '--no-progress-bar'), |
896 | 915b99b5 | Stavros Sachtouris | default=False)
|
897 | 2fe2672e | Stavros Sachtouris | ) |
898 | 486f7af1 | Stavros Sachtouris | |
899 | ca092af4 | Stavros Sachtouris | @errors.generic.all
|
900 | ca092af4 | Stavros Sachtouris | @errors.pithos.connection
|
901 | ca092af4 | Stavros Sachtouris | @errors.pithos.container
|
902 | ca092af4 | Stavros Sachtouris | @errors.pithos.object_path
|
903 | ca092af4 | Stavros Sachtouris | def _run(self, local_path): |
904 | ca092af4 | Stavros Sachtouris | (progress_bar, upload_cb) = self._safe_progress_bar('Appending') |
905 | 7493ccb6 | Stavros Sachtouris | try:
|
906 | ff1c0296 | Stavros Sachtouris | with open(local_path, 'rb') as f: |
907 | ff1c0296 | Stavros Sachtouris | self._optional_output(
|
908 | ff1c0296 | Stavros Sachtouris | self.client.append_object(self.path, f, upload_cb)) |
909 | 852a22e7 | Stavros Sachtouris | finally:
|
910 | ca092af4 | Stavros Sachtouris | self._safe_progress_bar_finish(progress_bar)
|
911 | ca092af4 | Stavros Sachtouris | |
912 | ca092af4 | Stavros Sachtouris | def main(self, local_path, container___path): |
913 | ca092af4 | Stavros Sachtouris | super(self.__class__, self)._run( |
914 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
915 | ca092af4 | Stavros Sachtouris | self._run(local_path)
|
916 | 7493ccb6 | Stavros Sachtouris | |
917 | 234954d1 | Stavros Sachtouris | |
918 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
919 | 915b99b5 | Stavros Sachtouris | class file_truncate(_file_container_command, _optional_output_cmd): |
920 | aaca2ef4 | Stavros Sachtouris | """Truncate remote file up to a size (default is 0)"""
|
921 | 7493ccb6 | Stavros Sachtouris | |
922 | ca092af4 | Stavros Sachtouris | @errors.generic.all
|
923 | ca092af4 | Stavros Sachtouris | @errors.pithos.connection
|
924 | ca092af4 | Stavros Sachtouris | @errors.pithos.container
|
925 | ca092af4 | Stavros Sachtouris | @errors.pithos.object_path
|
926 | ca092af4 | Stavros Sachtouris | @errors.pithos.object_size
|
927 | ca092af4 | Stavros Sachtouris | def _run(self, size=0): |
928 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.truncate_object(self.path, size)) |
929 | ca092af4 | Stavros Sachtouris | |
930 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path, size=0): |
931 | ca092af4 | Stavros Sachtouris | super(self.__class__, self)._run(container___path) |
932 | ca092af4 | Stavros Sachtouris | self._run(size=size)
|
933 | 7493ccb6 | Stavros Sachtouris | |
934 | 234954d1 | Stavros Sachtouris | |
935 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
936 | 915b99b5 | Stavros Sachtouris | class file_overwrite(_file_container_command, _optional_output_cmd): |
937 | aaca2ef4 | Stavros Sachtouris | """Overwrite part (from start to end) of a remote file
|
938 | aaca2ef4 | Stavros Sachtouris | overwrite local-path container 10 20
|
939 | aaca2ef4 | Stavros Sachtouris | . will overwrite bytes from 10 to 20 of a remote file with the same name
|
940 | aaca2ef4 | Stavros Sachtouris | . as local-path basename
|
941 | aaca2ef4 | Stavros Sachtouris | overwrite local-path container:path 10 20
|
942 | aaca2ef4 | Stavros Sachtouris | . will overwrite as above, but the remote file is named path
|
943 | aaca2ef4 | Stavros Sachtouris | """
|
944 | 7493ccb6 | Stavros Sachtouris | |
945 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
946 | 2fe2672e | Stavros Sachtouris | progress_bar=ProgressBarArgument( |
947 | ff1c0296 | Stavros Sachtouris | 'do not show progress bar', ('-N', '--no-progress-bar'), |
948 | 2fe2672e | Stavros Sachtouris | default=False)
|
949 | 2fe2672e | Stavros Sachtouris | ) |
950 | 486f7af1 | Stavros Sachtouris | |
951 | ca092af4 | Stavros Sachtouris | @errors.generic.all
|
952 | ca092af4 | Stavros Sachtouris | @errors.pithos.connection
|
953 | ca092af4 | Stavros Sachtouris | @errors.pithos.container
|
954 | ca092af4 | Stavros Sachtouris | @errors.pithos.object_path
|
955 | ca092af4 | Stavros Sachtouris | @errors.pithos.object_size
|
956 | ca092af4 | Stavros Sachtouris | def _run(self, local_path, start, end): |
957 | ff1c0296 | Stavros Sachtouris | start, end = int(start), int(end) |
958 | ca092af4 | Stavros Sachtouris | (progress_bar, upload_cb) = self._safe_progress_bar(
|
959 | ca092af4 | Stavros Sachtouris | 'Overwrite %s bytes' % (end - start))
|
960 | aaca2ef4 | Stavros Sachtouris | try:
|
961 | ff1c0296 | Stavros Sachtouris | with open(path.abspath(local_path), 'rb') as f: |
962 | ff1c0296 | Stavros Sachtouris | self._optional_output(self.client.overwrite_object( |
963 | ff1c0296 | Stavros Sachtouris | obj=self.path,
|
964 | ff1c0296 | Stavros Sachtouris | start=start, |
965 | ff1c0296 | Stavros Sachtouris | end=end, |
966 | ff1c0296 | Stavros Sachtouris | source_file=f, |
967 | ff1c0296 | Stavros Sachtouris | upload_cb=upload_cb)) |
968 | 852a22e7 | Stavros Sachtouris | finally:
|
969 | ca092af4 | Stavros Sachtouris | self._safe_progress_bar_finish(progress_bar)
|
970 | ca092af4 | Stavros Sachtouris | |
971 | 52edad0a | Stavros Sachtouris | def main(self, local_path, container___path, start, end): |
972 | 52edad0a | Stavros Sachtouris | super(self.__class__, self)._run( |
973 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=None)
|
974 | 52edad0a | Stavros Sachtouris | self.path = self.path or path.basename(local_path) |
975 | ca092af4 | Stavros Sachtouris | self._run(local_path=local_path, start=start, end=end)
|
976 | 7493ccb6 | Stavros Sachtouris | |
977 | 234954d1 | Stavros Sachtouris | |
978 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
979 | 915b99b5 | Stavros Sachtouris | class file_manifest(_file_container_command, _optional_output_cmd): |
980 | 8fa6ef6a | Stavros Sachtouris | """Create a remote file of uploaded parts by manifestation
|
981 | 35b52b0e | Stavros Sachtouris | Remains functional for compatibility with OOS Storage. Users are advised
|
982 | 35b52b0e | Stavros Sachtouris | to use the upload command instead.
|
983 | 35b52b0e | Stavros Sachtouris | Manifestation is a compliant process for uploading large files. The files
|
984 | 35b52b0e | Stavros Sachtouris | have to be chunked in smalled files and uploaded as <prefix><increment>
|
985 | 35b52b0e | Stavros Sachtouris | where increment is 1, 2, ...
|
986 | 35b52b0e | Stavros Sachtouris | Finally, the manifest command glues partial files together in one file
|
987 | 35b52b0e | Stavros Sachtouris | named <prefix>
|
988 | 35b52b0e | Stavros Sachtouris | The upload command is faster, easier and more intuitive than manifest
|
989 | 8fa6ef6a | Stavros Sachtouris | """
|
990 | 486f7af1 | Stavros Sachtouris | |
991 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
992 | 2fe2672e | Stavros Sachtouris | etag=ValueArgument('check written data', '--etag'), |
993 | 2fe2672e | Stavros Sachtouris | content_encoding=ValueArgument( |
994 | 201baa17 | Stavros Sachtouris | 'set MIME content type', '--content-encoding'), |
995 | 2fe2672e | Stavros Sachtouris | content_disposition=ValueArgument( |
996 | 201baa17 | Stavros Sachtouris | 'the presentation style of the object', '--content-disposition'), |
997 | 8fa6ef6a | Stavros Sachtouris | content_type=ValueArgument( |
998 | 201baa17 | Stavros Sachtouris | 'specify content type', '--content-type', |
999 | 8fa6ef6a | Stavros Sachtouris | default='application/octet-stream'),
|
1000 | 2fe2672e | Stavros Sachtouris | sharing=SharingArgument( |
1001 | de73876b | Stavros Sachtouris | '\n'.join([
|
1002 | de73876b | Stavros Sachtouris | 'define object sharing policy',
|
1003 | de73876b | Stavros Sachtouris | ' ( "read=user1,grp1,user2,... write=user1,grp2,..." )']),
|
1004 | 2fe2672e | Stavros Sachtouris | '--sharing'),
|
1005 | 2fe2672e | Stavros Sachtouris | public=FlagArgument('make object publicly accessible', '--public') |
1006 | 2fe2672e | Stavros Sachtouris | ) |
1007 | 234954d1 | Stavros Sachtouris | |
1008 | 68858765 | Stavros Sachtouris | @errors.generic.all
|
1009 | 68858765 | Stavros Sachtouris | @errors.pithos.connection
|
1010 | 68858765 | Stavros Sachtouris | @errors.pithos.container
|
1011 | 68858765 | Stavros Sachtouris | @errors.pithos.object_path
|
1012 | 68858765 | Stavros Sachtouris | def _run(self): |
1013 | abff3366 | Stavros Sachtouris | ctype, cenc = guess_mime_type(self.path)
|
1014 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.create_object_by_manifestation( |
1015 | 68858765 | Stavros Sachtouris | self.path,
|
1016 | f8426b5c | Stavros Sachtouris | content_encoding=self['content_encoding'] or cenc, |
1017 | 68858765 | Stavros Sachtouris | content_disposition=self['content_disposition'], |
1018 | abff3366 | Stavros Sachtouris | content_type=self['content_type'] or ctype, |
1019 | 68858765 | Stavros Sachtouris | sharing=self['sharing'], |
1020 | 915b99b5 | Stavros Sachtouris | public=self['public'])) |
1021 | 68858765 | Stavros Sachtouris | |
1022 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path): |
1023 | 68858765 | Stavros Sachtouris | super(self.__class__, self)._run( |
1024 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1025 | 68858765 | Stavros Sachtouris | self.run()
|
1026 | 7493ccb6 | Stavros Sachtouris | |
1027 | 234954d1 | Stavros Sachtouris | |
1028 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1029 | 915b99b5 | Stavros Sachtouris | class file_upload(_file_container_command, _optional_output_cmd): |
1030 | 7493ccb6 | Stavros Sachtouris | """Upload a file"""
|
1031 | 7493ccb6 | Stavros Sachtouris | |
1032 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1033 | 2fe2672e | Stavros Sachtouris | use_hashes=FlagArgument( |
1034 | 201baa17 | Stavros Sachtouris | 'provide hashmap file instead of data', '--use-hashes'), |
1035 | 2fe2672e | Stavros Sachtouris | etag=ValueArgument('check written data', '--etag'), |
1036 | 2fe2672e | Stavros Sachtouris | unchunked=FlagArgument('avoid chunked transfer mode', '--unchunked'), |
1037 | 2fe2672e | Stavros Sachtouris | content_encoding=ValueArgument( |
1038 | 201baa17 | Stavros Sachtouris | 'set MIME content type', '--content-encoding'), |
1039 | 2fe2672e | Stavros Sachtouris | content_disposition=ValueArgument( |
1040 | 201baa17 | Stavros Sachtouris | 'specify objects presentation style', '--content-disposition'), |
1041 | 2fe2672e | Stavros Sachtouris | content_type=ValueArgument('specify content type', '--content-type'), |
1042 | 2fe2672e | Stavros Sachtouris | sharing=SharingArgument( |
1043 | de73876b | Stavros Sachtouris | help='\n'.join([
|
1044 | de73876b | Stavros Sachtouris | 'define sharing object policy',
|
1045 | de73876b | Stavros Sachtouris | '( "read=user1,grp1,user2,... write=user1,grp2,... )']),
|
1046 | 2fe2672e | Stavros Sachtouris | parsed_name='--sharing'),
|
1047 | 2fe2672e | Stavros Sachtouris | public=FlagArgument('make object publicly accessible', '--public'), |
1048 | 2fe2672e | Stavros Sachtouris | poolsize=IntArgument('set pool size', '--with-pool-size'), |
1049 | 2fe2672e | Stavros Sachtouris | progress_bar=ProgressBarArgument( |
1050 | 2fe2672e | Stavros Sachtouris | 'do not show progress bar',
|
1051 | 8741c407 | Stavros Sachtouris | ('-N', '--no-progress-bar'), |
1052 | 706fc940 | Stavros Sachtouris | default=False),
|
1053 | 2d158d8b | Stavros Sachtouris | overwrite=FlagArgument('Force (over)write', ('-f', '--force')), |
1054 | 2d158d8b | Stavros Sachtouris | recursive=FlagArgument( |
1055 | 2d158d8b | Stavros Sachtouris | 'Recursively upload directory *contents* + subdirectories',
|
1056 | 915b99b5 | Stavros Sachtouris | ('-R', '--recursive')) |
1057 | 2fe2672e | Stavros Sachtouris | ) |
1058 | 7493ccb6 | Stavros Sachtouris | |
1059 | 14b25e00 | Stavros Sachtouris | def _check_container_limit(self, path): |
1060 | 14b25e00 | Stavros Sachtouris | cl_dict = self.client.get_container_limit()
|
1061 | 14b25e00 | Stavros Sachtouris | container_limit = int(cl_dict['x-container-policy-quota']) |
1062 | 2b74fc1d | Stavros Sachtouris | r = self.client.container_get()
|
1063 | 2b74fc1d | Stavros Sachtouris | used_bytes = sum(int(o['bytes']) for o in r.json) |
1064 | 14b25e00 | Stavros Sachtouris | path_size = get_path_size(path) |
1065 | c8d8c6c9 | Stavros Sachtouris | if container_limit and path_size > (container_limit - used_bytes): |
1066 | 2b74fc1d | Stavros Sachtouris | raiseCLIError( |
1067 | 2b74fc1d | Stavros Sachtouris | 'Container(%s) (limit(%s) - used(%s)) < size(%s) of %s' % (
|
1068 | 14b25e00 | Stavros Sachtouris | self.client.container,
|
1069 | 14b25e00 | Stavros Sachtouris | format_size(container_limit), |
1070 | 2b74fc1d | Stavros Sachtouris | format_size(used_bytes), |
1071 | 14b25e00 | Stavros Sachtouris | format_size(path_size), |
1072 | 14b25e00 | Stavros Sachtouris | path), |
1073 | 14b25e00 | Stavros Sachtouris | importance=1, details=[
|
1074 | 14b25e00 | Stavros Sachtouris | 'Check accound limit: /file quota',
|
1075 | 14b25e00 | Stavros Sachtouris | 'Check container limit:',
|
1076 | 14b25e00 | Stavros Sachtouris | '\t/file containerlimit get %s' % self.client.container, |
1077 | 14b25e00 | Stavros Sachtouris | 'Increase container limit:',
|
1078 | 14b25e00 | Stavros Sachtouris | '\t/file containerlimit set <new limit> %s' % (
|
1079 | 14b25e00 | Stavros Sachtouris | self.client.container)])
|
1080 | 14b25e00 | Stavros Sachtouris | |
1081 | b666ef82 | Stavros Sachtouris | def _path_pairs(self, local_path, remote_path): |
1082 | b666ef82 | Stavros Sachtouris | """Get pairs of local and remote paths"""
|
1083 | b666ef82 | Stavros Sachtouris | lpath = path.abspath(local_path) |
1084 | b666ef82 | Stavros Sachtouris | short_path = lpath.split(path.sep)[-1]
|
1085 | b666ef82 | Stavros Sachtouris | rpath = remote_path or short_path
|
1086 | b666ef82 | Stavros Sachtouris | if path.isdir(lpath):
|
1087 | 2d158d8b | Stavros Sachtouris | if not self['recursive']: |
1088 | 2d158d8b | Stavros Sachtouris | raiseCLIError('%s is a directory' % lpath, details=[
|
1089 | 2d158d8b | Stavros Sachtouris | 'Use -R to upload directory contents'])
|
1090 | b666ef82 | Stavros Sachtouris | robj = self.client.container_get(path=rpath)
|
1091 | b666ef82 | Stavros Sachtouris | if robj.json and not self['overwrite']: |
1092 | b666ef82 | Stavros Sachtouris | raiseCLIError( |
1093 | b666ef82 | Stavros Sachtouris | 'Objects prefixed with %s already exist' % rpath,
|
1094 | b666ef82 | Stavros Sachtouris | importance=1,
|
1095 | b666ef82 | Stavros Sachtouris | details=['Existing objects:'] + ['\t%s:\t%s' % ( |
1096 | b666ef82 | Stavros Sachtouris | o['content_type'][12:], |
1097 | b666ef82 | Stavros Sachtouris | o['name']) for o in robj.json] + [ |
1098 | b666ef82 | Stavros Sachtouris | 'Use -f to add, overwrite or resume'])
|
1099 | b666ef82 | Stavros Sachtouris | if not self['overwrite']: |
1100 | b666ef82 | Stavros Sachtouris | try:
|
1101 | b666ef82 | Stavros Sachtouris | topobj = self.client.get_object_info(rpath)
|
1102 | b666ef82 | Stavros Sachtouris | if not self._is_dir(topobj): |
1103 | b666ef82 | Stavros Sachtouris | raiseCLIError( |
1104 | b666ef82 | Stavros Sachtouris | 'Object %s exists but it is not a dir' % rpath,
|
1105 | b666ef82 | Stavros Sachtouris | importance=1, details=['Use -f to overwrite']) |
1106 | b666ef82 | Stavros Sachtouris | except ClientError as ce: |
1107 | ff1c0296 | Stavros Sachtouris | if ce.status not in (404, ): |
1108 | b666ef82 | Stavros Sachtouris | raise
|
1109 | 2d158d8b | Stavros Sachtouris | self._check_container_limit(lpath)
|
1110 | b666ef82 | Stavros Sachtouris | prev = ''
|
1111 | b666ef82 | Stavros Sachtouris | for top, subdirs, files in walk(lpath): |
1112 | b666ef82 | Stavros Sachtouris | if top != prev:
|
1113 | b666ef82 | Stavros Sachtouris | prev = top |
1114 | b666ef82 | Stavros Sachtouris | try:
|
1115 | b666ef82 | Stavros Sachtouris | rel_path = rpath + top.split(lpath)[1]
|
1116 | b666ef82 | Stavros Sachtouris | except IndexError: |
1117 | b666ef82 | Stavros Sachtouris | rel_path = rpath |
1118 | ff1c0296 | Stavros Sachtouris | self.error('mkdir %s:%s' % ( |
1119 | ff1c0296 | Stavros Sachtouris | self.client.container, rel_path))
|
1120 | b666ef82 | Stavros Sachtouris | self.client.create_directory(rel_path)
|
1121 | b666ef82 | Stavros Sachtouris | for f in files: |
1122 | b666ef82 | Stavros Sachtouris | fpath = path.join(top, f) |
1123 | b666ef82 | Stavros Sachtouris | if path.isfile(fpath):
|
1124 | 14d15eca | Stavros Sachtouris | rel_path = rel_path.replace(path.sep, '/')
|
1125 | 14d15eca | Stavros Sachtouris | pathfix = f.replace(path.sep, '/')
|
1126 | 14d15eca | Stavros Sachtouris | yield open(fpath, 'rb'), '%s/%s' % (rel_path, pathfix) |
1127 | b666ef82 | Stavros Sachtouris | else:
|
1128 | ff1c0296 | Stavros Sachtouris | self.error('%s is not a regular file' % fpath) |
1129 | b666ef82 | Stavros Sachtouris | else:
|
1130 | 14b25e00 | Stavros Sachtouris | if not path.isfile(lpath): |
1131 | 9d3cd179 | Stavros Sachtouris | raiseCLIError(('%s is not a regular file' % lpath) if ( |
1132 | a0a61f30 | Stavros Sachtouris | path.exists(lpath)) else '%s does not exist' % lpath) |
1133 | b666ef82 | Stavros Sachtouris | try:
|
1134 | b666ef82 | Stavros Sachtouris | robj = self.client.get_object_info(rpath)
|
1135 | b666ef82 | Stavros Sachtouris | if remote_path and self._is_dir(robj): |
1136 | 14d15eca | Stavros Sachtouris | rpath += '/%s' % (short_path.replace(path.sep, '/')) |
1137 | b666ef82 | Stavros Sachtouris | self.client.get_object_info(rpath)
|
1138 | b666ef82 | Stavros Sachtouris | if not self['overwrite']: |
1139 | b666ef82 | Stavros Sachtouris | raiseCLIError( |
1140 | b666ef82 | Stavros Sachtouris | 'Object %s already exists' % rpath,
|
1141 | b666ef82 | Stavros Sachtouris | importance=1,
|
1142 | b666ef82 | Stavros Sachtouris | details=['use -f to overwrite or resume'])
|
1143 | b666ef82 | Stavros Sachtouris | except ClientError as ce: |
1144 | ff1c0296 | Stavros Sachtouris | if ce.status not in (404, ): |
1145 | b666ef82 | Stavros Sachtouris | raise
|
1146 | 2d158d8b | Stavros Sachtouris | self._check_container_limit(lpath)
|
1147 | b666ef82 | Stavros Sachtouris | yield open(lpath, 'rb'), rpath |
1148 | 706fc940 | Stavros Sachtouris | |
1149 | 68858765 | Stavros Sachtouris | @errors.generic.all
|
1150 | 68858765 | Stavros Sachtouris | @errors.pithos.connection
|
1151 | 68858765 | Stavros Sachtouris | @errors.pithos.container
|
1152 | 68858765 | Stavros Sachtouris | @errors.pithos.object_path
|
1153 | 68858765 | Stavros Sachtouris | @errors.pithos.local_path
|
1154 | 68858765 | Stavros Sachtouris | def _run(self, local_path, remote_path): |
1155 | ff1c0296 | Stavros Sachtouris | if self['poolsize'] > 0: |
1156 | ff1c0296 | Stavros Sachtouris | self.client.MAX_THREADS = int(self['poolsize']) |
1157 | 72952f4f | Stavros Sachtouris | params = dict(
|
1158 | 72952f4f | Stavros Sachtouris | content_encoding=self['content_encoding'], |
1159 | 2fe2672e | Stavros Sachtouris | content_type=self['content_type'], |
1160 | 2fe2672e | Stavros Sachtouris | content_disposition=self['content_disposition'], |
1161 | 2fe2672e | Stavros Sachtouris | sharing=self['sharing'], |
1162 | 2fe2672e | Stavros Sachtouris | public=self['public']) |
1163 | 0e728dcb | Stavros Sachtouris | uploaded = [] |
1164 | 74c65e80 | Stavros Sachtouris | container_info_cache = dict()
|
1165 | b666ef82 | Stavros Sachtouris | for f, rpath in self._path_pairs(local_path, remote_path): |
1166 | ff1c0296 | Stavros Sachtouris | self.error('%s --> %s:%s' % (f.name, self.client.container, rpath)) |
1167 | f8426b5c | Stavros Sachtouris | if not (self['content_type'] and self['content_encoding']): |
1168 | f8426b5c | Stavros Sachtouris | ctype, cenc = guess_mime_type(f.name) |
1169 | f8426b5c | Stavros Sachtouris | params['content_type'] = self['content_type'] or ctype |
1170 | f8426b5c | Stavros Sachtouris | params['content_encoding'] = self['content_encoding'] or cenc |
1171 | 68858765 | Stavros Sachtouris | if self['unchunked']: |
1172 | 0e728dcb | Stavros Sachtouris | r = self.client.upload_object_unchunked(
|
1173 | b666ef82 | Stavros Sachtouris | rpath, f, |
1174 | b666ef82 | Stavros Sachtouris | etag=self['etag'], withHashFile=self['use_hashes'], |
1175 | 68858765 | Stavros Sachtouris | **params) |
1176 | 8fb0acd2 | Stavros Sachtouris | if self['with_output'] or self['json_output']: |
1177 | 0e728dcb | Stavros Sachtouris | r['name'] = '%s: %s' % (self.client.container, rpath) |
1178 | 0e728dcb | Stavros Sachtouris | uploaded.append(r) |
1179 | 68858765 | Stavros Sachtouris | else:
|
1180 | 68858765 | Stavros Sachtouris | try:
|
1181 | 68858765 | Stavros Sachtouris | (progress_bar, upload_cb) = self._safe_progress_bar(
|
1182 | b666ef82 | Stavros Sachtouris | 'Uploading %s' % f.name.split(path.sep)[-1]) |
1183 | 68858765 | Stavros Sachtouris | if progress_bar:
|
1184 | 68858765 | Stavros Sachtouris | hash_bar = progress_bar.clone() |
1185 | 68858765 | Stavros Sachtouris | hash_cb = hash_bar.get_generator( |
1186 | 278c9018 | Stavros Sachtouris | 'Calculating block hashes')
|
1187 | 68858765 | Stavros Sachtouris | else:
|
1188 | 68858765 | Stavros Sachtouris | hash_cb = None
|
1189 | 0e728dcb | Stavros Sachtouris | r = self.client.upload_object(
|
1190 | b666ef82 | Stavros Sachtouris | rpath, f, |
1191 | 74c65e80 | Stavros Sachtouris | hash_cb=hash_cb, |
1192 | 74c65e80 | Stavros Sachtouris | upload_cb=upload_cb, |
1193 | 74c65e80 | Stavros Sachtouris | container_info_cache=container_info_cache, |
1194 | 852a22e7 | Stavros Sachtouris | **params) |
1195 | 8fb0acd2 | Stavros Sachtouris | if self['with_output'] or self['json_output']: |
1196 | 0e728dcb | Stavros Sachtouris | r['name'] = '%s: %s' % (self.client.container, rpath) |
1197 | 0e728dcb | Stavros Sachtouris | uploaded.append(r) |
1198 | 68858765 | Stavros Sachtouris | except Exception: |
1199 | 68858765 | Stavros Sachtouris | self._safe_progress_bar_finish(progress_bar)
|
1200 | 68858765 | Stavros Sachtouris | raise
|
1201 | 68858765 | Stavros Sachtouris | finally:
|
1202 | 68858765 | Stavros Sachtouris | self._safe_progress_bar_finish(progress_bar)
|
1203 | d9301a7a | Stavros Sachtouris | self._optional_output(uploaded)
|
1204 | ff1c0296 | Stavros Sachtouris | self.error('Upload completed') |
1205 | 7493ccb6 | Stavros Sachtouris | |
1206 | 68858765 | Stavros Sachtouris | def main(self, local_path, container____path__=None): |
1207 | 68858765 | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
1208 | 9e0a1a4c | Stavros Sachtouris | remote_path = self.path or path.basename(path.abspath(local_path)) |
1209 | 68858765 | Stavros Sachtouris | self._run(local_path=local_path, remote_path=remote_path)
|
1210 | 68858765 | Stavros Sachtouris | |
1211 | 234954d1 | Stavros Sachtouris | |
1212 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1213 | 3ae60112 | Stavros Sachtouris | class file_cat(_file_container_command): |
1214 | 72952f4f | Stavros Sachtouris | """Print remote file contents to console"""
|
1215 | 9ceec15a | Stavros Sachtouris | |
1216 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1217 | 2fe2672e | Stavros Sachtouris | range=RangeArgument('show range of data', '--range'), |
1218 | 2fe2672e | Stavros Sachtouris | if_match=ValueArgument('show output if ETags match', '--if-match'), |
1219 | 2fe2672e | Stavros Sachtouris | if_none_match=ValueArgument( |
1220 | 201baa17 | Stavros Sachtouris | 'show output if ETags match', '--if-none-match'), |
1221 | 2fe2672e | Stavros Sachtouris | if_modified_since=DateArgument( |
1222 | 201baa17 | Stavros Sachtouris | 'show output modified since then', '--if-modified-since'), |
1223 | 2fe2672e | Stavros Sachtouris | if_unmodified_since=DateArgument( |
1224 | 201baa17 | Stavros Sachtouris | 'show output unmodified since then', '--if-unmodified-since'), |
1225 | 2fe2672e | Stavros Sachtouris | object_version=ValueArgument( |
1226 | 201baa17 | Stavros Sachtouris | 'get the specific version', ('-O', '--object-version')) |
1227 | 2fe2672e | Stavros Sachtouris | ) |
1228 | 2fe2672e | Stavros Sachtouris | |
1229 | 68858765 | Stavros Sachtouris | @errors.generic.all
|
1230 | 68858765 | Stavros Sachtouris | @errors.pithos.connection
|
1231 | 68858765 | Stavros Sachtouris | @errors.pithos.container
|
1232 | 68858765 | Stavros Sachtouris | @errors.pithos.object_path
|
1233 | 68858765 | Stavros Sachtouris | def _run(self): |
1234 | 68858765 | Stavros Sachtouris | self.client.download_object(
|
1235 | ff1c0296 | Stavros Sachtouris | self.path, self._out, |
1236 | 3d568c09 | Stavros Sachtouris | range_str=self['range'], |
1237 | 2fe2672e | Stavros Sachtouris | version=self['object_version'], |
1238 | 2fe2672e | Stavros Sachtouris | if_match=self['if_match'], |
1239 | 2fe2672e | Stavros Sachtouris | if_none_match=self['if_none_match'], |
1240 | 2fe2672e | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
1241 | 2fe2672e | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since']) |
1242 | 68858765 | Stavros Sachtouris | |
1243 | 68858765 | Stavros Sachtouris | def main(self, container___path): |
1244 | 68858765 | Stavros Sachtouris | super(self.__class__, self)._run( |
1245 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1246 | 68858765 | Stavros Sachtouris | self._run()
|
1247 | 9ceec15a | Stavros Sachtouris | |
1248 | 234954d1 | Stavros Sachtouris | |
1249 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1250 | 3ae60112 | Stavros Sachtouris | class file_download(_file_container_command): |
1251 | ae99b37d | Stavros Sachtouris | """Download remote object as local file
|
1252 | ae99b37d | Stavros Sachtouris | If local destination is a directory:
|
1253 | f40f0cb7 | Stavros Sachtouris | * download <container>:<path> <local dir> -R
|
1254 | ae99b37d | Stavros Sachtouris | will download all files on <container> prefixed as <path>,
|
1255 | c626151a | Stavros Sachtouris | to <local dir>/<full path> (or <local dir>\<full path> in windows)
|
1256 | fa9c0c38 | Stavros Sachtouris | * download <container>:<path> <local dir>
|
1257 | fa9c0c38 | Stavros Sachtouris | will download only one file<path>
|
1258 | f6c09d14 | Stavros Sachtouris | ATTENTION: to download cont:dir1/dir2/file there must exist objects
|
1259 | f6c09d14 | Stavros Sachtouris | cont:dir1 and cont:dir1/dir2 of type application/directory
|
1260 | 3ae60112 | Stavros Sachtouris | To create directory objects, use /file mkdir
|
1261 | ae99b37d | Stavros Sachtouris | """
|
1262 | 7493ccb6 | Stavros Sachtouris | |
1263 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1264 | f40f0cb7 | Stavros Sachtouris | resume=FlagArgument('Resume instead of overwrite', ('-r', '--resume')), |
1265 | 2fe2672e | Stavros Sachtouris | range=RangeArgument('show range of data', '--range'), |
1266 | 2fe2672e | Stavros Sachtouris | if_match=ValueArgument('show output if ETags match', '--if-match'), |
1267 | 2fe2672e | Stavros Sachtouris | if_none_match=ValueArgument( |
1268 | 201baa17 | Stavros Sachtouris | 'show output if ETags match', '--if-none-match'), |
1269 | 2fe2672e | Stavros Sachtouris | if_modified_since=DateArgument( |
1270 | 201baa17 | Stavros Sachtouris | 'show output modified since then', '--if-modified-since'), |
1271 | 2fe2672e | Stavros Sachtouris | if_unmodified_since=DateArgument( |
1272 | 201baa17 | Stavros Sachtouris | 'show output unmodified since then', '--if-unmodified-since'), |
1273 | 2fe2672e | Stavros Sachtouris | object_version=ValueArgument( |
1274 | 201baa17 | Stavros Sachtouris | 'get the specific version', ('-O', '--object-version')), |
1275 | 2fe2672e | Stavros Sachtouris | poolsize=IntArgument('set pool size', '--with-pool-size'), |
1276 | 2fe2672e | Stavros Sachtouris | progress_bar=ProgressBarArgument( |
1277 | ff1c0296 | Stavros Sachtouris | 'do not show progress bar', ('-N', '--no-progress-bar'), |
1278 | ae99b37d | Stavros Sachtouris | default=False),
|
1279 | f6c09d14 | Stavros Sachtouris | recursive=FlagArgument( |
1280 | ff1c0296 | Stavros Sachtouris | 'Download a remote path and its contents', ('-R', '--recursive')) |
1281 | 2fe2672e | Stavros Sachtouris | ) |
1282 | 7493ccb6 | Stavros Sachtouris | |
1283 | f6c09d14 | Stavros Sachtouris | def _outputs(self, local_path): |
1284 | a3ba3bce | Stavros Sachtouris | """:returns: (local_file, remote_path)"""
|
1285 | a3ba3bce | Stavros Sachtouris | remotes = [] |
1286 | a3ba3bce | Stavros Sachtouris | if self['recursive']: |
1287 | a3ba3bce | Stavros Sachtouris | r = self.client.container_get(
|
1288 | a3ba3bce | Stavros Sachtouris | prefix=self.path or '/', |
1289 | f6c09d14 | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
1290 | f6c09d14 | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since']) |
1291 | a3ba3bce | Stavros Sachtouris | dirlist = dict()
|
1292 | a3ba3bce | Stavros Sachtouris | for remote in r.json: |
1293 | a3ba3bce | Stavros Sachtouris | rname = remote['name'].strip('/') |
1294 | a3ba3bce | Stavros Sachtouris | tmppath = ''
|
1295 | a3ba3bce | Stavros Sachtouris | for newdir in rname.strip('/').split('/')[:-1]: |
1296 | a3ba3bce | Stavros Sachtouris | tmppath = '/'.join([tmppath, newdir])
|
1297 | a3ba3bce | Stavros Sachtouris | dirlist.update({tmppath.strip('/'): True}) |
1298 | 3ae60112 | Stavros Sachtouris | remotes.append((rname, file_download._is_dir(remote))) |
1299 | a3ba3bce | Stavros Sachtouris | dir_remotes = [r[0] for r in remotes if r[1]] |
1300 | a3ba3bce | Stavros Sachtouris | if not set(dirlist).issubset(dir_remotes): |
1301 | a3ba3bce | Stavros Sachtouris | badguys = [bg.strip('/') for bg in set( |
1302 | a3ba3bce | Stavros Sachtouris | dirlist).difference(dir_remotes)] |
1303 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1304 | a3ba3bce | Stavros Sachtouris | 'Some remote paths contain non existing directories',
|
1305 | a3ba3bce | Stavros Sachtouris | details=['Missing remote directories:'] + badguys)
|
1306 | a3ba3bce | Stavros Sachtouris | elif self.path: |
1307 | a3ba3bce | Stavros Sachtouris | r = self.client.get_object_info(
|
1308 | a3ba3bce | Stavros Sachtouris | self.path,
|
1309 | a3ba3bce | Stavros Sachtouris | version=self['object_version']) |
1310 | 3ae60112 | Stavros Sachtouris | if file_download._is_dir(r):
|
1311 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1312 | a3ba3bce | Stavros Sachtouris | 'Illegal download: Remote object %s is a directory' % (
|
1313 | a3ba3bce | Stavros Sachtouris | self.path),
|
1314 | 14d15eca | Stavros Sachtouris | details=['To download a directory, try --recursive or -R'])
|
1315 | a3ba3bce | Stavros Sachtouris | if '/' in self.path.strip('/') and not local_path: |
1316 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1317 | a3ba3bce | Stavros Sachtouris | 'Illegal download: remote object %s contains "/"' % (
|
1318 | a3ba3bce | Stavros Sachtouris | self.path),
|
1319 | a3ba3bce | Stavros Sachtouris | details=[ |
1320 | a3ba3bce | Stavros Sachtouris | 'To download an object containing "/" characters',
|
1321 | a3ba3bce | Stavros Sachtouris | 'either create the remote directories or',
|
1322 | a3ba3bce | Stavros Sachtouris | 'specify a non-directory local path for this object'])
|
1323 | a3ba3bce | Stavros Sachtouris | remotes = [(self.path, False)] |
1324 | a3ba3bce | Stavros Sachtouris | if not remotes: |
1325 | a3ba3bce | Stavros Sachtouris | if self.path: |
1326 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1327 | a3ba3bce | Stavros Sachtouris | 'No matching path %s on container %s' % (
|
1328 | 14d15eca | Stavros Sachtouris | self.path, self.container), |
1329 | a3ba3bce | Stavros Sachtouris | details=[ |
1330 | a3ba3bce | Stavros Sachtouris | 'To list the contents of %s, try:' % self.container, |
1331 | 3ae60112 | Stavros Sachtouris | ' /file list %s' % self.container]) |
1332 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1333 | a3ba3bce | Stavros Sachtouris | 'Illegal download of container %s' % self.container, |
1334 | a3ba3bce | Stavros Sachtouris | details=[ |
1335 | a3ba3bce | Stavros Sachtouris | 'To download a whole container, try:',
|
1336 | 3ae60112 | Stavros Sachtouris | ' /file download --recursive <container>'])
|
1337 | a3ba3bce | Stavros Sachtouris | |
1338 | a3ba3bce | Stavros Sachtouris | lprefix = path.abspath(local_path or path.curdir)
|
1339 | a3ba3bce | Stavros Sachtouris | if path.isdir(lprefix):
|
1340 | a3ba3bce | Stavros Sachtouris | for rpath, remote_is_dir in remotes: |
1341 | 14d15eca | Stavros Sachtouris | lpath = path.sep.join([ |
1342 | 14d15eca | Stavros Sachtouris | lprefix[:-1] if lprefix.endswith(path.sep) else lprefix, |
1343 | 14d15eca | Stavros Sachtouris | rpath.strip('/').replace('/', path.sep)]) |
1344 | a3ba3bce | Stavros Sachtouris | if remote_is_dir:
|
1345 | a3ba3bce | Stavros Sachtouris | if path.exists(lpath) and path.isdir(lpath): |
1346 | a3ba3bce | Stavros Sachtouris | continue
|
1347 | a3ba3bce | Stavros Sachtouris | makedirs(lpath) |
1348 | a3ba3bce | Stavros Sachtouris | elif path.exists(lpath):
|
1349 | a3ba3bce | Stavros Sachtouris | if not self['resume']: |
1350 | ff1c0296 | Stavros Sachtouris | self.error('File %s exists, aborting...' % lpath) |
1351 | a3ba3bce | Stavros Sachtouris | continue
|
1352 | a3ba3bce | Stavros Sachtouris | with open(lpath, 'rwb+') as f: |
1353 | a3ba3bce | Stavros Sachtouris | yield (f, rpath)
|
1354 | a3ba3bce | Stavros Sachtouris | else:
|
1355 | a3ba3bce | Stavros Sachtouris | with open(lpath, 'wb+') as f: |
1356 | a3ba3bce | Stavros Sachtouris | yield (f, rpath)
|
1357 | a3ba3bce | Stavros Sachtouris | elif path.exists(lprefix):
|
1358 | a3ba3bce | Stavros Sachtouris | if len(remotes) > 1: |
1359 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1360 | a3ba3bce | Stavros Sachtouris | '%s remote objects cannot be merged in local file %s' % (
|
1361 | a3ba3bce | Stavros Sachtouris | len(remotes),
|
1362 | a3ba3bce | Stavros Sachtouris | local_path), |
1363 | a3ba3bce | Stavros Sachtouris | details=[ |
1364 | a3ba3bce | Stavros Sachtouris | 'To download multiple objects, local path should be',
|
1365 | a3ba3bce | Stavros Sachtouris | 'a directory, or use download without a local path'])
|
1366 | a3ba3bce | Stavros Sachtouris | (rpath, remote_is_dir) = remotes[0]
|
1367 | a3ba3bce | Stavros Sachtouris | if remote_is_dir:
|
1368 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1369 | a3ba3bce | Stavros Sachtouris | 'Remote directory %s should not replace local file %s' % (
|
1370 | a3ba3bce | Stavros Sachtouris | rpath, |
1371 | a3ba3bce | Stavros Sachtouris | local_path)) |
1372 | a3ba3bce | Stavros Sachtouris | if self['resume']: |
1373 | a3ba3bce | Stavros Sachtouris | with open(lprefix, 'rwb+') as f: |
1374 | a3ba3bce | Stavros Sachtouris | yield (f, rpath)
|
1375 | a3ba3bce | Stavros Sachtouris | else:
|
1376 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1377 | db36a6a7 | Stavros Sachtouris | 'Local file %s already exist' % local_path,
|
1378 | db36a6a7 | Stavros Sachtouris | details=['Try --resume to overwrite it'])
|
1379 | a3ba3bce | Stavros Sachtouris | else:
|
1380 | a3ba3bce | Stavros Sachtouris | if len(remotes) > 1 or remotes[0][1]: |
1381 | a3ba3bce | Stavros Sachtouris | raiseCLIError( |
1382 | a3ba3bce | Stavros Sachtouris | 'Local directory %s does not exist' % local_path)
|
1383 | a3ba3bce | Stavros Sachtouris | with open(lprefix, 'wb+') as f: |
1384 | a3ba3bce | Stavros Sachtouris | yield (f, remotes[0][0]) |
1385 | 7493ccb6 | Stavros Sachtouris | |
1386 | 68858765 | Stavros Sachtouris | @errors.generic.all
|
1387 | 68858765 | Stavros Sachtouris | @errors.pithos.connection
|
1388 | 68858765 | Stavros Sachtouris | @errors.pithos.container
|
1389 | 68858765 | Stavros Sachtouris | @errors.pithos.object_path
|
1390 | 68858765 | Stavros Sachtouris | @errors.pithos.local_path
|
1391 | 68858765 | Stavros Sachtouris | def _run(self, local_path): |
1392 | 2fe2672e | Stavros Sachtouris | poolsize = self['poolsize'] |
1393 | 68858765 | Stavros Sachtouris | if poolsize:
|
1394 | 16b0afe6 | Stavros Sachtouris | self.client.MAX_THREADS = int(poolsize) |
1395 | f6c09d14 | Stavros Sachtouris | progress_bar = None
|
1396 | ae99b37d | Stavros Sachtouris | try:
|
1397 | a3ba3bce | Stavros Sachtouris | for f, rpath in self._outputs(local_path): |
1398 | 3d568c09 | Stavros Sachtouris | ( |
1399 | 3d568c09 | Stavros Sachtouris | progress_bar, |
1400 | a3ba3bce | Stavros Sachtouris | download_cb) = self._safe_progress_bar(
|
1401 | a3ba3bce | Stavros Sachtouris | 'Download %s' % rpath)
|
1402 | ae99b37d | Stavros Sachtouris | self.client.download_object(
|
1403 | 5655d560 | Stavros Sachtouris | rpath, f, |
1404 | ae99b37d | Stavros Sachtouris | download_cb=download_cb, |
1405 | 3d568c09 | Stavros Sachtouris | range_str=self['range'], |
1406 | ae99b37d | Stavros Sachtouris | version=self['object_version'], |
1407 | ae99b37d | Stavros Sachtouris | if_match=self['if_match'], |
1408 | ae99b37d | Stavros Sachtouris | resume=self['resume'], |
1409 | ae99b37d | Stavros Sachtouris | if_none_match=self['if_none_match'], |
1410 | ae99b37d | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
1411 | ae99b37d | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since']) |
1412 | 7493ccb6 | Stavros Sachtouris | except KeyboardInterrupt: |
1413 | b78ee581 | Stavros Sachtouris | from threading import activeCount, enumerate as activethreads |
1414 | cae76f25 | Stavros Sachtouris | timeout = 0.5
|
1415 | b78ee581 | Stavros Sachtouris | while activeCount() > 1: |
1416 | 1757c616 | Stavros Sachtouris | self._out.write('\nCancel %s threads: ' % (activeCount() - 1)) |
1417 | 1757c616 | Stavros Sachtouris | self._out.flush()
|
1418 | b78ee581 | Stavros Sachtouris | for thread in activethreads(): |
1419 | b78ee581 | Stavros Sachtouris | try:
|
1420 | cae76f25 | Stavros Sachtouris | thread.join(timeout) |
1421 | 1757c616 | Stavros Sachtouris | self._out.write('.' if thread.isAlive() else '*') |
1422 | b78ee581 | Stavros Sachtouris | except RuntimeError: |
1423 | b78ee581 | Stavros Sachtouris | continue
|
1424 | cae76f25 | Stavros Sachtouris | finally:
|
1425 | 1757c616 | Stavros Sachtouris | self._out.flush()
|
1426 | cae76f25 | Stavros Sachtouris | timeout += 0.1
|
1427 | ff1c0296 | Stavros Sachtouris | self.error('\nDownload canceled by user') |
1428 | 7493ccb6 | Stavros Sachtouris | if local_path is not None: |
1429 | ff1c0296 | Stavros Sachtouris | self.error('to resume, re-run with --resume') |
1430 | 68858765 | Stavros Sachtouris | except Exception: |
1431 | 68858765 | Stavros Sachtouris | self._safe_progress_bar_finish(progress_bar)
|
1432 | 68858765 | Stavros Sachtouris | raise
|
1433 | 68858765 | Stavros Sachtouris | finally:
|
1434 | 68858765 | Stavros Sachtouris | self._safe_progress_bar_finish(progress_bar)
|
1435 | 68858765 | Stavros Sachtouris | |
1436 | 68858765 | Stavros Sachtouris | def main(self, container___path, local_path=None): |
1437 | a3ba3bce | Stavros Sachtouris | super(self.__class__, self)._run(container___path) |
1438 | 68858765 | Stavros Sachtouris | self._run(local_path=local_path)
|
1439 | 7493ccb6 | Stavros Sachtouris | |
1440 | 234954d1 | Stavros Sachtouris | |
1441 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1442 | 545c6c29 | Stavros Sachtouris | class file_hashmap(_file_container_command, _optional_json): |
1443 | 72952f4f | Stavros Sachtouris | """Get the hash-map of an object"""
|
1444 | 7493ccb6 | Stavros Sachtouris | |
1445 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1446 | 2fe2672e | Stavros Sachtouris | if_match=ValueArgument('show output if ETags match', '--if-match'), |
1447 | 2fe2672e | Stavros Sachtouris | if_none_match=ValueArgument( |
1448 | 545c6c29 | Stavros Sachtouris | 'show output if ETags match', '--if-none-match'), |
1449 | 2fe2672e | Stavros Sachtouris | if_modified_since=DateArgument( |
1450 | 545c6c29 | Stavros Sachtouris | 'show output modified since then', '--if-modified-since'), |
1451 | 2fe2672e | Stavros Sachtouris | if_unmodified_since=DateArgument( |
1452 | 545c6c29 | Stavros Sachtouris | 'show output unmodified since then', '--if-unmodified-since'), |
1453 | 2fe2672e | Stavros Sachtouris | object_version=ValueArgument( |
1454 | 545c6c29 | Stavros Sachtouris | 'get the specific version', ('-O', '--object-version')) |
1455 | 2fe2672e | Stavros Sachtouris | ) |
1456 | 7493ccb6 | Stavros Sachtouris | |
1457 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1458 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1459 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1460 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1461 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1462 | 545c6c29 | Stavros Sachtouris | self._print(self.client.get_object_hashmap( |
1463 | b4cf92b8 | Stavros Sachtouris | self.path,
|
1464 | b4cf92b8 | Stavros Sachtouris | version=self['object_version'], |
1465 | b4cf92b8 | Stavros Sachtouris | if_match=self['if_match'], |
1466 | b4cf92b8 | Stavros Sachtouris | if_none_match=self['if_none_match'], |
1467 | b4cf92b8 | Stavros Sachtouris | if_modified_since=self['if_modified_since'], |
1468 | 76f58e2e | Stavros Sachtouris | if_unmodified_since=self['if_unmodified_since']), self.print_dict) |
1469 | b4cf92b8 | Stavros Sachtouris | |
1470 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path): |
1471 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run( |
1472 | ff1c0296 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1473 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1474 | 7493ccb6 | Stavros Sachtouris | |
1475 | 234954d1 | Stavros Sachtouris | |
1476 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1477 | 915b99b5 | Stavros Sachtouris | class file_delete(_file_container_command, _optional_output_cmd): |
1478 | 72952f4f | Stavros Sachtouris | """Delete a container [or an object]
|
1479 | 72952f4f | Stavros Sachtouris | How to delete a non-empty container:
|
1480 | 3ae60112 | Stavros Sachtouris | - empty the container: /file delete -R <container>
|
1481 | 3ae60112 | Stavros Sachtouris | - delete it: /file delete <container>
|
1482 | 72952f4f | Stavros Sachtouris | .
|
1483 | 72952f4f | Stavros Sachtouris | Semantics of directory deletion:
|
1484 | 3ae60112 | Stavros Sachtouris | .a preserve the contents: /file delete <container>:<directory>
|
1485 | 72952f4f | Stavros Sachtouris | . objects of the form dir/filename can exist with a dir object
|
1486 | 3ae60112 | Stavros Sachtouris | .b delete contents: /file delete -R <container>:<directory>
|
1487 | 72952f4f | Stavros Sachtouris | . all dir/* objects are affected, even if dir does not exist
|
1488 | 72952f4f | Stavros Sachtouris | .
|
1489 | 72952f4f | Stavros Sachtouris | To restore a deleted object OBJ in a container CONT:
|
1490 | 3ae60112 | Stavros Sachtouris | - get object versions: /file versions CONT:OBJ
|
1491 | 72952f4f | Stavros Sachtouris | . and choose the version to be restored
|
1492 | 3ae60112 | Stavros Sachtouris | - restore the object: /file copy --source-version=<version> CONT:OBJ OBJ
|
1493 | 72952f4f | Stavros Sachtouris | """
|
1494 | 7493ccb6 | Stavros Sachtouris | |
1495 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1496 | 439826ec | Stavros Sachtouris | until=DateArgument('remove history until that date', '--until'), |
1497 | 7147e1ca | Stavros Sachtouris | yes=FlagArgument('Do not prompt for permission', '--yes'), |
1498 | 2fe2672e | Stavros Sachtouris | recursive=FlagArgument( |
1499 | 234954d1 | Stavros Sachtouris | 'empty dir or container and delete (if dir)',
|
1500 | 1757c616 | Stavros Sachtouris | ('-R', '--recursive')), |
1501 | 1757c616 | Stavros Sachtouris | delimiter=ValueArgument( |
1502 | 1757c616 | Stavros Sachtouris | 'delete objects prefixed with <object><delimiter>', '--delimiter') |
1503 | 2fe2672e | Stavros Sachtouris | ) |
1504 | 2fe2672e | Stavros Sachtouris | |
1505 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1506 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1507 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1508 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1509 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1510 | b4cf92b8 | Stavros Sachtouris | if self.path: |
1511 | 76f58e2e | Stavros Sachtouris | if self['yes'] or self.ask_user( |
1512 | 76f58e2e | Stavros Sachtouris | 'Delete %s:%s ?' % (self.container, self.path)): |
1513 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.del_object( |
1514 | b4cf92b8 | Stavros Sachtouris | self.path,
|
1515 | 1757c616 | Stavros Sachtouris | until=self['until'], |
1516 | 1757c616 | Stavros Sachtouris | delimiter='/' if self['recursive'] else self['delimiter'])) |
1517 | 7493ccb6 | Stavros Sachtouris | else:
|
1518 | ff1c0296 | Stavros Sachtouris | self.error('Aborted') |
1519 | cf115aed | Stavros Sachtouris | elif self.container: |
1520 | 24ff0a35 | Stavros Sachtouris | if self['recursive']: |
1521 | de73876b | Stavros Sachtouris | ask_msg = 'Delete container contents'
|
1522 | de73876b | Stavros Sachtouris | else:
|
1523 | de73876b | Stavros Sachtouris | ask_msg = 'Delete container'
|
1524 | 76f58e2e | Stavros Sachtouris | if self['yes'] or self.ask_user( |
1525 | 76f58e2e | Stavros Sachtouris | '%s %s ?' % (ask_msg, self.container)): |
1526 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.del_container( |
1527 | 1757c616 | Stavros Sachtouris | until=self['until'], |
1528 | 1757c616 | Stavros Sachtouris | delimiter='/' if self['recursive'] else self['delimiter'])) |
1529 | b4cf92b8 | Stavros Sachtouris | else:
|
1530 | ff1c0296 | Stavros Sachtouris | self.error('Aborted') |
1531 | cf115aed | Stavros Sachtouris | else:
|
1532 | cf115aed | Stavros Sachtouris | raiseCLIError('Nothing to delete, please provide container[:path]')
|
1533 | b4cf92b8 | Stavros Sachtouris | |
1534 | edab7ba7 | Stavros Sachtouris | def main(self, container____path__=None): |
1535 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
1536 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1537 | 7493ccb6 | Stavros Sachtouris | |
1538 | 234954d1 | Stavros Sachtouris | |
1539 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1540 | 915b99b5 | Stavros Sachtouris | class file_purge(_file_container_command, _optional_output_cmd): |
1541 | 72952f4f | Stavros Sachtouris | """Delete a container and release related data blocks
|
1542 | 72952f4f | Stavros Sachtouris | Non-empty containers can not purged.
|
1543 | 72952f4f | Stavros Sachtouris | To purge a container with content:
|
1544 | 3ae60112 | Stavros Sachtouris | . /file delete -R <container>
|
1545 | 72952f4f | Stavros Sachtouris | . objects are deleted, but data blocks remain on server
|
1546 | 3ae60112 | Stavros Sachtouris | . /file purge <container>
|
1547 | 72952f4f | Stavros Sachtouris | . container and data blocks are released and deleted
|
1548 | 2fe2672e | Stavros Sachtouris | """
|
1549 | 234954d1 | Stavros Sachtouris | |
1550 | 7147e1ca | Stavros Sachtouris | arguments = dict(
|
1551 | 7147e1ca | Stavros Sachtouris | yes=FlagArgument('Do not prompt for permission', '--yes'), |
1552 | 915b99b5 | Stavros Sachtouris | force=FlagArgument('purge even if not empty', ('-F', '--force')) |
1553 | 7147e1ca | Stavros Sachtouris | ) |
1554 | 7147e1ca | Stavros Sachtouris | |
1555 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1556 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1557 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1558 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1559 | 76f58e2e | Stavros Sachtouris | if self['yes'] or self.ask_user( |
1560 | 76f58e2e | Stavros Sachtouris | 'Purge container %s?' % self.container): |
1561 | be4a8ccd | Stavros Sachtouris | try:
|
1562 | 5655d560 | Stavros Sachtouris | r = self.client.purge_container()
|
1563 | be4a8ccd | Stavros Sachtouris | except ClientError as ce: |
1564 | be4a8ccd | Stavros Sachtouris | if ce.status in (409,): |
1565 | be4a8ccd | Stavros Sachtouris | if self['force']: |
1566 | be4a8ccd | Stavros Sachtouris | self.client.del_container(delimiter='/') |
1567 | 5655d560 | Stavros Sachtouris | r = self.client.purge_container()
|
1568 | be4a8ccd | Stavros Sachtouris | else:
|
1569 | be4a8ccd | Stavros Sachtouris | raiseCLIError(ce, details=['Try -F to force-purge'])
|
1570 | be4a8ccd | Stavros Sachtouris | else:
|
1571 | be4a8ccd | Stavros Sachtouris | raise
|
1572 | 915b99b5 | Stavros Sachtouris | self._optional_output(r)
|
1573 | b4cf92b8 | Stavros Sachtouris | else:
|
1574 | ff1c0296 | Stavros Sachtouris | self.error('Aborted') |
1575 | b4cf92b8 | Stavros Sachtouris | |
1576 | 52edad0a | Stavros Sachtouris | def main(self, container=None): |
1577 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run(container) |
1578 | 52edad0a | Stavros Sachtouris | if container and self.container != container: |
1579 | 52edad0a | Stavros Sachtouris | raiseCLIError('Invalid container name %s' % container, details=[
|
1580 | 52edad0a | Stavros Sachtouris | 'Did you mean "%s" ?' % self.container, |
1581 | 52edad0a | Stavros Sachtouris | 'Use --container for names containing :'])
|
1582 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1583 | 7493ccb6 | Stavros Sachtouris | |
1584 | 234954d1 | Stavros Sachtouris | |
1585 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1586 | 3ae60112 | Stavros Sachtouris | class file_publish(_file_container_command): |
1587 | 2fe2672e | Stavros Sachtouris | """Publish the object and print the public url"""
|
1588 | 7493ccb6 | Stavros Sachtouris | |
1589 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1590 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1591 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1592 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1593 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1594 | b5578909 | Stavros Sachtouris | self.writeln(self.client.publish_object(self.path)) |
1595 | b4cf92b8 | Stavros Sachtouris | |
1596 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path): |
1597 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run( |
1598 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1599 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1600 | 7493ccb6 | Stavros Sachtouris | |
1601 | 234954d1 | Stavros Sachtouris | |
1602 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1603 | 915b99b5 | Stavros Sachtouris | class file_unpublish(_file_container_command, _optional_output_cmd): |
1604 | 7493ccb6 | Stavros Sachtouris | """Unpublish an object"""
|
1605 | 7493ccb6 | Stavros Sachtouris | |
1606 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1607 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1608 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1609 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1610 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1611 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.unpublish_object(self.path)) |
1612 | b4cf92b8 | Stavros Sachtouris | |
1613 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path): |
1614 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run( |
1615 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1616 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1617 | 7493ccb6 | Stavros Sachtouris | |
1618 | 234954d1 | Stavros Sachtouris | |
1619 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1620 | 5655d560 | Stavros Sachtouris | class file_permissions(_pithos_init): |
1621 | 5655d560 | Stavros Sachtouris | """Manage user and group accessibility for objects
|
1622 | 5655d560 | Stavros Sachtouris | Permissions are lists of users and user groups. There are read and write
|
1623 | 72952f4f | Stavros Sachtouris | permissions. Users and groups with write permission have also read
|
1624 | 72952f4f | Stavros Sachtouris | permission.
|
1625 | 72952f4f | Stavros Sachtouris | """
|
1626 | 7493ccb6 | Stavros Sachtouris | |
1627 | 5655d560 | Stavros Sachtouris | |
1628 | 5655d560 | Stavros Sachtouris | @command(pithos_cmds)
|
1629 | 545c6c29 | Stavros Sachtouris | class file_permissions_get(_file_container_command, _optional_json): |
1630 | 5655d560 | Stavros Sachtouris | """Get read and write permissions of an object"""
|
1631 | 5655d560 | Stavros Sachtouris | |
1632 | 76f58e2e | Stavros Sachtouris | def print_permissions(self, permissions_dict, out): |
1633 | 76f58e2e | Stavros Sachtouris | expected_keys = ('read', 'write') |
1634 | 76f58e2e | Stavros Sachtouris | if set(permissions_dict).issubset(expected_keys): |
1635 | 4f736175 | Stavros Sachtouris | self.print_dict(permissions_dict, out=out)
|
1636 | 76f58e2e | Stavros Sachtouris | else:
|
1637 | 76f58e2e | Stavros Sachtouris | invalid_keys = set(permissions_dict.keys()).difference(
|
1638 | 76f58e2e | Stavros Sachtouris | expected_keys) |
1639 | 76f58e2e | Stavros Sachtouris | raiseCLIError( |
1640 | 76f58e2e | Stavros Sachtouris | 'Illegal permission keys: %s' % ', '.join(invalid_keys), |
1641 | 76f58e2e | Stavros Sachtouris | importance=1, details=[
|
1642 | 76f58e2e | Stavros Sachtouris | 'Valid permission types: %s' % ' '.join(expected_keys)]) |
1643 | 76f58e2e | Stavros Sachtouris | |
1644 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1645 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1646 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1647 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1648 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1649 | 545c6c29 | Stavros Sachtouris | self._print(
|
1650 | 76f58e2e | Stavros Sachtouris | self.client.get_object_sharing(self.path), self.print_permissions) |
1651 | b4cf92b8 | Stavros Sachtouris | |
1652 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path): |
1653 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run( |
1654 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1655 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1656 | 7493ccb6 | Stavros Sachtouris | |
1657 | 234954d1 | Stavros Sachtouris | |
1658 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1659 | 915b99b5 | Stavros Sachtouris | class file_permissions_set(_file_container_command, _optional_output_cmd): |
1660 | 72952f4f | Stavros Sachtouris | """Set permissions for an object
|
1661 | 72952f4f | Stavros Sachtouris | New permissions overwrite existing permissions.
|
1662 | 72952f4f | Stavros Sachtouris | Permission format:
|
1663 | 72952f4f | Stavros Sachtouris | - read=<username>[,usergroup[,...]]
|
1664 | 72952f4f | Stavros Sachtouris | - write=<username>[,usegroup[,...]]
|
1665 | 72952f4f | Stavros Sachtouris | E.g. to give read permissions for file F to users A and B and write for C:
|
1666 | 5655d560 | Stavros Sachtouris | . /file permissions set F read=A,B write=C
|
1667 | 7df54888 | Stavros Sachtouris | To share with everybody, use '*' instead of a user id or group.
|
1668 | 7df54888 | Stavros Sachtouris | E.g. to make file F available to all pithos users:
|
1669 | 97086fcd | Stavros Sachtouris | . /file permissions set F read=*
|
1670 | 7df54888 | Stavros Sachtouris | E.g. to make file F available for editing to all pithos users:
|
1671 | 97086fcd | Stavros Sachtouris | . /file permissions set F write=*
|
1672 | 72952f4f | Stavros Sachtouris | """
|
1673 | 7493ccb6 | Stavros Sachtouris | |
1674 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1675 | 00336c85 | Stavros Sachtouris | def format_permission_dict(self, permissions): |
1676 | ff1c0296 | Stavros Sachtouris | read, write = False, False |
1677 | 3dabe5d2 | Stavros Sachtouris | for perms in permissions: |
1678 | 7493ccb6 | Stavros Sachtouris | splstr = perms.split('=')
|
1679 | 7493ccb6 | Stavros Sachtouris | if 'read' == splstr[0]: |
1680 | 24ff0a35 | Stavros Sachtouris | read = [ug.strip() for ug in splstr[1].split(',')] |
1681 | 7493ccb6 | Stavros Sachtouris | elif 'write' == splstr[0]: |
1682 | 24ff0a35 | Stavros Sachtouris | write = [ug.strip() for ug in splstr[1].split(',')] |
1683 | 7493ccb6 | Stavros Sachtouris | else:
|
1684 | 24ff0a35 | Stavros Sachtouris | msg = 'Usage:\tread=<groups,users> write=<groups,users>'
|
1685 | 24ff0a35 | Stavros Sachtouris | raiseCLIError(None, msg)
|
1686 | 234954d1 | Stavros Sachtouris | return (read, write)
|
1687 | 7493ccb6 | Stavros Sachtouris | |
1688 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1689 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1690 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1691 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1692 | b4cf92b8 | Stavros Sachtouris | def _run(self, read, write): |
1693 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.set_object_sharing( |
1694 | 201baa17 | Stavros Sachtouris | self.path, read_permission=read, write_permission=write))
|
1695 | b4cf92b8 | Stavros Sachtouris | |
1696 | 3dabe5d2 | Stavros Sachtouris | def main(self, container___path, *permissions): |
1697 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run( |
1698 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1699 | 201baa17 | Stavros Sachtouris | read, write = self.format_permission_dict(permissions)
|
1700 | b4cf92b8 | Stavros Sachtouris | self._run(read, write)
|
1701 | 7493ccb6 | Stavros Sachtouris | |
1702 | 234954d1 | Stavros Sachtouris | |
1703 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1704 | 915b99b5 | Stavros Sachtouris | class file_permissions_delete(_file_container_command, _optional_output_cmd): |
1705 | 72952f4f | Stavros Sachtouris | """Delete all permissions set on object
|
1706 | 5655d560 | Stavros Sachtouris | To modify permissions, use /file permissions set
|
1707 | 72952f4f | Stavros Sachtouris | """
|
1708 | 7493ccb6 | Stavros Sachtouris | |
1709 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1710 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1711 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1712 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1713 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1714 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.del_object_sharing(self.path)) |
1715 | b4cf92b8 | Stavros Sachtouris | |
1716 | 7493ccb6 | Stavros Sachtouris | def main(self, container___path): |
1717 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run( |
1718 | 201baa17 | Stavros Sachtouris | container___path, path_is_optional=False)
|
1719 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1720 | 7493ccb6 | Stavros Sachtouris | |
1721 | 234954d1 | Stavros Sachtouris | |
1722 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1723 | 545c6c29 | Stavros Sachtouris | class file_info(_file_container_command, _optional_json): |
1724 | 72952f4f | Stavros Sachtouris | """Get detailed information for user account, containers or objects
|
1725 | 3ae60112 | Stavros Sachtouris | to get account info: /file info
|
1726 | 3ae60112 | Stavros Sachtouris | to get container info: /file info <container>
|
1727 | 3ae60112 | Stavros Sachtouris | to get object info: /file info <container>:<path>
|
1728 | 72952f4f | Stavros Sachtouris | """
|
1729 | 7493ccb6 | Stavros Sachtouris | |
1730 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1731 | 2fe2672e | Stavros Sachtouris | object_version=ValueArgument( |
1732 | 2fe2672e | Stavros Sachtouris | 'show specific version \ (applies only for objects)',
|
1733 | 545c6c29 | Stavros Sachtouris | ('-O', '--object-version')) |
1734 | 2fe2672e | Stavros Sachtouris | ) |
1735 | 6ac7f90f | Stavros Sachtouris | |
1736 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1737 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1738 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1739 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1740 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1741 | b4cf92b8 | Stavros Sachtouris | if self.container is None: |
1742 | b4cf92b8 | Stavros Sachtouris | r = self.client.get_account_info()
|
1743 | b4cf92b8 | Stavros Sachtouris | elif self.path is None: |
1744 | b4cf92b8 | Stavros Sachtouris | r = self.client.get_container_info(self.container) |
1745 | b4cf92b8 | Stavros Sachtouris | else:
|
1746 | b4cf92b8 | Stavros Sachtouris | r = self.client.get_object_info(
|
1747 | 201baa17 | Stavros Sachtouris | self.path, version=self['object_version']) |
1748 | 76f58e2e | Stavros Sachtouris | self._print(r, self.print_dict) |
1749 | b4cf92b8 | Stavros Sachtouris | |
1750 | 7493ccb6 | Stavros Sachtouris | def main(self, container____path__=None): |
1751 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
1752 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1753 | 7493ccb6 | Stavros Sachtouris | |
1754 | 234954d1 | Stavros Sachtouris | |
1755 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1756 | 5655d560 | Stavros Sachtouris | class file_metadata(_pithos_init): |
1757 | 5655d560 | Stavros Sachtouris | """Metadata are attached on objects. They are formed as key:value pairs.
|
1758 | 5655d560 | Stavros Sachtouris | They can have arbitary values.
|
1759 | 5655d560 | Stavros Sachtouris | """
|
1760 | 5655d560 | Stavros Sachtouris | |
1761 | 5655d560 | Stavros Sachtouris | |
1762 | 5655d560 | Stavros Sachtouris | @command(pithos_cmds)
|
1763 | 545c6c29 | Stavros Sachtouris | class file_metadata_get(_file_container_command, _optional_json): |
1764 | 72952f4f | Stavros Sachtouris | """Get metadata for account, containers or objects"""
|
1765 | 7493ccb6 | Stavros Sachtouris | |
1766 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
1767 | f40f0cb7 | Stavros Sachtouris | detail=FlagArgument('show detailed output', ('-l', '--details')), |
1768 | 2fe2672e | Stavros Sachtouris | until=DateArgument('show metadata until then', '--until'), |
1769 | 2fe2672e | Stavros Sachtouris | object_version=ValueArgument( |
1770 | c626151a | Stavros Sachtouris | 'show specific version (applies only for objects)',
|
1771 | 545c6c29 | Stavros Sachtouris | ('-O', '--object-version')) |
1772 | 2fe2672e | Stavros Sachtouris | ) |
1773 | 7493ccb6 | Stavros Sachtouris | |
1774 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1775 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1776 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1777 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1778 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1779 | b4cf92b8 | Stavros Sachtouris | until = self['until'] |
1780 | 545c6c29 | Stavros Sachtouris | r = None
|
1781 | b4cf92b8 | Stavros Sachtouris | if self.container is None: |
1782 | 0f383dcc | Stavros Sachtouris | r = self.client.get_account_info(until=until)
|
1783 | b4cf92b8 | Stavros Sachtouris | elif self.path is None: |
1784 | b4cf92b8 | Stavros Sachtouris | if self['detail']: |
1785 | b4cf92b8 | Stavros Sachtouris | r = self.client.get_container_info(until=until)
|
1786 | b4cf92b8 | Stavros Sachtouris | else:
|
1787 | b4cf92b8 | Stavros Sachtouris | cmeta = self.client.get_container_meta(until=until)
|
1788 | b4cf92b8 | Stavros Sachtouris | ometa = self.client.get_container_object_meta(until=until)
|
1789 | b4cf92b8 | Stavros Sachtouris | r = {} |
1790 | b4cf92b8 | Stavros Sachtouris | if cmeta:
|
1791 | 0f383dcc | Stavros Sachtouris | r['container-meta'] = cmeta
|
1792 | b4cf92b8 | Stavros Sachtouris | if ometa:
|
1793 | 0f383dcc | Stavros Sachtouris | r['object-meta'] = ometa
|
1794 | b4cf92b8 | Stavros Sachtouris | else:
|
1795 | b4cf92b8 | Stavros Sachtouris | if self['detail']: |
1796 | de73876b | Stavros Sachtouris | r = self.client.get_object_info(
|
1797 | de73876b | Stavros Sachtouris | self.path,
|
1798 | b4cf92b8 | Stavros Sachtouris | version=self['object_version']) |
1799 | b4cf92b8 | Stavros Sachtouris | else:
|
1800 | de73876b | Stavros Sachtouris | r = self.client.get_object_meta(
|
1801 | de73876b | Stavros Sachtouris | self.path,
|
1802 | b4cf92b8 | Stavros Sachtouris | version=self['object_version']) |
1803 | b4cf92b8 | Stavros Sachtouris | if r:
|
1804 | 76f58e2e | Stavros Sachtouris | self._print(r, self.print_dict) |
1805 | b4cf92b8 | Stavros Sachtouris | |
1806 | b4cf92b8 | Stavros Sachtouris | def main(self, container____path__=None): |
1807 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
1808 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1809 | 7493ccb6 | Stavros Sachtouris | |
1810 | 234954d1 | Stavros Sachtouris | |
1811 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1812 | 915b99b5 | Stavros Sachtouris | class file_metadata_set(_file_container_command, _optional_output_cmd): |
1813 | 5655d560 | Stavros Sachtouris | """Set a piece of metadata for account, container or object"""
|
1814 | 7493ccb6 | Stavros Sachtouris | |
1815 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1816 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1817 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1818 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1819 | b4cf92b8 | Stavros Sachtouris | def _run(self, metakey, metaval): |
1820 | b4cf92b8 | Stavros Sachtouris | if not self.container: |
1821 | 915b99b5 | Stavros Sachtouris | r = self.client.set_account_meta({metakey: metaval})
|
1822 | b4cf92b8 | Stavros Sachtouris | elif not self.path: |
1823 | 915b99b5 | Stavros Sachtouris | r = self.client.set_container_meta({metakey: metaval})
|
1824 | b4cf92b8 | Stavros Sachtouris | else:
|
1825 | 915b99b5 | Stavros Sachtouris | r = self.client.set_object_meta(self.path, {metakey: metaval}) |
1826 | 915b99b5 | Stavros Sachtouris | self._optional_output(r)
|
1827 | b4cf92b8 | Stavros Sachtouris | |
1828 | b4cf92b8 | Stavros Sachtouris | def main(self, metakey, metaval, container____path__=None): |
1829 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
1830 | b4cf92b8 | Stavros Sachtouris | self._run(metakey=metakey, metaval=metaval)
|
1831 | 7493ccb6 | Stavros Sachtouris | |
1832 | 234954d1 | Stavros Sachtouris | |
1833 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1834 | 915b99b5 | Stavros Sachtouris | class file_metadata_delete(_file_container_command, _optional_output_cmd): |
1835 | 72952f4f | Stavros Sachtouris | """Delete metadata with given key from account, container or object
|
1836 | 5655d560 | Stavros Sachtouris | - to get metadata of current account: /file metadata get
|
1837 | 5655d560 | Stavros Sachtouris | - to get metadata of a container: /file metadata get <container>
|
1838 | 5655d560 | Stavros Sachtouris | - to get metadata of an object: /file metadata get <container>:<path>
|
1839 | 72952f4f | Stavros Sachtouris | """
|
1840 | 7493ccb6 | Stavros Sachtouris | |
1841 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1842 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1843 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1844 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
1845 | b4cf92b8 | Stavros Sachtouris | def _run(self, metakey): |
1846 | b4cf92b8 | Stavros Sachtouris | if self.container is None: |
1847 | 915b99b5 | Stavros Sachtouris | r = self.client.del_account_meta(metakey)
|
1848 | b4cf92b8 | Stavros Sachtouris | elif self.path is None: |
1849 | 915b99b5 | Stavros Sachtouris | r = self.client.del_container_meta(metakey)
|
1850 | b4cf92b8 | Stavros Sachtouris | else:
|
1851 | 915b99b5 | Stavros Sachtouris | r = self.client.del_object_meta(self.path, metakey) |
1852 | 915b99b5 | Stavros Sachtouris | self._optional_output(r)
|
1853 | b4cf92b8 | Stavros Sachtouris | |
1854 | 7493ccb6 | Stavros Sachtouris | def main(self, metakey, container____path__=None): |
1855 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run(container____path__) |
1856 | b4cf92b8 | Stavros Sachtouris | self._run(metakey)
|
1857 | 7493ccb6 | Stavros Sachtouris | |
1858 | 234954d1 | Stavros Sachtouris | |
1859 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1860 | 545c6c29 | Stavros Sachtouris | class file_quota(_file_account_command, _optional_json): |
1861 | 3ed6dbde | Stavros Sachtouris | """Get account quota"""
|
1862 | 001200c3 | Stavros Sachtouris | |
1863 | 001200c3 | Stavros Sachtouris | arguments = dict(
|
1864 | 001200c3 | Stavros Sachtouris | in_bytes=FlagArgument('Show result in bytes', ('-b', '--bytes')) |
1865 | de73876b | Stavros Sachtouris | ) |
1866 | 7493ccb6 | Stavros Sachtouris | |
1867 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1868 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1869 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1870 | 545c6c29 | Stavros Sachtouris | |
1871 | 7f869771 | Stavros Sachtouris | def pretty_print(output, **kwargs): |
1872 | 545c6c29 | Stavros Sachtouris | if not self['in_bytes']: |
1873 | 545c6c29 | Stavros Sachtouris | for k in output: |
1874 | 545c6c29 | Stavros Sachtouris | output[k] = format_size(output[k]) |
1875 | 7f869771 | Stavros Sachtouris | self.print_dict(output, '-', **kwargs) |
1876 | 545c6c29 | Stavros Sachtouris | |
1877 | 7f869771 | Stavros Sachtouris | self._print(self.client.get_account_quota(), pretty_print) |
1878 | 7493ccb6 | Stavros Sachtouris | |
1879 | 3ed6dbde | Stavros Sachtouris | def main(self, custom_uuid=None): |
1880 | 3ed6dbde | Stavros Sachtouris | super(self.__class__, self)._run(custom_account=custom_uuid) |
1881 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1882 | b4cf92b8 | Stavros Sachtouris | |
1883 | 234954d1 | Stavros Sachtouris | |
1884 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1885 | 326a79b9 | Stavros Sachtouris | class file_containerlimit(_pithos_init): |
1886 | 326a79b9 | Stavros Sachtouris | """Container size limit commands"""
|
1887 | 326a79b9 | Stavros Sachtouris | |
1888 | 326a79b9 | Stavros Sachtouris | |
1889 | 326a79b9 | Stavros Sachtouris | @command(pithos_cmds)
|
1890 | 545c6c29 | Stavros Sachtouris | class file_containerlimit_get(_file_container_command, _optional_json): |
1891 | 3ed6dbde | Stavros Sachtouris | """Get container size limit"""
|
1892 | 3ed6dbde | Stavros Sachtouris | |
1893 | 3ed6dbde | Stavros Sachtouris | arguments = dict(
|
1894 | 3ed6dbde | Stavros Sachtouris | in_bytes=FlagArgument('Show result in bytes', ('-b', '--bytes')) |
1895 | 3ed6dbde | Stavros Sachtouris | ) |
1896 | 3ed6dbde | Stavros Sachtouris | |
1897 | 3ed6dbde | Stavros Sachtouris | @errors.generic.all
|
1898 | 3ed6dbde | Stavros Sachtouris | @errors.pithos.container
|
1899 | 3ed6dbde | Stavros Sachtouris | def _run(self): |
1900 | 545c6c29 | Stavros Sachtouris | |
1901 | 545c6c29 | Stavros Sachtouris | def pretty_print(output): |
1902 | 545c6c29 | Stavros Sachtouris | if not self['in_bytes']: |
1903 | 545c6c29 | Stavros Sachtouris | for k, v in output.items(): |
1904 | 545c6c29 | Stavros Sachtouris | output[k] = 'unlimited' if '0' == v else format_size(v) |
1905 | 76f58e2e | Stavros Sachtouris | self.print_dict(output, '-') |
1906 | 545c6c29 | Stavros Sachtouris | |
1907 | 545c6c29 | Stavros Sachtouris | self._print(
|
1908 | 545c6c29 | Stavros Sachtouris | self.client.get_container_limit(self.container), pretty_print) |
1909 | 3ed6dbde | Stavros Sachtouris | |
1910 | 3ed6dbde | Stavros Sachtouris | def main(self, container=None): |
1911 | 3ed6dbde | Stavros Sachtouris | super(self.__class__, self)._run() |
1912 | 3ed6dbde | Stavros Sachtouris | self.container = container
|
1913 | 3ed6dbde | Stavros Sachtouris | self._run()
|
1914 | 3ed6dbde | Stavros Sachtouris | |
1915 | 3ed6dbde | Stavros Sachtouris | |
1916 | 3ed6dbde | Stavros Sachtouris | @command(pithos_cmds)
|
1917 | 545c6c29 | Stavros Sachtouris | class file_containerlimit_set(_file_account_command, _optional_output_cmd): |
1918 | 326a79b9 | Stavros Sachtouris | """Set new storage limit for a container
|
1919 | 326a79b9 | Stavros Sachtouris | By default, the limit is set in bytes
|
1920 | 001200c3 | Stavros Sachtouris | Users may specify a different unit, e.g:
|
1921 | 326a79b9 | Stavros Sachtouris | /file containerlimit set 2.3GB mycontainer
|
1922 | 3ed6dbde | Stavros Sachtouris | Valid units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
|
1923 | 9f783a51 | Stavros Sachtouris | To set container limit to "unlimited", use 0
|
1924 | 001200c3 | Stavros Sachtouris | """
|
1925 | 001200c3 | Stavros Sachtouris | |
1926 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1927 | 326a79b9 | Stavros Sachtouris | def _calculate_limit(self, user_input): |
1928 | 326a79b9 | Stavros Sachtouris | limit = 0
|
1929 | 001200c3 | Stavros Sachtouris | try:
|
1930 | 326a79b9 | Stavros Sachtouris | limit = int(user_input)
|
1931 | 001200c3 | Stavros Sachtouris | except ValueError: |
1932 | 001200c3 | Stavros Sachtouris | index = 0
|
1933 | 001200c3 | Stavros Sachtouris | digits = [str(num) for num in range(0, 10)] + ['.'] |
1934 | 001200c3 | Stavros Sachtouris | while user_input[index] in digits: |
1935 | 001200c3 | Stavros Sachtouris | index += 1
|
1936 | 326a79b9 | Stavros Sachtouris | limit = user_input[:index] |
1937 | 001200c3 | Stavros Sachtouris | format = user_input[index:] |
1938 | 001200c3 | Stavros Sachtouris | try:
|
1939 | 326a79b9 | Stavros Sachtouris | return to_bytes(limit, format)
|
1940 | 001200c3 | Stavros Sachtouris | except Exception as qe: |
1941 | de73876b | Stavros Sachtouris | msg = 'Failed to convert %s to bytes' % user_input,
|
1942 | de73876b | Stavros Sachtouris | raiseCLIError(qe, msg, details=[ |
1943 | 326a79b9 | Stavros Sachtouris | 'Syntax: containerlimit set <limit>[format] [container]',
|
1944 | 16d7b9ff | Stavros Sachtouris | 'e.g.,: containerlimit set 2.3GB mycontainer',
|
1945 | 326a79b9 | Stavros Sachtouris | 'Valid formats:',
|
1946 | de73876b | Stavros Sachtouris | '(*1024): B, KiB, MiB, GiB, TiB',
|
1947 | de73876b | Stavros Sachtouris | '(*1000): B, KB, MB, GB, TB'])
|
1948 | 326a79b9 | Stavros Sachtouris | return limit
|
1949 | 7493ccb6 | Stavros Sachtouris | |
1950 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1951 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1952 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1953 | 326a79b9 | Stavros Sachtouris | def _run(self, limit): |
1954 | b4cf92b8 | Stavros Sachtouris | if self.container: |
1955 | b4cf92b8 | Stavros Sachtouris | self.client.container = self.container |
1956 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.set_container_limit(limit)) |
1957 | b4cf92b8 | Stavros Sachtouris | |
1958 | 326a79b9 | Stavros Sachtouris | def main(self, limit, container=None): |
1959 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
1960 | 326a79b9 | Stavros Sachtouris | limit = self._calculate_limit(limit)
|
1961 | b4cf92b8 | Stavros Sachtouris | self.container = container
|
1962 | 326a79b9 | Stavros Sachtouris | self._run(limit)
|
1963 | 7493ccb6 | Stavros Sachtouris | |
1964 | 234954d1 | Stavros Sachtouris | |
1965 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1966 | 915b99b5 | Stavros Sachtouris | class file_versioning(_pithos_init): |
1967 | 915b99b5 | Stavros Sachtouris | """Manage the versioning scheme of current pithos user account"""
|
1968 | 915b99b5 | Stavros Sachtouris | |
1969 | 915b99b5 | Stavros Sachtouris | |
1970 | 915b99b5 | Stavros Sachtouris | @command(pithos_cmds)
|
1971 | 545c6c29 | Stavros Sachtouris | class file_versioning_get(_file_account_command, _optional_json): |
1972 | 776eee69 | Stavros Sachtouris | """Get versioning for account or container"""
|
1973 | 7493ccb6 | Stavros Sachtouris | |
1974 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1975 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
1976 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
1977 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
1978 | 545c6c29 | Stavros Sachtouris | self._print(
|
1979 | 76f58e2e | Stavros Sachtouris | self.client.get_container_versioning(self.container), |
1980 | 76f58e2e | Stavros Sachtouris | self.print_dict)
|
1981 | b4cf92b8 | Stavros Sachtouris | |
1982 | df0045d8 | Stavros Sachtouris | def main(self, container): |
1983 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
1984 | b4cf92b8 | Stavros Sachtouris | self.container = container
|
1985 | b4cf92b8 | Stavros Sachtouris | self._run()
|
1986 | 7493ccb6 | Stavros Sachtouris | |
1987 | 234954d1 | Stavros Sachtouris | |
1988 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
1989 | 915b99b5 | Stavros Sachtouris | class file_versioning_set(_file_account_command, _optional_output_cmd): |
1990 | 776eee69 | Stavros Sachtouris | """Set versioning mode (auto, none) for account or container"""
|
1991 | 7493ccb6 | Stavros Sachtouris | |
1992 | b4cf92b8 | Stavros Sachtouris | def _check_versioning(self, versioning): |
1993 | b4cf92b8 | Stavros Sachtouris | if versioning and versioning.lower() in ('auto', 'none'): |
1994 | b4cf92b8 | Stavros Sachtouris | return versioning.lower()
|
1995 | b4cf92b8 | Stavros Sachtouris | raiseCLIError('Invalid versioning %s' % versioning, details=[
|
1996 | b4cf92b8 | Stavros Sachtouris | 'Versioning can be auto or none'])
|
1997 | b4cf92b8 | Stavros Sachtouris | |
1998 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
1999 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
2000 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
2001 | b4cf92b8 | Stavros Sachtouris | def _run(self, versioning): |
2002 | df0045d8 | Stavros Sachtouris | self.client.container = self.container |
2003 | df0045d8 | Stavros Sachtouris | r = self.client.set_container_versioning(versioning)
|
2004 | 915b99b5 | Stavros Sachtouris | self._optional_output(r)
|
2005 | b4cf92b8 | Stavros Sachtouris | |
2006 | df0045d8 | Stavros Sachtouris | def main(self, versioning, container): |
2007 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
2008 | b4cf92b8 | Stavros Sachtouris | self._run(self._check_versioning(versioning)) |
2009 | 7493ccb6 | Stavros Sachtouris | |
2010 | 234954d1 | Stavros Sachtouris | |
2011 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
2012 | 915b99b5 | Stavros Sachtouris | class file_group(_pithos_init): |
2013 | 915b99b5 | Stavros Sachtouris | """Manage access groups and group members"""
|
2014 | 915b99b5 | Stavros Sachtouris | |
2015 | 915b99b5 | Stavros Sachtouris | |
2016 | 915b99b5 | Stavros Sachtouris | @command(pithos_cmds)
|
2017 | 545c6c29 | Stavros Sachtouris | class file_group_list(_file_account_command, _optional_json): |
2018 | 545c6c29 | Stavros Sachtouris | """list all groups and group members"""
|
2019 | 7493ccb6 | Stavros Sachtouris | |
2020 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
2021 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
2022 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
2023 | 76f58e2e | Stavros Sachtouris | self._print(
|
2024 | 76f58e2e | Stavros Sachtouris | self.client.get_account_group(), self.print_dict, delim='-') |
2025 | b4cf92b8 | Stavros Sachtouris | |
2026 | 7493ccb6 | Stavros Sachtouris | def main(self): |
2027 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
2028 | b4cf92b8 | Stavros Sachtouris | self._run()
|
2029 | 7493ccb6 | Stavros Sachtouris | |
2030 | 234954d1 | Stavros Sachtouris | |
2031 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
2032 | 915b99b5 | Stavros Sachtouris | class file_group_set(_file_account_command, _optional_output_cmd): |
2033 | 4fcc38a2 | Stavros Sachtouris | """Set a user group"""
|
2034 | 7493ccb6 | Stavros Sachtouris | |
2035 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
2036 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
2037 | b4cf92b8 | Stavros Sachtouris | def _run(self, groupname, *users): |
2038 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.set_account_group(groupname, users)) |
2039 | b4cf92b8 | Stavros Sachtouris | |
2040 | 7493ccb6 | Stavros Sachtouris | def main(self, groupname, *users): |
2041 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
2042 | b4cf92b8 | Stavros Sachtouris | if users:
|
2043 | b4cf92b8 | Stavros Sachtouris | self._run(groupname, *users)
|
2044 | b4cf92b8 | Stavros Sachtouris | else:
|
2045 | b4cf92b8 | Stavros Sachtouris | raiseCLIError('No users to add in group %s' % groupname)
|
2046 | 7493ccb6 | Stavros Sachtouris | |
2047 | 234954d1 | Stavros Sachtouris | |
2048 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
2049 | 915b99b5 | Stavros Sachtouris | class file_group_delete(_file_account_command, _optional_output_cmd): |
2050 | 4fcc38a2 | Stavros Sachtouris | """Delete a user group"""
|
2051 | 7493ccb6 | Stavros Sachtouris | |
2052 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
2053 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
2054 | b4cf92b8 | Stavros Sachtouris | def _run(self, groupname): |
2055 | 915b99b5 | Stavros Sachtouris | self._optional_output(self.client.del_account_group(groupname)) |
2056 | b4cf92b8 | Stavros Sachtouris | |
2057 | 7493ccb6 | Stavros Sachtouris | def main(self, groupname): |
2058 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
2059 | b4cf92b8 | Stavros Sachtouris | self._run(groupname)
|
2060 | a23f6ffe | Stavros Sachtouris | |
2061 | 234954d1 | Stavros Sachtouris | |
2062 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
2063 | 545c6c29 | Stavros Sachtouris | class file_sharers(_file_account_command, _optional_json): |
2064 | 4fcc38a2 | Stavros Sachtouris | """List the accounts that share objects with current user"""
|
2065 | a23f6ffe | Stavros Sachtouris | |
2066 | 2fe2672e | Stavros Sachtouris | arguments = dict(
|
2067 | f40f0cb7 | Stavros Sachtouris | detail=FlagArgument('show detailed output', ('-l', '--details')), |
2068 | 2fe2672e | Stavros Sachtouris | marker=ValueArgument('show output greater then marker', '--marker') |
2069 | 2fe2672e | Stavros Sachtouris | ) |
2070 | a23f6ffe | Stavros Sachtouris | |
2071 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
2072 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
2073 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
2074 | b4cf92b8 | Stavros Sachtouris | accounts = self.client.get_sharing_accounts(marker=self['marker']) |
2075 | f76c6bbc | Stavros Sachtouris | if not (self['json_output'] or self['output_format']): |
2076 | cf115aed | Stavros Sachtouris | usernames = self._uuids2usernames(
|
2077 | cf115aed | Stavros Sachtouris | [acc['name'] for acc in accounts]) |
2078 | cf115aed | Stavros Sachtouris | for item in accounts: |
2079 | cf115aed | Stavros Sachtouris | uuid = item['name']
|
2080 | cf115aed | Stavros Sachtouris | item['id'], item['name'] = uuid, usernames[uuid] |
2081 | cf115aed | Stavros Sachtouris | if not self['detail']: |
2082 | cf115aed | Stavros Sachtouris | item.pop('last_modified')
|
2083 | cf115aed | Stavros Sachtouris | self._print(accounts)
|
2084 | a23f6ffe | Stavros Sachtouris | |
2085 | b4cf92b8 | Stavros Sachtouris | def main(self): |
2086 | b4cf92b8 | Stavros Sachtouris | super(self.__class__, self)._run() |
2087 | b4cf92b8 | Stavros Sachtouris | self._run()
|
2088 | 38dc5d2f | Stavros Sachtouris | |
2089 | 234954d1 | Stavros Sachtouris | |
2090 | d486baec | Stavros Sachtouris | @command(pithos_cmds)
|
2091 | 545c6c29 | Stavros Sachtouris | class file_versions(_file_container_command, _optional_json): |
2092 | 4fcc38a2 | Stavros Sachtouris | """Get the list of object versions
|
2093 | 4fcc38a2 | Stavros Sachtouris | Deleted objects may still have versions that can be used to restore it and
|
2094 | 4fcc38a2 | Stavros Sachtouris | get information about its previous state.
|
2095 | 4fcc38a2 | Stavros Sachtouris | The version number can be used in a number of other commands, like info,
|
2096 | 16d7b9ff | Stavros Sachtouris | copy, move, meta. See these commands for more information, e.g.,
|
2097 | 3ae60112 | Stavros Sachtouris | /file info -h
|
2098 | 4fcc38a2 | Stavros Sachtouris | """
|
2099 | 38dc5d2f | Stavros Sachtouris | |
2100 | 76f58e2e | Stavros Sachtouris | def version_print(self, versions, out): |
2101 | 76f58e2e | Stavros Sachtouris | self.print_items(
|
2102 | 76f58e2e | Stavros Sachtouris | [dict(id=vitem[0], created=strftime( |
2103 | 76f58e2e | Stavros Sachtouris | '%d-%m-%Y %H:%M:%S',
|
2104 | 76f58e2e | Stavros Sachtouris | localtime(float(vitem[1])))) for vitem in versions], |
2105 | 76f58e2e | Stavros Sachtouris | out=out) |
2106 | 76f58e2e | Stavros Sachtouris | |
2107 | b4cf92b8 | Stavros Sachtouris | @errors.generic.all
|
2108 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.connection
|
2109 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.container
|
2110 | b4cf92b8 | Stavros Sachtouris | @errors.pithos.object_path
|
2111 | b4cf92b8 | Stavros Sachtouris | def _run(self): |
2112 | 545c6c29 | Stavros Sachtouris | self._print(
|
2113 | 76f58e2e | Stavros Sachtouris | self.client.get_object_versionlist(self.path), self.version_print) |
2114 | b4cf92b8 | Stavros Sachtouris | |
2115 | 38dc5d2f | Stavros Sachtouris | def main(self, container___path): |
2116 | 3ae60112 | Stavros Sachtouris | super(file_versions, self)._run( |
2117 | ff1c0296 | Stavros Sachtouris | container___path, path_is_optional=False)
|
2118 | b4cf92b8 | Stavros Sachtouris | self._run() |