(results, output_file)
| 78 | |
| 79 | |
| 80 | def write_csv(results, output_file): |
| 81 | # FIXME: this is reading all in memory |
| 82 | results = list(results) |
| 83 | |
| 84 | headers = dict([ |
| 85 | ('info', []), |
| 86 | ('license', []), |
| 87 | ('copyright', []), |
| 88 | ('email', []), |
| 89 | ('url', []), |
| 90 | ('package', []), |
| 91 | ]) |
| 92 | |
| 93 | # note: FIXME: headers are collected as a side effect and this is not great |
| 94 | rows = list(flatten_scan(results, headers)) |
| 95 | |
| 96 | ordered_headers = [] |
| 97 | for key_group in headers.values(): |
| 98 | ordered_headers.extend(key_group) |
| 99 | |
| 100 | w = csv.DictWriter(output_file, fieldnames=ordered_headers) |
| 101 | w.writeheader() |
| 102 | |
| 103 | for r in rows: |
| 104 | w.writerow(r) |
| 105 | |
| 106 | |
| 107 | def flatten_scan(scan, headers): |
no test coverage detected