summaryrefslogtreecommitdiffstats
path: root/qtip/util/export_to.py
blob: 17adae7c52516859f95f50163b540f84e85ddb99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
##############################################################################
# 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(spec, metrics, dest=None):
        content = func(spec, metrics)
        if dest is not None:
            with open(dest, 'w+') as f:
                f.write(json.dumps(content, indent=2))
        return content
    return func_wrapper