|
48 | 48 | # Additional Formatting style |
49 | 49 | line1 = "---------------------------------------------------------------------------------------------------------" |
50 | 50 |
|
| 51 | +def sanitize_string(v): |
| 52 | + return v.decode('utf-8', 'ignore') |
| 53 | + |
| 54 | +def sanitize_dict(d): |
| 55 | + for k, v in d.iteritems(): |
| 56 | + if isinstance(v, dict): |
| 57 | + d[k] = sanitize_dict(v) |
| 58 | + elif isinstance(v, str): |
| 59 | + d[k] = sanitize_string(v) |
| 60 | + else: |
| 61 | + d[k] = v |
| 62 | + return d |
| 63 | + |
51 | 64 | # username defined |
52 | 65 | username = commands.getoutput("whoami") |
53 | 66 |
|
@@ -172,7 +185,8 @@ def dump_table( db, user, table_name, count, target_dir, is_ras=False ): |
172 | 185 | colnames = [desc[0] for desc in cursor.description] |
173 | 186 | for row in cursor: |
174 | 187 | file.write('{{ "type":"db-{0}", "data":{1} }}\n'.format( |
175 | | - table_name, json.dumps(dict(zip(colnames, row)), default=str))) |
| 188 | + table_name, json.dumps(sanitize_dict(dict(zip(colnames, row))), |
| 189 | + default=str))) |
176 | 190 | except Exception as e: |
177 | 191 | print "[INFO] Exception caught: {0}".format(e) |
178 | 192 | logger.info("Exception caught: {0}".format(e)) |
@@ -262,7 +276,7 @@ def main(args): |
262 | 276 | entry = dump_table( args.db, args.user, table, args.count, temp_dir, True) |
263 | 277 | if entry is None:0 |
264 | 278 | else: |
265 | | - print entry args.target |
| 279 | + print (entry, args.target) |
266 | 280 |
|
267 | 281 | # After the tables are dumped, it's time to merge them into the weekly report. |
268 | 282 | rollupDir(temp_dir,"..") |
|
0 commit comments