Revision 14b25e00 kamaki/cli/commands/pithos.py
b/kamaki/cli/commands/pithos.py | ||
---|---|---|
40 | 40 |
from kamaki.cli.command_tree import CommandTree |
41 | 41 |
from kamaki.cli.errors import raiseCLIError, CLISyntaxError |
42 | 42 |
from kamaki.cli.utils import ( |
43 |
format_size, |
|
44 |
to_bytes, |
|
45 |
print_dict, |
|
46 |
print_items, |
|
47 |
pretty_keys, |
|
48 |
page_hold, |
|
49 |
bold, |
|
50 |
ask_user) |
|
43 |
format_size, to_bytes, print_dict, print_items, pretty_keys, |
|
44 |
page_hold, bold, ask_user, get_path_size) |
|
51 | 45 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
52 | 46 |
from kamaki.cli.argument import KeyValueArgument, DateArgument |
53 | 47 |
from kamaki.cli.argument import ProgressBarArgument |
... | ... | |
1029 | 1023 |
overwrite=FlagArgument('Force (over)write', ('-f', '--force')) |
1030 | 1024 |
) |
1031 | 1025 |
|
1026 |
def _check_container_limit(self, path): |
|
1027 |
cl_dict = self.client.get_container_limit() |
|
1028 |
container_limit = int(cl_dict['x-container-policy-quota']) |
|
1029 |
path_size = get_path_size(path) |
|
1030 |
if path_size > container_limit: |
|
1031 |
raiseCLIError('Container(%s) limit(%s) < size(%s) of %s' % ( |
|
1032 |
self.client.container, |
|
1033 |
format_size(container_limit), |
|
1034 |
format_size(path_size), |
|
1035 |
path), |
|
1036 |
importance=1, details=[ |
|
1037 |
'Check accound limit: /file quota', |
|
1038 |
'Check container limit:', |
|
1039 |
'\t/file containerlimit get %s' % self.client.container, |
|
1040 |
'Increase container limit:', |
|
1041 |
'\t/file containerlimit set <new limit> %s' % ( |
|
1042 |
self.client.container)]) |
|
1043 |
|
|
1032 | 1044 |
def _path_pairs(self, local_path, remote_path): |
1033 | 1045 |
"""Get pairs of local and remote paths""" |
1034 | 1046 |
lpath = path.abspath(local_path) |
1047 |
self._check_container_limit(lpath) |
|
1035 | 1048 |
short_path = lpath.split(path.sep)[-1] |
1036 | 1049 |
rpath = remote_path or short_path |
1037 | 1050 |
if path.isdir(lpath): |
... | ... | |
1067 | 1080 |
for f in files: |
1068 | 1081 |
fpath = path.join(top, f) |
1069 | 1082 |
if path.isfile(fpath): |
1070 |
yield open(fpath, 'rb'), '%s%s/%s' % ( |
|
1071 |
rpath, rel_path, f) |
|
1083 |
yield open(fpath, 'rb'), '%s/%s' % (rel_path, f) |
|
1072 | 1084 |
else: |
1073 | 1085 |
print('%s is not a regular file' % fpath) |
1074 | 1086 |
else: |
1087 |
if not path.isfile(lpath): |
|
1088 |
raiseCLIError('%s is not a regular file' % lpath) |
|
1075 | 1089 |
try: |
1076 | 1090 |
robj = self.client.get_object_info(rpath) |
1077 | 1091 |
if remote_path and self._is_dir(robj): |
... | ... | |
1102 | 1116 |
content_disposition=self['content_disposition'], |
1103 | 1117 |
sharing=self['sharing'], |
1104 | 1118 |
public=self['public']) |
1105 |
|
|
1106 | 1119 |
for f, rpath in self._path_pairs(local_path, remote_path): |
1107 | 1120 |
print('%s --> %s:%s' % (f.name, self.client.container, rpath)) |
1108 | 1121 |
if self['unchunked']: |
Also available in: Unified diff