root / kamaki / cli / commands / pithos_cli.py @ bc223d91
History | View | Annotate | Download (46.1 kB)
1 |
# Copyright 2011-2012 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.command
|
33 |
|
34 |
from kamaki.cli import command |
35 |
from kamaki.cli.command_tree import CommandTree |
36 |
from kamaki.cli.errors import CLIError, raiseCLIError |
37 |
from kamaki.cli.utils import format_size, print_dict, pretty_keys |
38 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
39 |
from kamaki.cli.argument import KeyValueArgument |
40 |
from kamaki.cli.argument import ProgressBarArgument |
41 |
from kamaki.cli.commands import _command_init |
42 |
from kamaki.clients.pithos import PithosClient, ClientError |
43 |
from kamaki.cli.utils import bold |
44 |
from sys import stdout |
45 |
from time import localtime, strftime |
46 |
from datetime import datetime as dtm |
47 |
|
48 |
|
49 |
pithos_cmds = CommandTree('store', 'Pithos+ storage commands') |
50 |
_commands = [pithos_cmds] |
51 |
|
52 |
|
53 |
# Argument functionality
|
54 |
|
55 |
|
56 |
class DelimiterArgument(ValueArgument): |
57 |
"""
|
58 |
:value type: string
|
59 |
:value returns: given string or /
|
60 |
"""
|
61 |
|
62 |
def __init__(self, caller_obj, help='', parsed_name=None, default=None): |
63 |
super(DelimiterArgument, self).__init__(help, parsed_name, default) |
64 |
self.caller_obj = caller_obj
|
65 |
|
66 |
@property
|
67 |
def value(self): |
68 |
if self.caller_obj.get_argument('recursive'): |
69 |
return '/' |
70 |
return getattr(self, '_value', self.default) |
71 |
|
72 |
@value.setter
|
73 |
def value(self, newvalue): |
74 |
self._value = newvalue
|
75 |
|
76 |
|
77 |
class SharingArgument(ValueArgument): |
78 |
"""Set sharing (read and/or write) groups
|
79 |
|
80 |
:value type: "read=term1,term2,... write=term1,term2,..."
|
81 |
|
82 |
:value returns: {'read':['term1', 'term2', ...],
|
83 |
'write':['term1', 'term2', ...]}
|
84 |
"""
|
85 |
|
86 |
@property
|
87 |
def value(self): |
88 |
return getattr(self, '_value', self.default) |
89 |
|
90 |
@value.setter
|
91 |
def value(self, newvalue): |
92 |
perms = {} |
93 |
try:
|
94 |
permlist = newvalue.split(' ')
|
95 |
except AttributeError: |
96 |
return
|
97 |
for p in permlist: |
98 |
try:
|
99 |
(key, val) = p.split('=')
|
100 |
except ValueError: |
101 |
raise CLIError(message='Error in --sharing', |
102 |
details='Incorrect format',
|
103 |
importance=1)
|
104 |
if key.lower() not in ('read', 'write'): |
105 |
raise CLIError(message='Error in --sharing', |
106 |
details='Invalid permition key %s' % key,
|
107 |
importance=1)
|
108 |
val_list = val.split(',')
|
109 |
if not key in perms: |
110 |
perms[key] = [] |
111 |
for item in val_list: |
112 |
if item not in perms[key]: |
113 |
perms[key].append(item) |
114 |
self._value = perms
|
115 |
|
116 |
|
117 |
class RangeArgument(ValueArgument): |
118 |
"""
|
119 |
:value type: string of the form <start>-<end>
|
120 |
where <start> and <end> are integers
|
121 |
|
122 |
:value returns: the input string, after type checking <start> and <end>
|
123 |
"""
|
124 |
|
125 |
@property
|
126 |
def value(self): |
127 |
return getattr(self, '_value', self.default) |
128 |
|
129 |
@value.setter
|
130 |
def value(self, newvalue): |
131 |
if newvalue is None: |
132 |
self._value = self.default |
133 |
return
|
134 |
(start, end) = newvalue.split('-')
|
135 |
(start, end) = (int(start), int(end)) |
136 |
self._value = '%s-%s' % (start, end) |
137 |
|
138 |
|
139 |
class DateArgument(ValueArgument): |
140 |
"""
|
141 |
:value type: a string formated in an acceptable date format
|
142 |
|
143 |
:value returns: same date in first of DATE_FORMATS
|
144 |
"""
|
145 |
|
146 |
DATE_FORMATS = ["%a %b %d %H:%M:%S %Y",
|
147 |
"%A, %d-%b-%y %H:%M:%S GMT",
|
148 |
"%a, %d %b %Y %H:%M:%S GMT"]
|
149 |
|
150 |
INPUT_FORMATS = DATE_FORMATS + ["%d-%m-%Y", "%H:%M:%S %d-%m-%Y"] |
151 |
|
152 |
@property
|
153 |
def value(self): |
154 |
return getattr(self, '_value', self.default) |
155 |
|
156 |
@value.setter
|
157 |
def value(self, newvalue): |
158 |
if newvalue is None: |
159 |
return
|
160 |
self._value = self.format_date(newvalue) |
161 |
|
162 |
def format_date(self, datestr): |
163 |
for format in self.INPUT_FORMATS: |
164 |
try:
|
165 |
t = dtm.strptime(datestr, format) |
166 |
except ValueError: |
167 |
continue
|
168 |
self._value = t.strftime(self.DATE_FORMATS[0]) |
169 |
return
|
170 |
raise CLIError('Date Argument Error', |
171 |
details='%s not a valid date. correct formats:\n\t%s'\
|
172 |
% (datestr, self.INPUT_FORMATS))
|
173 |
|
174 |
|
175 |
# Command specs
|
176 |
|
177 |
|
178 |
class _pithos_init(_command_init): |
179 |
"""Initialize a pithos+ kamaki client"""
|
180 |
|
181 |
def main(self): |
182 |
self.token = self.config.get('store', 'token')\ |
183 |
or self.config.get('global', 'token') |
184 |
self.base_url = self.config.get('store', 'url')\ |
185 |
or self.config.get('global', 'url') |
186 |
self.account = self.config.get('store', 'account')\ |
187 |
or self.config.get('global', 'account') |
188 |
self.container = self.config.get('store', 'container')\ |
189 |
or self.config.get('global', 'container') |
190 |
self.client = PithosClient(base_url=self.base_url, |
191 |
token=self.token,
|
192 |
account=self.account,
|
193 |
container=self.container)
|
194 |
|
195 |
|
196 |
class _store_account_command(_pithos_init): |
197 |
"""Base class for account level storage commands"""
|
198 |
|
199 |
def __init__(self, arguments={}): |
200 |
super(_store_account_command, self).__init__(arguments) |
201 |
self.arguments['account'] =\ |
202 |
ValueArgument('Specify the account', '--account') |
203 |
|
204 |
def generator(self, message): |
205 |
return None |
206 |
|
207 |
def main(self): |
208 |
super(_store_account_command, self).main() |
209 |
if self.arguments['account'].value is not None: |
210 |
self.client.account = self.arguments['account'].value |
211 |
|
212 |
|
213 |
class _store_container_command(_store_account_command): |
214 |
"""Base class for container level storage commands"""
|
215 |
|
216 |
def __init__(self, arguments={}): |
217 |
super(_store_container_command, self).__init__(arguments) |
218 |
self.arguments['container'] =\ |
219 |
ValueArgument('Specify the container name', '--container') |
220 |
self.container = None |
221 |
self.path = None |
222 |
|
223 |
def extract_container_and_path(self, |
224 |
container_with_path, |
225 |
path_is_optional=True):
|
226 |
assert isinstance(container_with_path, str) |
227 |
if ':' not in container_with_path: |
228 |
if self.get_argument('container') is not None: |
229 |
self.container = self.get_argument('container') |
230 |
else:
|
231 |
self.container = self.client.container |
232 |
if self.container is None: |
233 |
self.container = container_with_path
|
234 |
else:
|
235 |
self.path = container_with_path
|
236 |
if not path_is_optional and self.path is None: |
237 |
raise CLIError('Object path is missing\n', importance=1) |
238 |
return
|
239 |
cnp = container_with_path.split(':')
|
240 |
self.container = cnp[0] |
241 |
try:
|
242 |
self.path = cnp[1] |
243 |
except IndexError: |
244 |
if path_is_optional:
|
245 |
self.path = None |
246 |
else:
|
247 |
raise CLIError('Object path is missing\n', importance=1) |
248 |
|
249 |
def main(self, container_with_path=None, path_is_optional=True): |
250 |
super(_store_container_command, self).main() |
251 |
if container_with_path is not None: |
252 |
self.extract_container_and_path(container_with_path,
|
253 |
path_is_optional) |
254 |
self.client.container = self.container |
255 |
elif self.get_argument('container') is not None: |
256 |
self.client.container = self.get_argument('container') |
257 |
self.container = self.client.container |
258 |
|
259 |
|
260 |
@command(pithos_cmds)
|
261 |
class store_list(_store_container_command): |
262 |
"""List containers, object trees or objects in a directory
|
263 |
"""
|
264 |
|
265 |
def __init__(self, arguments={}): |
266 |
super(store_list, self).__init__(arguments) |
267 |
self.arguments['detail'] = FlagArgument('show detailed output', '-l') |
268 |
self.arguments['show_size'] =\ |
269 |
ValueArgument('print output in chunks of size N', '-N') |
270 |
self.arguments['limit'] = IntArgument('show limited output', '-n') |
271 |
self.arguments['marker'] =\ |
272 |
ValueArgument('show output greater that marker', '--marker') |
273 |
self.arguments['prefix'] =\ |
274 |
ValueArgument('show output staritng with prefix', '--prefix') |
275 |
self.arguments['delimiter'] =\ |
276 |
ValueArgument('show output up to delimiter', '--delimiter') |
277 |
self.arguments['path'] =\ |
278 |
ValueArgument('show output starting with prefix up to /', '--path') |
279 |
self.arguments['meta'] =\ |
280 |
ValueArgument('show output haviung the specified meta keys',
|
281 |
'--meta', default=[])
|
282 |
self.arguments['if_modified_since'] =\ |
283 |
ValueArgument('show output modified since then',
|
284 |
'--if-modified-since')
|
285 |
self.arguments['if_unmodified_since'] =\ |
286 |
ValueArgument('show output not modified since then',
|
287 |
'--if-unmodified-since')
|
288 |
self.arguments['until'] =\ |
289 |
DateArgument('show metadata until then', '--until') |
290 |
self.arguments['format'] =\ |
291 |
ValueArgument('format to parse until data (default: d/m/Y H:M:S',
|
292 |
'--format')
|
293 |
self.arguments['shared'] = FlagArgument('show only shared', '--shared') |
294 |
self.arguments['public'] = FlagArgument('show only public', '--public') |
295 |
|
296 |
def print_objects(self, object_list): |
297 |
import sys |
298 |
try:
|
299 |
limit = self.get_argument('show_size') |
300 |
limit = int(limit)
|
301 |
except (AttributeError, TypeError): |
302 |
limit = len(object_list) + 1 |
303 |
#index = 0
|
304 |
for index, obj in enumerate(object_list): |
305 |
if 'content_type' not in obj: |
306 |
continue
|
307 |
pretty_obj = obj.copy() |
308 |
index += 1
|
309 |
empty_space = ' ' * (len(str(len(object_list))) - len(str(index))) |
310 |
if obj['content_type'] == 'application/directory': |
311 |
isDir = True
|
312 |
size = 'D'
|
313 |
else:
|
314 |
isDir = False
|
315 |
size = format_size(obj['bytes'])
|
316 |
pretty_obj['bytes'] = '%s (%s)' % (obj['bytes'], size) |
317 |
oname = bold(obj['name'])
|
318 |
if self.get_argument('detail'): |
319 |
print('%s%s. %s' % (empty_space, index, oname))
|
320 |
print_dict(pretty_keys(pretty_obj), exclude=('name'))
|
321 |
print
|
322 |
else:
|
323 |
oname = '%s%s. %6s %s' % (empty_space, index, size, oname)
|
324 |
oname += '/' if isDir else '' |
325 |
print(oname) |
326 |
if limit <= index < len(object_list) and index % limit == 0: |
327 |
print('(press "enter" to continue)')
|
328 |
sys.stdin.read(1)
|
329 |
|
330 |
def print_containers(self, container_list): |
331 |
import sys |
332 |
try:
|
333 |
limit = self.get_argument('show_size') |
334 |
limit = int(limit)
|
335 |
except (AttributeError, TypeError): |
336 |
limit = len(container_list) + 1 |
337 |
for index, container in enumerate(container_list): |
338 |
if 'bytes' in container: |
339 |
size = format_size(container['bytes'])
|
340 |
cname = '%s. %s' % (index + 1, bold(container['name'])) |
341 |
if self.get_argument('detail'): |
342 |
print(cname) |
343 |
pretty_c = container.copy() |
344 |
if 'bytes' in container: |
345 |
pretty_c['bytes'] = '%s (%s)' % (container['bytes'], size) |
346 |
print_dict(pretty_keys(pretty_c), exclude=('name'))
|
347 |
print
|
348 |
else:
|
349 |
if 'count' in container and 'bytes' in container: |
350 |
print('%s (%s, %s objects)'\
|
351 |
% (cname, size, container['count']))
|
352 |
else:
|
353 |
print(cname) |
354 |
if limit <= index < len(container_list) and index % limit == 0: |
355 |
print('(press "enter" to continue)')
|
356 |
sys.stdin.read(1)
|
357 |
|
358 |
def main(self, container____path__=None): |
359 |
super(self.__class__, self).main(container____path__) |
360 |
try:
|
361 |
if self.container is None: |
362 |
r = self.client.account_get(limit=self.get_argument('limit'), |
363 |
marker=self.get_argument('marker'), |
364 |
if_modified_since=self.get_argument('if_modified_since'), |
365 |
if_unmodified_since=self.get_argument(\
|
366 |
'if_unmodified_since'),
|
367 |
until=self.get_argument('until'), |
368 |
show_only_shared=self.get_argument('shared')) |
369 |
self.print_containers(r.json)
|
370 |
else:
|
371 |
r = self.client.container_get(limit=self.get_argument('limit'), |
372 |
marker=self.get_argument('marker'), |
373 |
prefix=self.get_argument('prefix'), |
374 |
delimiter=self.get_argument('delimiter'), |
375 |
path=self.get_argument('path'), |
376 |
if_modified_since=self.get_argument('if_modified_since'), |
377 |
if_unmodified_since=self.get_argument(\
|
378 |
'if_unmodified_since'),
|
379 |
until=self.get_argument('until'), |
380 |
meta=self.get_argument('meta'), |
381 |
show_only_shared=self.get_argument('shared')) |
382 |
self.print_objects(r.json)
|
383 |
except ClientError as err: |
384 |
raiseCLIError(err) |
385 |
|
386 |
|
387 |
@command(pithos_cmds)
|
388 |
class store_mkdir(_store_container_command): |
389 |
"""Create a directory"""
|
390 |
|
391 |
def main(self, container___directory): |
392 |
super(self.__class__, |
393 |
self).main(container___directory, path_is_optional=False) |
394 |
try:
|
395 |
self.client.create_directory(self.path) |
396 |
except ClientError as err: |
397 |
raiseCLIError(err) |
398 |
|
399 |
|
400 |
@command(pithos_cmds)
|
401 |
class store_create(_store_container_command): |
402 |
"""Create a container or a directory object"""
|
403 |
|
404 |
def __init__(self, arguments={}): |
405 |
super(self.__class__, self).__init__(arguments) |
406 |
self.arguments['versioning'] = \ |
407 |
ValueArgument('set container versioning (auto/none)',
|
408 |
'--versioning')
|
409 |
self.arguments['quota'] =\ |
410 |
IntArgument('set default container quota', '--quota') |
411 |
self.arguments['meta'] =\ |
412 |
KeyValueArgument( |
413 |
'set container metadata (can be repeated)', '--meta') |
414 |
# MetaArgument('set container metadata', '--meta')
|
415 |
|
416 |
def main(self, container____directory__): |
417 |
super(self.__class__, self).main(container____directory__) |
418 |
try:
|
419 |
if self.path is None: |
420 |
self.client.container_put(quota=self.get_argument('quota'), |
421 |
versioning=self.get_argument('versioning'), |
422 |
metadata=self.get_argument('meta')) |
423 |
else:
|
424 |
self.client.create_directory(self.path) |
425 |
except ClientError as err: |
426 |
raiseCLIError(err) |
427 |
|
428 |
|
429 |
@command(pithos_cmds)
|
430 |
class store_copy(_store_container_command): |
431 |
"""Copy an object"""
|
432 |
|
433 |
def __init__(self, arguments={}): |
434 |
super(self.__class__, self).__init__(arguments) |
435 |
self.arguments['source_version'] = ValueArgument(\ |
436 |
'copy specific version', '--source-version') |
437 |
self.arguments['public'] = ValueArgument(\ |
438 |
'make object publicly accessible', '--public') |
439 |
self.arguments['content_type'] = ValueArgument(\ |
440 |
'change object\'s content type', '--content-type') |
441 |
self.arguments['delimiter'] = DelimiterArgument(self, |
442 |
parsed_name='--delimiter',
|
443 |
help=u'copy objects prefixed as src_object + delimiter')
|
444 |
self.arguments['recursive'] = FlagArgument( |
445 |
'mass copy with delimiter /', ('-r', '--recursive')) |
446 |
|
447 |
def main(self, source_container___path, destination_container____path__): |
448 |
super(self.__class__, |
449 |
self).main(source_container___path, path_is_optional=False) |
450 |
try:
|
451 |
dst = destination_container____path__.split(':')
|
452 |
dst_cont = dst[0]
|
453 |
dst_path = dst[1] if len(dst) > 1 else False |
454 |
self.client.copy_object(src_container=self.container, |
455 |
src_object=self.path,
|
456 |
dst_container=dst_cont, |
457 |
dst_object=dst_path, |
458 |
source_version=self.get_argument('source_version'), |
459 |
public=self.get_argument('public'), |
460 |
content_type=self.get_argument('content_type'), |
461 |
delimiter=self.get_argument('delimiter')) |
462 |
except ClientError as err: |
463 |
raiseCLIError(err) |
464 |
|
465 |
|
466 |
@command(pithos_cmds)
|
467 |
class store_move(_store_container_command): |
468 |
"""Copy an object"""
|
469 |
|
470 |
def __init__(self, arguments={}): |
471 |
super(self.__class__, self).__init__(arguments) |
472 |
|
473 |
self.arguments['source_version'] = ValueArgument(\ |
474 |
'copy specific version', '--source-version') |
475 |
self.arguments['public'] = FlagArgument(\ |
476 |
'make object publicly accessible', '--public') |
477 |
self.arguments['content_type'] = ValueArgument(\ |
478 |
'change object\'s content type', '--content-type') |
479 |
self.arguments['delimiter'] = DelimiterArgument(self, |
480 |
parsed_name='--delimiter',
|
481 |
help='move objects prefixed as src_object + delimiter')
|
482 |
self.arguments['recursive'] = FlagArgument(\ |
483 |
'copy with delimiter /', ('-r', '--recursive')) |
484 |
|
485 |
def main(self, source_container___path, destination_container____path__): |
486 |
super(self.__class__, |
487 |
self).main(source_container___path, path_is_optional=False) |
488 |
try:
|
489 |
dst = destination_container____path__.split(':')
|
490 |
dst_cont = dst[0]
|
491 |
dst_path = dst[1] if len(dst) > 1 else False |
492 |
self.client.move_object(src_container=self.container, |
493 |
src_object=self.path,
|
494 |
dst_container=dst_cont, |
495 |
dst_object=dst_path, |
496 |
source_version=self.get_argument('source_version'), |
497 |
public=self.get_argument('public'), |
498 |
content_type=self.get_argument('content_type'), |
499 |
delimiter=self.get_argument('delimiter')) |
500 |
except ClientError as err: |
501 |
raiseCLIError(err) |
502 |
|
503 |
|
504 |
@command(pithos_cmds)
|
505 |
class store_append(_store_container_command): |
506 |
"""Append local file to (existing) remote object"""
|
507 |
|
508 |
def __init__(self, arguments={}): |
509 |
super(self.__class__, self).__init__(arguments) |
510 |
self.arguments['progress_bar'] = ProgressBarArgument(\ |
511 |
'do not show progress bar', '--no-progress-bar', False) |
512 |
|
513 |
def main(self, local_path, container___path): |
514 |
super(self.__class__, |
515 |
self).main(container___path, path_is_optional=False) |
516 |
try:
|
517 |
f = open(local_path, 'r') |
518 |
progress_bar = self.arguments['progress_bar'] |
519 |
try:
|
520 |
upload_cb = progress_bar.get_generator('Appending blocks')
|
521 |
except Exception: |
522 |
upload_cb = None
|
523 |
self.client.append_object(object=self.path, |
524 |
source_file=f, |
525 |
upload_cb=upload_cb) |
526 |
except ClientError as err: |
527 |
progress_bar.finish() |
528 |
raiseCLIError(err) |
529 |
finally:
|
530 |
progress_bar.finish() |
531 |
|
532 |
|
533 |
@command(pithos_cmds)
|
534 |
class store_truncate(_store_container_command): |
535 |
"""Truncate remote file up to a size"""
|
536 |
|
537 |
def main(self, container___path, size=0): |
538 |
super(self.__class__, |
539 |
self).main(container___path, path_is_optional=False) |
540 |
try:
|
541 |
self.client.truncate_object(self.path, size) |
542 |
except ClientError as err: |
543 |
raiseCLIError(err) |
544 |
|
545 |
|
546 |
@command(pithos_cmds)
|
547 |
class store_overwrite(_store_container_command): |
548 |
"""Overwrite part (from start to end) of a remote file"""
|
549 |
|
550 |
def __init__(self, arguments={}): |
551 |
super(self.__class__, self).__init__(arguments) |
552 |
self.arguments['progress_bar'] = ProgressBarArgument(\ |
553 |
'do not show progress bar', '--no-progress-bar', False) |
554 |
|
555 |
def main(self, local_path, container___path, start, end): |
556 |
super(self.__class__, |
557 |
self).main(container___path, path_is_optional=False) |
558 |
try:
|
559 |
f = open(local_path, 'r') |
560 |
progress_bar = self.arguments['progress_bar'] |
561 |
try:
|
562 |
upload_cb = progress_bar.get_generator('Overwritting blocks')
|
563 |
except Exception: |
564 |
upload_cb = None
|
565 |
self.client.overwrite_object(object=self.path, |
566 |
start=start, |
567 |
end=end, |
568 |
source_file=f, |
569 |
upload_cb=upload_cb) |
570 |
except ClientError as err: |
571 |
progress_bar.finish() |
572 |
raiseCLIError(err) |
573 |
finally:
|
574 |
progress_bar.finish() |
575 |
|
576 |
|
577 |
@command(pithos_cmds)
|
578 |
class store_manifest(_store_container_command): |
579 |
"""Create a remote file with uploaded parts by manifestation"""
|
580 |
|
581 |
def __init__(self, arguments={}): |
582 |
super(self.__class__, self).__init__(arguments) |
583 |
self.arguments['etag'] = ValueArgument('check written data', '--etag') |
584 |
self.arguments['content_encoding'] = ValueArgument(\ |
585 |
'provide the object MIME content type', '--content-encoding') |
586 |
self.arguments['content_disposition'] = ValueArgument(\ |
587 |
'provide the presentation style of the object',
|
588 |
'--content-disposition')
|
589 |
self.arguments['content_type'] = ValueArgument(\ |
590 |
'create object with specific content type', '--content-type') |
591 |
self.arguments['sharing'] = SharingArgument(parsed_name='--sharing', |
592 |
help='define object sharing policy ' +\
|
593 |
'( "read=user1,grp1,user2,... write=user1,grp2,..." )')
|
594 |
self.arguments['public'] = FlagArgument(\ |
595 |
'make object publicly accessible', '--public') |
596 |
|
597 |
def main(self, container___path): |
598 |
super(self.__class__, |
599 |
self).main(container___path, path_is_optional=False) |
600 |
try:
|
601 |
self.client.create_object_by_manifestation(self.path, |
602 |
content_encoding=self.get_argument('content_encoding'), |
603 |
content_disposition=self.get_argument('content_disposition'), |
604 |
content_type=self.get_argument('content_type'), |
605 |
sharing=self.get_argument('sharing'), |
606 |
public=self.get_argument('public')) |
607 |
except ClientError as err: |
608 |
raiseCLIError(err) |
609 |
|
610 |
|
611 |
@command(pithos_cmds)
|
612 |
class store_upload(_store_container_command): |
613 |
"""Upload a file"""
|
614 |
|
615 |
def __init__(self, arguments={}): |
616 |
super(self.__class__, self).__init__(arguments) |
617 |
self.arguments['use_hashes'] = FlagArgument(\ |
618 |
'provide hashmap file instead of data', '--use-hashes') |
619 |
self.arguments['etag'] = ValueArgument('check written data', '--etag') |
620 |
self.arguments['unchunked'] = FlagArgument(\ |
621 |
'avoid chunked transfer mode', '--unchunked') |
622 |
self.arguments['content_encoding'] = ValueArgument(\ |
623 |
'provide the object MIME content type', '--content-encoding') |
624 |
self.arguments['content_disposition'] = ValueArgument(\ |
625 |
'provide the presentation style of the object',
|
626 |
'--content-disposition')
|
627 |
self.arguments['content_type'] = ValueArgument(\ |
628 |
'create object with specific content type', '--content-type') |
629 |
self.arguments['sharing'] = SharingArgument(parsed_name='--sharing', |
630 |
help='define sharing object policy ' +\
|
631 |
'( "read=user1,grp1,user2,... write=user1,grp2,...')
|
632 |
self.arguments['public'] = FlagArgument(\ |
633 |
'make object publicly accessible', '--public') |
634 |
self.arguments['poolsize'] = IntArgument(\ |
635 |
'set pool size', '--with-pool-size') |
636 |
self.arguments['progress_bar'] = ProgressBarArgument(\ |
637 |
'do not show progress bar', '--no-progress-bar', False) |
638 |
|
639 |
def main(self, local_path, container____path__): |
640 |
super(self.__class__, self).main(container____path__) |
641 |
remote_path = local_path if self.path is None else self.path |
642 |
poolsize = self.get_argument('poolsize') |
643 |
if poolsize is not None: |
644 |
self.client.POOL_SIZE = int(poolsize) |
645 |
params = dict(content_encoding=self.get_argument('content_encoding'), |
646 |
content_type=self.get_argument('content_type'), |
647 |
content_disposition=self.get_argument('content_disposition'), |
648 |
sharing=self.get_argument('sharing'), |
649 |
public=self.get_argument('public')) |
650 |
try:
|
651 |
progress_bar = self.arguments['progress_bar'] |
652 |
hash_bar = progress_bar.clone() |
653 |
with open(local_path) as f: |
654 |
if self.get_argument('unchunked'): |
655 |
self.client.upload_object_unchunked(remote_path, f,
|
656 |
etag=self.get_argument('etag'), |
657 |
withHashFile=self.get_argument('use_hashes'), |
658 |
**params) |
659 |
else:
|
660 |
hash_cb = hash_bar.get_generator(\ |
661 |
'Calculating block hashes')
|
662 |
upload_cb = progress_bar.get_generator('Uploading')
|
663 |
self.client.upload_object(remote_path, f,
|
664 |
hash_cb=hash_cb, |
665 |
upload_cb=upload_cb, |
666 |
**params) |
667 |
progress_bar.finish() |
668 |
hash_bar.finish() |
669 |
except ClientError as err: |
670 |
progress_bar.finish() |
671 |
hash_bar.finish() |
672 |
raiseCLIError(err) |
673 |
except IOError as err: |
674 |
progress_bar.finish() |
675 |
hash_bar.finish() |
676 |
raise CLIError(
|
677 |
message='Failed to read form file %s' % local_path,
|
678 |
importance=2,
|
679 |
details=unicode(err))
|
680 |
print 'Upload completed' |
681 |
|
682 |
|
683 |
@command(pithos_cmds)
|
684 |
class store_cat(_store_container_command): |
685 |
"""Print a file to console"""
|
686 |
|
687 |
def __init__(self, arguments={}): |
688 |
super(self.__class__, self).__init__(arguments) |
689 |
self.arguments['range'] =\ |
690 |
RangeArgument('show range of data', '--range') |
691 |
self.arguments['if_match'] =\ |
692 |
ValueArgument('show output if ETags match', '--if-match') |
693 |
self.arguments['if_none_match'] =\ |
694 |
ValueArgument('show output if ETags match', '--if-none-match') |
695 |
self.arguments['if_modified_since'] =\ |
696 |
DateArgument('show output modified since then',
|
697 |
'--if-modified-since')
|
698 |
self.arguments['if_unmodified_since'] =\ |
699 |
DateArgument('show output unmodified since then',
|
700 |
'--if-unmodified-since')
|
701 |
self.arguments['object_version'] =\ |
702 |
ValueArgument('get the specific version', '--object-version') |
703 |
|
704 |
def main(self, container___path): |
705 |
super(self.__class__, |
706 |
self).main(container___path, path_is_optional=False) |
707 |
try:
|
708 |
self.client.download_object(self.path, stdout, |
709 |
range=self.get_argument('range'), |
710 |
version=self.get_argument('object_version'), |
711 |
if_match=self.get_argument('if_match'), |
712 |
if_none_match=self.get_argument('if_none_match'), |
713 |
if_modified_since=self.get_argument('if_modified_since'), |
714 |
if_unmodified_since=self.get_argument('if_unmodified_since')) |
715 |
except ClientError as err: |
716 |
raiseCLIError(err) |
717 |
|
718 |
|
719 |
@command(pithos_cmds)
|
720 |
class store_download(_store_container_command): |
721 |
"""Download a file"""
|
722 |
|
723 |
def __init__(self, arguments={}): |
724 |
super(self.__class__, self).__init__(arguments) |
725 |
self.arguments['resume'] = FlagArgument(parsed_name='--resume', |
726 |
help='Resume a previous download instead of overwritting it')
|
727 |
self.arguments['range'] = RangeArgument(\ |
728 |
'show range of data', '--range') |
729 |
self.arguments['if_match'] = ValueArgument(\ |
730 |
'show output if ETags match', '--if-match') |
731 |
self.arguments['if_none_match'] = ValueArgument(\ |
732 |
'show output if ETags match', '--if-none-match') |
733 |
self.arguments['if_modified_since'] = DateArgument(\ |
734 |
'show output modified since then', '--if-modified-since') |
735 |
self.arguments['if_unmodified_since'] = DateArgument(\ |
736 |
'show output unmodified since then', '--if-unmodified-since') |
737 |
self.arguments['object_version'] = ValueArgument(\ |
738 |
'get the specific version', '--object-version') |
739 |
self.arguments['poolsize'] = IntArgument(\ |
740 |
'set pool size', '--with-pool-size') |
741 |
self.arguments['progress_bar'] = ProgressBarArgument(\ |
742 |
'do not show progress bar', '--no-progress-bar', False) |
743 |
|
744 |
def main(self, container___path, local_path): |
745 |
super(self.__class__, |
746 |
self).main(container___path, path_is_optional=False) |
747 |
|
748 |
# setup output stream
|
749 |
if local_path is None: |
750 |
out = stdout |
751 |
else:
|
752 |
try:
|
753 |
if self.get_argument('resume'): |
754 |
out = open(local_path, 'rwb+') |
755 |
else:
|
756 |
out = open(local_path, 'wb+') |
757 |
except IOError as err: |
758 |
raise CLIError(message='Cannot write to file %s - %s'\ |
759 |
% (local_path, unicode(err)),
|
760 |
importance=1)
|
761 |
poolsize = self.get_argument('poolsize') |
762 |
if poolsize is not None: |
763 |
self.client.POOL_SIZE = int(poolsize) |
764 |
|
765 |
try:
|
766 |
progress_bar = self.arguments['progress_bar'] |
767 |
download_cb = progress_bar.get_generator('Downloading')
|
768 |
self.client.download_object(self.path, out, |
769 |
download_cb=download_cb, |
770 |
range=self.get_argument('range'), |
771 |
version=self.get_argument('object_version'), |
772 |
if_match=self.get_argument('if_match'), |
773 |
resume=self.get_argument('resume'), |
774 |
if_none_match=self.get_argument('if_none_match'), |
775 |
if_modified_since=self.get_argument('if_modified_since'), |
776 |
if_unmodified_since=self.get_argument('if_unmodified_since')) |
777 |
progress_bar.finish() |
778 |
except ClientError as err: |
779 |
progress_bar.finish() |
780 |
raiseCLIError(err) |
781 |
except KeyboardInterrupt: |
782 |
from threading import enumerate as activethreads |
783 |
stdout.write('\nFinishing active threads ')
|
784 |
for thread in activethreads(): |
785 |
stdout.flush() |
786 |
try:
|
787 |
thread.join() |
788 |
stdout.write('.')
|
789 |
except RuntimeError: |
790 |
continue
|
791 |
progress_bar.finish() |
792 |
print('\ndownload canceled by user')
|
793 |
if local_path is not None: |
794 |
print('to resume, re-run with --resume')
|
795 |
except Exception as e: |
796 |
progress_bar.finish() |
797 |
raise e
|
798 |
print
|
799 |
|
800 |
|
801 |
@command(pithos_cmds)
|
802 |
class store_hashmap(_store_container_command): |
803 |
"""Get the hashmap of an object"""
|
804 |
|
805 |
def __init__(self, arguments={}): |
806 |
super(self.__class__, self).__init__(arguments) |
807 |
self.arguments['if_match'] =\ |
808 |
ValueArgument('show output if ETags match', '--if-match') |
809 |
self.arguments['if_none_match'] =\ |
810 |
ValueArgument('show output if ETags match', '--if-none-match') |
811 |
self.arguments['if_modified_since'] =\ |
812 |
DateArgument('show output modified since then',
|
813 |
'--if-modified-since')
|
814 |
self.arguments['if_unmodified_since'] =\ |
815 |
DateArgument('show output unmodified since then',
|
816 |
'--if-unmodified-since')
|
817 |
self.arguments['object_version'] =\ |
818 |
ValueArgument('get the specific version', '--object-version') |
819 |
|
820 |
def main(self, container___path): |
821 |
super(self.__class__, |
822 |
self).main(container___path, path_is_optional=False) |
823 |
try:
|
824 |
data = self.client.get_object_hashmap(self.path, |
825 |
version=self.arguments('object_version'), |
826 |
if_match=self.arguments('if_match'), |
827 |
if_none_match=self.arguments('if_none_match'), |
828 |
if_modified_since=self.arguments('if_modified_since'), |
829 |
if_unmodified_since=self.arguments('if_unmodified_since')) |
830 |
except ClientError as err: |
831 |
raiseCLIError(err) |
832 |
print_dict(data) |
833 |
|
834 |
|
835 |
@command(pithos_cmds)
|
836 |
class store_delete(_store_container_command): |
837 |
"""Delete a container [or an object]"""
|
838 |
|
839 |
def __init__(self, arguments={}): |
840 |
super(self.__class__, self).__init__(arguments) |
841 |
self.arguments['until'] = DateArgument(\ |
842 |
'remove history until that date', '--until') |
843 |
self.arguments['recursive'] = FlagArgument(\ |
844 |
'empty dir or container and delete (if dir)',
|
845 |
('-r', '--recursive')) |
846 |
self.arguments['delimiter'] = DelimiterArgument(self, |
847 |
parsed_name='--delimiter',
|
848 |
help='delete objects prefixed with <object><delimiter>')
|
849 |
|
850 |
def main(self, container____path__): |
851 |
super(self.__class__, self).main(container____path__) |
852 |
try:
|
853 |
if self.path is None: |
854 |
self.client.del_container(until=self.get_argument('until'), |
855 |
delimiter=self.get_argument('delimiter')) |
856 |
else:
|
857 |
# self.client.delete_object(self.path)
|
858 |
self.client.del_object(self.path, |
859 |
until=self.get_argument('until'), |
860 |
delimiter=self.get_argument('delimiter')) |
861 |
except ClientError as err: |
862 |
raiseCLIError(err) |
863 |
|
864 |
|
865 |
@command(pithos_cmds)
|
866 |
class store_purge(_store_container_command): |
867 |
"""Purge a container"""
|
868 |
|
869 |
def main(self, container): |
870 |
super(self.__class__, self).main(container) |
871 |
try:
|
872 |
self.client.purge_container()
|
873 |
except ClientError as err: |
874 |
raiseCLIError(err) |
875 |
|
876 |
|
877 |
@command(pithos_cmds)
|
878 |
class store_publish(_store_container_command): |
879 |
"""Publish an object"""
|
880 |
|
881 |
def main(self, container___path): |
882 |
super(self.__class__, |
883 |
self).main(container___path, path_is_optional=False) |
884 |
try:
|
885 |
self.client.publish_object(self.path) |
886 |
except ClientError as err: |
887 |
raiseCLIError(err) |
888 |
|
889 |
|
890 |
@command(pithos_cmds)
|
891 |
class store_unpublish(_store_container_command): |
892 |
"""Unpublish an object"""
|
893 |
|
894 |
def main(self, container___path): |
895 |
super(self.__class__, |
896 |
self).main(container___path, path_is_optional=False) |
897 |
try:
|
898 |
self.client.unpublish_object(self.path) |
899 |
except ClientError as err: |
900 |
raiseCLIError(err) |
901 |
|
902 |
|
903 |
@command(pithos_cmds)
|
904 |
class store_permissions(_store_container_command): |
905 |
"""Get object read / write permissions """
|
906 |
|
907 |
def main(self, container___path): |
908 |
super(self.__class__, |
909 |
self).main(container___path, path_is_optional=False) |
910 |
try:
|
911 |
reply = self.client.get_object_sharing(self.path) |
912 |
print_dict(reply) |
913 |
except ClientError as err: |
914 |
raiseCLIError(err) |
915 |
|
916 |
|
917 |
@command(pithos_cmds)
|
918 |
class store_setpermissions(_store_container_command): |
919 |
"""Set sharing permissions """
|
920 |
|
921 |
def format_permition_dict(self, permissions): |
922 |
read = False
|
923 |
write = False
|
924 |
for perms in permissions: |
925 |
splstr = perms.split('=')
|
926 |
if 'read' == splstr[0]: |
927 |
read = [user_or_group.strip() \ |
928 |
for user_or_group in splstr[1].split(',')] |
929 |
elif 'write' == splstr[0]: |
930 |
write = [user_or_group.strip() \ |
931 |
for user_or_group in splstr[1].split(',')] |
932 |
else:
|
933 |
read = False
|
934 |
write = False
|
935 |
if not read and not write: |
936 |
raise CLIError(importance=0, |
937 |
message='Usage:\tread=<groups,users> write=<groups,users>')
|
938 |
return (read, write)
|
939 |
|
940 |
def main(self, container___path, *permissions): |
941 |
super(self.__class__, |
942 |
self).main(container___path, path_is_optional=False) |
943 |
(read, write) = self.format_permition_dict(permissions)
|
944 |
try:
|
945 |
self.client.set_object_sharing(self.path, |
946 |
read_permition=read, write_permition=write) |
947 |
except ClientError as err: |
948 |
raiseCLIError(err) |
949 |
|
950 |
|
951 |
@command(pithos_cmds)
|
952 |
class store_delpermissions(_store_container_command): |
953 |
"""Delete all sharing permissions"""
|
954 |
|
955 |
def main(self, container___path): |
956 |
super(self.__class__, |
957 |
self).main(container___path, path_is_optional=False) |
958 |
try:
|
959 |
self.client.del_object_sharing(self.path) |
960 |
except ClientError as err: |
961 |
raiseCLIError(err) |
962 |
|
963 |
|
964 |
@command(pithos_cmds)
|
965 |
class store_info(_store_container_command): |
966 |
"""Get information for account [, container [or object]]"""
|
967 |
|
968 |
def __init__(self, arguments={}): |
969 |
super(self.__class__, self).__init__(arguments) |
970 |
self.arguments['object_version'] =\ |
971 |
ValueArgument(parsed_name='--object-version',
|
972 |
help='show specific version \ (applies only for objects)')
|
973 |
|
974 |
def main(self, container____path__=None): |
975 |
super(self.__class__, self).main(container____path__) |
976 |
try:
|
977 |
if self.container is None: |
978 |
reply = self.client.get_account_info()
|
979 |
elif self.path is None: |
980 |
reply = self.client.get_container_info(self.container) |
981 |
else:
|
982 |
reply = self.client.get_object_info(self.path, |
983 |
version=self.get_argument('object_version')) |
984 |
except ClientError as err: |
985 |
raiseCLIError(err) |
986 |
print_dict(reply) |
987 |
|
988 |
|
989 |
@command(pithos_cmds)
|
990 |
class store_meta(_store_container_command): |
991 |
"""Get custom meta-content for account [, container [or object]]"""
|
992 |
|
993 |
def __init__(self, arguments={}): |
994 |
super(self.__class__, self).__init__(arguments) |
995 |
self.arguments['detail'] =\ |
996 |
FlagArgument('show detailed output', '-l') |
997 |
self.arguments['until'] =\ |
998 |
DateArgument('show metadata until then', '--until') |
999 |
self.arguments['object_version'] =\ |
1000 |
ValueArgument(parsed_name='--object-version',
|
1001 |
help='show specific version \ (applies only for objects)')
|
1002 |
|
1003 |
def main(self, container____path__=None): |
1004 |
super(self.__class__, self).main(container____path__) |
1005 |
|
1006 |
detail = self.get_argument('detail') |
1007 |
try:
|
1008 |
until = self.get_argument('until') |
1009 |
if self.container is None: |
1010 |
print(bold(self.client.account))
|
1011 |
if detail:
|
1012 |
reply = self.client.get_account_info(until=until)
|
1013 |
else:
|
1014 |
reply = self.client.get_account_meta(until=until)
|
1015 |
reply = pretty_keys(reply, '-')
|
1016 |
elif self.path is None: |
1017 |
print(bold('%s: %s' % (self.client.account, self.container))) |
1018 |
if detail:
|
1019 |
reply = self.client.get_container_info(until=until)
|
1020 |
else:
|
1021 |
cmeta = self.client.get_container_meta(until=until)
|
1022 |
ometa = self.client.get_container_object_meta(until=until)
|
1023 |
reply = {'container-meta': pretty_keys(cmeta, '-'), |
1024 |
'object-meta': pretty_keys(ometa, '-')} |
1025 |
else:
|
1026 |
print(bold('%s: %s:%s'\
|
1027 |
% (self.client.account, self.container, self.path))) |
1028 |
version = self.get_argument('object_version') |
1029 |
if detail:
|
1030 |
reply = self.client.get_object_info(self.path, |
1031 |
version=version) |
1032 |
else:
|
1033 |
reply = self.client.get_object_meta(self.path, |
1034 |
version=version) |
1035 |
reply = pretty_keys(pretty_keys(reply, '-'))
|
1036 |
except ClientError as err: |
1037 |
raiseCLIError(err) |
1038 |
print_dict(reply) |
1039 |
|
1040 |
|
1041 |
@command(pithos_cmds)
|
1042 |
class store_setmeta(_store_container_command): |
1043 |
"""Set a new metadatum for account [, container [or object]]"""
|
1044 |
|
1045 |
def main(self, metakey___metaval, container____path__=None): |
1046 |
super(self.__class__, self).main(container____path__) |
1047 |
try:
|
1048 |
metakey, metavalue = metakey___metaval.split(':')
|
1049 |
except ValueError: |
1050 |
raise CLIError(message='Usage: metakey:metavalue', importance=1) |
1051 |
try:
|
1052 |
if self.container is None: |
1053 |
self.client.set_account_meta({metakey: metavalue})
|
1054 |
elif self.path is None: |
1055 |
self.client.set_container_meta({metakey: metavalue})
|
1056 |
else:
|
1057 |
self.client.set_object_meta(self.path, {metakey: metavalue}) |
1058 |
except ClientError as err: |
1059 |
raiseCLIError(err) |
1060 |
|
1061 |
|
1062 |
@command(pithos_cmds)
|
1063 |
class store_delmeta(_store_container_command): |
1064 |
"""Delete an existing metadatum of account [, container [or object]]"""
|
1065 |
|
1066 |
def main(self, metakey, container____path__=None): |
1067 |
super(self.__class__, self).main(container____path__) |
1068 |
try:
|
1069 |
if self.container is None: |
1070 |
self.client.del_account_meta(metakey)
|
1071 |
elif self.path is None: |
1072 |
self.client.del_container_meta(metakey)
|
1073 |
else:
|
1074 |
self.client.del_object_meta(self.path, metakey) |
1075 |
except ClientError as err: |
1076 |
raiseCLIError(err) |
1077 |
|
1078 |
|
1079 |
@command(pithos_cmds)
|
1080 |
class store_quota(_store_account_command): |
1081 |
"""Get quota for account [or container]"""
|
1082 |
|
1083 |
def main(self, container=None): |
1084 |
super(self.__class__, self).main() |
1085 |
try:
|
1086 |
if container is None: |
1087 |
reply = self.client.get_account_quota()
|
1088 |
else:
|
1089 |
reply = self.client.get_container_quota(container)
|
1090 |
except ClientError as err: |
1091 |
raiseCLIError(err) |
1092 |
print_dict(reply) |
1093 |
|
1094 |
|
1095 |
@command(pithos_cmds)
|
1096 |
class store_setquota(_store_account_command): |
1097 |
"""Set new quota (in KB) for account [or container]"""
|
1098 |
|
1099 |
def main(self, quota, container=None): |
1100 |
super(self.__class__, self).main() |
1101 |
try:
|
1102 |
if container is None: |
1103 |
self.client.set_account_quota(quota)
|
1104 |
else:
|
1105 |
self.client.container = container
|
1106 |
self.client.set_container_quota(quota)
|
1107 |
except ClientError as err: |
1108 |
raiseCLIError(err) |
1109 |
|
1110 |
|
1111 |
@command(pithos_cmds)
|
1112 |
class store_versioning(_store_account_command): |
1113 |
"""Get versioning for account [or container ]"""
|
1114 |
|
1115 |
def main(self, container=None): |
1116 |
super(self.__class__, self).main() |
1117 |
try:
|
1118 |
if container is None: |
1119 |
reply = self.client.get_account_versioning()
|
1120 |
else:
|
1121 |
reply = self.client.get_container_versioning(container)
|
1122 |
except ClientError as err: |
1123 |
raiseCLIError(err) |
1124 |
print_dict(reply) |
1125 |
|
1126 |
|
1127 |
@command(pithos_cmds)
|
1128 |
class store_setversioning(_store_account_command): |
1129 |
"""Set new versioning (auto, none) for account [or container]"""
|
1130 |
|
1131 |
def main(self, versioning, container=None): |
1132 |
super(self.__class__, self).main() |
1133 |
try:
|
1134 |
if container is None: |
1135 |
self.client.set_account_versioning(versioning)
|
1136 |
else:
|
1137 |
self.client.container = container
|
1138 |
self.client.set_container_versioning(versioning)
|
1139 |
except ClientError as err: |
1140 |
raiseCLIError(err) |
1141 |
|
1142 |
|
1143 |
@command(pithos_cmds)
|
1144 |
class store_group(_store_account_command): |
1145 |
"""Get user groups details for account"""
|
1146 |
|
1147 |
def main(self): |
1148 |
super(self.__class__, self).main() |
1149 |
try:
|
1150 |
reply = self.client.get_account_group()
|
1151 |
except ClientError as err: |
1152 |
raiseCLIError(err) |
1153 |
print_dict(reply) |
1154 |
|
1155 |
|
1156 |
@command(pithos_cmds)
|
1157 |
class store_setgroup(_store_account_command): |
1158 |
"""Create/update a new user group on account"""
|
1159 |
|
1160 |
def main(self, groupname, *users): |
1161 |
super(self.__class__, self).main() |
1162 |
try:
|
1163 |
self.client.set_account_group(groupname, users)
|
1164 |
except ClientError as err: |
1165 |
raiseCLIError(err) |
1166 |
|
1167 |
|
1168 |
@command(pithos_cmds)
|
1169 |
class store_delgroup(_store_account_command): |
1170 |
"""Delete a user group on an account"""
|
1171 |
|
1172 |
def main(self, groupname): |
1173 |
super(self.__class__, self).main() |
1174 |
try:
|
1175 |
self.client.del_account_group(groupname)
|
1176 |
except ClientError as err: |
1177 |
raiseCLIError(err) |
1178 |
|
1179 |
|
1180 |
@command(pithos_cmds)
|
1181 |
class store_sharers(_store_account_command): |
1182 |
"""List the accounts that share objects with default account"""
|
1183 |
|
1184 |
def __init__(self, arguments={}): |
1185 |
super(self.__class__, self).__init__(arguments) |
1186 |
self.arguments['detail'] =\ |
1187 |
FlagArgument('show detailed output', '-l') |
1188 |
self.arguments['limit'] =\ |
1189 |
IntArgument('show limited output', '--n', default=1000) |
1190 |
self.arguments['marker'] =\ |
1191 |
ValueArgument('show output greater then marker', '--marker') |
1192 |
|
1193 |
def main(self): |
1194 |
super(self.__class__, self).main() |
1195 |
try:
|
1196 |
marker = self.get_argument('marker') |
1197 |
accounts = self.client.get_sharing_accounts(marker=marker)
|
1198 |
except ClientError as err: |
1199 |
raiseCLIError(err) |
1200 |
|
1201 |
for acc in accounts: |
1202 |
stdout.write(bold(acc['name']) + ' ') |
1203 |
if self.get_argument('detail'): |
1204 |
print_dict(acc, exclude='name', ident=4) |
1205 |
if not self.get_argument('detail'): |
1206 |
print
|
1207 |
|
1208 |
|
1209 |
@command(pithos_cmds)
|
1210 |
class store_versions(_store_container_command): |
1211 |
"""Get the version list of an object"""
|
1212 |
|
1213 |
def main(self, container___path): |
1214 |
super(store_versions, self).main(container___path) |
1215 |
try:
|
1216 |
versions = self.client.get_object_versionlist(self.path) |
1217 |
except ClientError as err: |
1218 |
raise CLIError(err)
|
1219 |
|
1220 |
print('%s:%s versions' % (self.container, self.path)) |
1221 |
for vitem in versions: |
1222 |
t = localtime(float(vitem[1])) |
1223 |
vid = bold(unicode(vitem[0])) |
1224 |
print('\t%s \t(%s)' % (vid, strftime('%d-%m-%Y %H:%M:%S', t))) |