Package modules :: Package reporting :: Module jsondump
[hide private]
[frames] | no frames]

Source Code for Module modules.reporting.jsondump

 1  # Copyright (C) 2010-2015 Cuckoo Foundation. 
 2  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
 3  # See the file 'docs/LICENSE' for copying permission. 
 4   
 5  import os 
 6  import json 
 7  import codecs 
 8   
 9  from lib.cuckoo.common.abstracts import Report 
10  from lib.cuckoo.common.exceptions import CuckooReportError 
11   
12 -class JsonDump(Report):
13 """Saves analysis results in JSON format.""" 14
15 - def run(self, results):
16 """Writes report. 17 @param results: Cuckoo results dict. 18 @raise CuckooReportError: if fails to write report. 19 """ 20 indent = self.options.get("indent", 4) 21 encoding = self.options.get("encoding", "utf-8") 22 23 try: 24 path = os.path.join(self.reports_path, "report.json") 25 with codecs.open(path, "w", "utf-8") as report: 26 json.dump(results, report, sort_keys=False, 27 indent=int(indent), encoding=encoding) 28 except (UnicodeError, TypeError, IOError) as e: 29 raise CuckooReportError("Failed to generate JSON report: %s" % e)
30