Revision a0608786 kamaki/cli/utils.py

b/kamaki/cli/utils.py
40 40
from kamaki.cli.errors import raiseCLIError
41 41

  
42 42

  
43
IDENT_TAB = 4
43
INDENT_TAB = 4
44 44

  
45 45

  
46 46
suggest = dict(ansicolors=dict(
......
113 113

  
114 114
    :param data: json-dumpable data
115 115
    """
116
    print(dumps(data, indent=IDENT_TAB))
116
    print(dumps(data, indent=INDENT_TAB))
117 117

  
118 118

  
119 119
def pretty_dict(d, *args, **kwargs):
......
127 127
    """Pretty-print a dictionary object
128 128
    <indent>key: <non iterable item>
129 129
    <indent>key:
130
    <indent + IDENT_TAB><pretty-print iterable>
130
    <indent + INDENT_TAB><pretty-print iterable>
131 131

  
132 132
    :param d: (dict)
133 133

  
......
155 155
        if isinstance(v, dict):
156 156
            print print_str
157 157
            print_dict(
158
                v, exclude, indent + IDENT_TAB,
158
                v, exclude, indent + INDENT_TAB,
159 159
                recursive_enumeration, recursive_enumeration)
160 160
        elif isinstance(v, list) or isinstance(v, tuple):
161 161
            print print_str
162 162
            print_list(
163
                v, exclude, indent + IDENT_TAB,
163
                v, exclude, indent + INDENT_TAB,
164 164
                recursive_enumeration, recursive_enumeration)
165 165
        else:
166 166
            print '%s %s' % (print_str, v)
......
173 173
    """Pretty-print a list of items
174 174
    <indent>key: <non iterable item>
175 175
    <indent>key:
176
    <indent + IDENT_TAB><pretty-print iterable>
176
    <indent + INDENT_TAB><pretty-print iterable>
177 177

  
178 178
    :param l: (list)
179 179

  
......
192 192
        'print_list prinbts a list or tuple')
193 193
    assert indent >= 0, 'print_list indent must be >= 0'
194 194

  
195
    counter = 0
195 196
    for i, item in enumerate(l):
196 197
        print_str = ' ' * indent
197 198
        print_str += '%s.' % (i + 1) if with_enumeration else ''
198 199
        if isinstance(item, dict):
199 200
            if with_enumeration:
200 201
                print print_str
202
            elif counter and counter < len(l):
203
                print
201 204
            print_dict(
202
                item, exclude, indent,
205
                item, exclude,
206
                indent + (INDENT_TAB if with_enumeration else 0),
203 207
                recursive_enumeration, recursive_enumeration)
204 208
        elif isinstance(item, list) or isinstance(item, tuple):
205 209
            if with_enumeration:
206 210
                print print_str
211
            elif counter and counter < len(l):
212
                print
207 213
            print_list(
208
                item, exclude, indent + IDENT_TAB,
214
                item, exclude, indent + INDENT_TAB,
209 215
                recursive_enumeration, recursive_enumeration)
210 216
        else:
211 217
            item = ('%s' % item).strip()
212 218
            if item in exclude:
213 219
                continue
214 220
            print '%s%s' % (print_str, item)
215
        if (i + 1) < len(l):
216
            print
221
        counter += 1
217 222

  
218 223

  
219 224
def page_hold(index, limit, maxlen):
......
274 279
                header = ' '.join('%s' % item.pop(key) for key in title)
275 280
            print(bold(header))
276 281
        if isinstance(item, dict):
277
            print_dict(item, indent=IDENT_TAB)
282
            print_dict(item, indent=INDENT_TAB)
278 283
        elif isinstance(item, list):
279
            print_list(item, indent=IDENT_TAB)
284
            print_list(item, indent=INDENT_TAB)
280 285
        else:
281 286
            print(' %s' % item)
282 287
        page_hold(i + 1, page_size, len(items))

Also available in: Unified diff