aboutsummaryrefslogtreecommitdiffstats
path: root/qtip/util
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-25 14:08:01 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-25 16:58:31 +0800
commit2189e3bfdf1d250fa1201f89249745d4d6aab7f0 (patch)
tree3a5ab98cdd7632bd80c9181001a635c72a252eef /qtip/util
parent6463b6635a8094a0ddcf83605cd231ba46104f72 (diff)
Rewrite `export_to_file` as decorator
Change-Id: Ibf852038fac986801a3fc2c608a0ddb1572abbde Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip/util')
-rw-r--r--qtip/util/export_to.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/qtip/util/export_to.py b/qtip/util/export_to.py
index 98c39b5f..17adae7c 100644
--- a/qtip/util/export_to.py
+++ b/qtip/util/export_to.py
@@ -10,6 +10,11 @@
import json
-def export_to_file(content, filename):
- with open(filename, 'w+') as f:
- f.write(json.dumps(content, indent=2))
+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