Revision 6acfcec4 kamaki/cli/utils/__init__.py

b/kamaki/cli/utils/__init__.py
117 117

  
118 118
    :param out: Input/Output stream to dump values into
119 119
    """
120
    out.writelines(unicode(dumps(data, indent=INDENT_TAB) + '\n'))
120
    out.write(unicode(dumps(data, indent=INDENT_TAB) + '\n'))
121
    out.flush()
121 122

  
122 123

  
123 124
def print_dict(
......
155 156
        print_str += u'%s.' % (i + 1) if with_enumeration else u''
156 157
        print_str += u'%s:' % k
157 158
        if isinstance(v, dict):
158
            out.writelines(print_str + '\n')
159
            out.write(print_str + '\n')
159 160
            print_dict(
160 161
                v, exclude, indent + INDENT_TAB,
161 162
                recursive_enumeration, recursive_enumeration, out)
162 163
        elif isinstance(v, list) or isinstance(v, tuple):
163
            out.writelines(print_str + '\n')
164
            out.write(print_str + '\n')
164 165
            print_list(
165 166
                v, exclude, indent + INDENT_TAB,
166 167
                recursive_enumeration, recursive_enumeration, out)
167 168
        else:
168
            out.writelines(u'%s %s\n' % (print_str, v))
169
            out.write(u'%s %s\n' % (print_str, v))
170
        out.flush()
169 171

  
170 172

  
171 173
def print_list(
......
201 203
        print_str += u'%s.' % (i + 1) if with_enumeration else u''
202 204
        if isinstance(item, dict):
203 205
            if with_enumeration:
204
                out.writelines(print_str + '\n')
206
                out.write(print_str + '\n')
205 207
            elif i and i < len(l):
206
                out.writelines(u'\n')
208
                out.write(u'\n')
207 209
            print_dict(
208 210
                item, exclude,
209 211
                indent + (INDENT_TAB if with_enumeration else 0),
210 212
                recursive_enumeration, recursive_enumeration, out)
211 213
        elif isinstance(item, list) or isinstance(item, tuple):
212 214
            if with_enumeration:
213
                out.writelines(print_str + '\n')
215
                out.write(print_str + '\n')
214 216
            elif i and i < len(l):
215
                out.writelines(u'\n')
217
                out.write(u'\n')
216 218
            print_list(
217 219
                item, exclude, indent + INDENT_TAB,
218 220
                recursive_enumeration, recursive_enumeration, out)
......
221 223
            if item in exclude:
222 224
                continue
223 225
            out.write(u'%s%s\n' % (print_str, item))
224
            out.flush()
226
        out.flush()
227
    out.flush()
225 228

  
226 229

  
227 230
def print_items(
......
244 247
        return
245 248
    if not (isinstance(items, dict) or isinstance(items, list) or isinstance(
246 249
                items, tuple)):
247
        out.writelines(u'%s\n' % items)
250
        out.write(u'%s\n' % items)
251
        out.flush()
248 252
        return
249 253

  
250 254
    for i, item in enumerate(items):
......
255 259
            title = sorted(set(title).intersection(item))
256 260
            pick = item.get if with_redundancy else item.pop
257 261
            header = u' '.join(u'%s' % pick(key) for key in title)
258
            out.writelines((unicode(bold(header) if header else '') + '\n'))
262
            out.write((unicode(bold(header) if header else '') + '\n'))
259 263
            print_dict(item, indent=INDENT_TAB, out=out)
260 264
        elif isinstance(item, list) or isinstance(item, tuple):
261 265
            print_list(item, indent=INDENT_TAB, out=out)
262 266
        else:
263
            out.writelines(u' %s\n' % item)
267
            out.write(u' %s\n' % item)
268
        out.flush()
269
    out.flush()
264 270

  
265 271

  
266 272
def format_size(size, decimal_factors=False):

Also available in: Unified diff