Revision 098ca087
b/kamaki/cli.py | ||
---|---|---|
66 | 66 |
The order of commands is important, it will be preserved in the help output. |
67 | 67 |
""" |
68 | 68 |
|
69 |
from __future__ import print_function |
|
70 |
|
|
69 | 71 |
import inspect |
70 | 72 |
import logging |
71 | 73 |
import os |
... | ... | |
75 | 77 |
from optparse import OptionParser |
76 | 78 |
from os.path import abspath, basename, exists |
77 | 79 |
from pwd import getpwuid |
78 |
from sys import argv, exit, stdout |
|
80 |
from sys import argv, exit, stdout, stderr
|
|
79 | 81 |
|
80 | 82 |
from clint import args |
81 |
from clint.textui import puts, puts_err, indent, progress |
|
82 |
from clint.textui.cols import columns |
|
83 |
from clint.textui import progress |
|
83 | 84 |
from colors import magenta, red, yellow |
84 | 85 |
from requests.exceptions import ConnectionError |
85 | 86 |
|
... | ... | |
149 | 150 |
for section in sorted(self.config.sections()): |
150 | 151 |
items = self.config.items(section, include_defaults) |
151 | 152 |
for key, val in sorted(items): |
152 |
puts('%s.%s = %s' % (section, key, val))
|
|
153 |
print('%s.%s = %s' % (section, key, val))
|
|
153 | 154 |
|
154 | 155 |
|
155 | 156 |
@command(api='config') |
... | ... | |
161 | 162 |
section = section or 'global' |
162 | 163 |
value = self.config.get(section, key) |
163 | 164 |
if value is not None: |
164 |
print value
|
|
165 |
print(value)
|
|
165 | 166 |
|
166 | 167 |
|
167 | 168 |
@command(api='config') |
... | ... | |
229 | 230 |
path = p[0] |
230 | 231 |
|
231 | 232 |
if not path: |
232 |
print "Invalid personality argument '%s'" % p
|
|
233 |
print("Invalid personality argument '%s'" % p)
|
|
233 | 234 |
return 1 |
234 | 235 |
if not exists(path): |
235 |
print "File %s does not exist" % path
|
|
236 |
print("File %s does not exist" % path)
|
|
236 | 237 |
return 1 |
237 | 238 |
|
238 | 239 |
with open(path) as f: |
... | ... | |
606 | 607 |
for property in self.options.properties or []: |
607 | 608 |
key, sep, val = property.partition('=') |
608 | 609 |
if not sep: |
609 |
print "Invalid property '%s'" % property
|
|
610 |
print("Invalid property '%s'" % property)
|
|
610 | 611 |
return 1 |
611 | 612 |
properties[key.strip()] = val.strip() |
612 | 613 |
|
... | ... | |
620 | 621 |
def main(self, image_id): |
621 | 622 |
members = self.client.list_members(image_id) |
622 | 623 |
for member in members: |
623 |
print member['member_id']
|
|
624 |
print(member['member_id'])
|
|
624 | 625 |
|
625 | 626 |
|
626 | 627 |
@command(api='image') |
... | ... | |
630 | 631 |
def main(self, member): |
631 | 632 |
images = self.client.list_shared(member) |
632 | 633 |
for image in images: |
633 |
print image['image_id']
|
|
634 |
print(image['image_id'])
|
|
634 | 635 |
|
635 | 636 |
|
636 | 637 |
@command(api='image') |
... | ... | |
737 | 738 |
super(store_list, self).main() |
738 | 739 |
for object in self.client.list_objects(): |
739 | 740 |
size = self.format_size(object['bytes']) |
740 |
print '%6s %s' % (size, object['name'])
|
|
741 |
print('%6s %s' % (size, object['name']))
|
|
741 | 742 |
|
742 | 743 |
|
743 | 744 |
@command(api='storage') |
... | ... | |
810 | 811 |
|
811 | 812 |
|
812 | 813 |
def print_groups(): |
813 |
puts('\nGroups:') |
|
814 |
with indent(2): |
|
815 |
for group in _commands: |
|
816 |
description = GROUPS.get(group, '') |
|
817 |
puts(columns([group, 12], [description, 60])) |
|
814 |
print('\nGroups:') |
|
815 |
for group in _commands: |
|
816 |
description = GROUPS.get(group, '') |
|
817 |
print(' ', group.ljust(12), description) |
|
818 | 818 |
|
819 | 819 |
|
820 | 820 |
def print_commands(group): |
821 | 821 |
description = GROUPS.get(group, '') |
822 | 822 |
if description: |
823 |
puts('\n' + description)
|
|
823 |
print('\n' + description)
|
|
824 | 824 |
|
825 |
puts('\nCommands:') |
|
826 |
with indent(2): |
|
827 |
for name, cls in _commands[group].items(): |
|
828 |
puts(columns([name, 14], [cls.description, 60])) |
|
825 |
print('\nCommands:') |
|
826 |
for name, cls in _commands[group].items(): |
|
827 |
print(' ', name.ljust(14), cls.description) |
|
829 | 828 |
|
830 | 829 |
|
831 | 830 |
def add_handler(name, level, prefix=''): |
... | ... | |
866 | 865 |
|
867 | 866 |
if args.contains(['-V', '--version']): |
868 | 867 |
import kamaki |
869 |
print "kamaki %s" % kamaki.__version__
|
|
868 |
print("kamaki %s" % kamaki.__version__)
|
|
870 | 869 |
exit(0) |
871 | 870 |
|
872 | 871 |
if '--config' in args: |
... | ... | |
877 | 876 |
for option in args.grouped.get('-o', []): |
878 | 877 |
keypath, sep, val = option.partition('=') |
879 | 878 |
if not sep: |
880 |
print "Invalid option '%s'" % option
|
|
879 |
print("Invalid option '%s'" % option)
|
|
881 | 880 |
exit(1) |
882 | 881 |
section, sep, key = keypath.partition('.') |
883 | 882 |
if not sep: |
884 |
print "Invalid option '%s'" % option
|
|
883 |
print("Invalid option '%s'" % option)
|
|
885 | 884 |
exit(1) |
886 | 885 |
config.override(section.strip(), key.strip(), val.strip()) |
887 | 886 |
|
... | ... | |
1004 | 1003 |
else: |
1005 | 1004 |
color = red |
1006 | 1005 |
|
1007 |
puts_err(color(err.message))
|
|
1006 |
print(color(err.message), file=stderr)
|
|
1008 | 1007 |
if err.details and (options.verbose or options.debug): |
1009 |
puts_err(err.details)
|
|
1008 |
print(err.details, file=stderr)
|
|
1010 | 1009 |
exit(2) |
1011 | 1010 |
except ConnectionError as err: |
1012 |
puts_err(red("Connection error"))
|
|
1011 |
print(red("Connection error"), file=stderr)
|
|
1013 | 1012 |
exit(1) |
1014 | 1013 |
|
1015 | 1014 |
|
Also available in: Unified diff