Revision 447c9568
b/kamaki/cli/commands/pithos_cli.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
from kamaki.cli import command |
35 | 35 |
from kamaki.cli.command_tree import CommandTree |
36 |
from kamaki.cli.errors import raiseCLIError |
|
36 |
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
|
|
37 | 37 |
from kamaki.cli.utils import format_size, print_dict, pretty_keys |
38 | 38 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
39 | 39 |
from kamaki.cli.argument import KeyValueArgument |
... | ... | |
228 | 228 |
assert isinstance(container_with_path, str) |
229 | 229 |
except AssertionError as err: |
230 | 230 |
raiseCLIError(err) |
231 |
if ':' not in container_with_path: |
|
232 |
if self.get_argument('container') is not None: |
|
233 |
self.container = self.get_argument('container') |
|
234 |
else: |
|
235 |
self.container = self.client.container |
|
236 |
if self.container is None: |
|
237 |
self.container = container_with_path |
|
238 |
else: |
|
239 |
self.path = container_with_path |
|
240 |
if not path_is_optional and self.path is None: |
|
241 |
raiseCLIError(None, 'Object path is missing\n', importance=1) |
|
242 |
return |
|
243 |
cnp = container_with_path.split(':') |
|
244 |
self.container = cnp[0] |
|
245 |
try: |
|
246 |
self.path = cnp[1] |
|
247 |
except IndexError as err: |
|
248 |
if path_is_optional: |
|
231 |
|
|
232 |
cont, sep, path = container_with_path.partition(':') |
|
233 |
|
|
234 |
if sep: |
|
235 |
if not cont: |
|
236 |
raiseCLIError(None, 'Container is missing\n', importance=1) |
|
237 |
alt_cont = self.get_argument('container') |
|
238 |
if alt_cont and cont != alt_cont: |
|
239 |
raiseCLIError(None, |
|
240 |
'Conflict: 2 containers (%s, %s)' % (cont, alt_cont), |
|
241 |
importance=1) |
|
242 |
self.container = cont |
|
243 |
if not path: |
|
244 |
raiseCLIError(None, |
|
245 |
'Path is missing for object in container %s' % cont, |
|
246 |
importance=1, |
|
247 |
details='Usage: <container>:<object path>') |
|
248 |
self.path = path |
|
249 |
else: |
|
250 |
alt_cont = self.get_argument('container') or self.client.container |
|
251 |
if alt_cont: |
|
252 |
self.container = alt_cont |
|
253 |
self.path = cont |
|
254 |
elif path_is_optional: |
|
255 |
self.container = cont |
|
249 | 256 |
self.path = None |
250 | 257 |
else: |
251 |
raiseCLIError(err, 'Object path is missing\n', importance=1) |
|
258 |
self.container = cont |
|
259 |
raiseCLIError(CLISyntaxError( |
|
260 |
'Syntax error: container and path are both required', |
|
261 |
importance=1, |
|
262 |
details='Usage: <container>:<object path>')) |
|
252 | 263 |
|
253 | 264 |
def main(self, container_with_path=None, path_is_optional=True): |
254 | 265 |
super(_store_container_command, self).main() |
Also available in: Unified diff