aboutsummaryrefslogtreecommitdiffstats
path: root/qtip/util/export_to.py
blob: 4d054c66fe39a11eeb7f075b8f7a639f1ba9464e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
##############################################################################
# Copyright (c) 2017 ZTE and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

import json


def export_to_file(func):
    def func_wrapper(*args, **kwargs):
        dest = kwargs.pop('dest', None)
        content = func(*args, **kwargs)
        if dest is not None:
            with open(dest, 'w+') as f:
                f.write(json.dumps(content, indent=2))
        return content
    return func_wrapper