diff options
| author | J08nY | 2020-10-18 17:42:56 +0200 |
|---|---|---|
| committer | J08nY | 2020-10-18 17:42:56 +0200 |
| commit | edaa68a3bdbe40027cb1e809d7b5790c480d52cd (patch) | |
| tree | d4cece55e9d3c993a9ee6aeb4d83c38fe8d28a5c | |
| parent | 9357918d2f44a6754e7f21a17ea038ca8452e522 (diff) | |
| download | sec-certs-edaa68a3bdbe40027cb1e809d7b5790c480d52cd.tar.gz sec-certs-edaa68a3bdbe40027cb1e809d7b5790c480d52cd.tar.zst sec-certs-edaa68a3bdbe40027cb1e809d7b5790c480d52cd.zip | |
Replace json.dumps with json.dump to file.
| -rw-r--r-- | sec_certs/extract_certificates.py | 38 | ||||
| -rwxr-xr-x | sec_certs/fips_certificates.py | 9 | ||||
| -rwxr-xr-x | sec_certs/process_certificates.py | 16 |
3 files changed, 26 insertions, 37 deletions
diff --git a/sec_certs/extract_certificates.py b/sec_certs/extract_certificates.py index cc0bc8af..ae5bb2cc 100644 --- a/sec_certs/extract_certificates.py +++ b/sec_certs/extract_certificates.py @@ -472,7 +472,7 @@ def search_only_headers_bsi(walk_dir: Path): print_found_properties(items_found_all) with open("certificate_data_bsiheader.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps(items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, indent=4, sort_keys=True) print('\n*** Certificates without detected preface:') for file_name in files_without_match: @@ -689,7 +689,7 @@ def search_only_headers_anssi(walk_dir: Path): # store results into file with fixed name and also with time appendix with open("certificate_data_anssiheader.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps(items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, indent=4, sort_keys=True) print('\n*** Certificates without detected preface:') for file_name in files_without_match: @@ -728,8 +728,7 @@ def extract_certificates_frontpage(walk_dir: Path, write_output_file=True): if write_output_file: with open("certificate_data_frontpage_all.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, indent=4, sort_keys=True) return items_found_all @@ -1080,7 +1079,7 @@ def search_pp_only_headers(walk_dir: Path): print_found_properties(items_found_all) with open("pp_data_header.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps(items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, indent=4, sort_keys=True) print('\n*** Protection profiles without detected header:') for file_name in files_without_match: @@ -1102,8 +1101,7 @@ def extract_protectionprofiles_frontpage(walk_dir: Path, write_output_file=True) # store results into file with fixed name and also with time appendix if write_output_file: with open("pp_data_frontpage_all.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - pp_items_found, indent=4, sort_keys=True)) + json.dump(pp_items_found, write_file, indent=4, sort_keys=True) return pp_items_found @@ -1139,15 +1137,14 @@ def extract_certificates_keywords(walk_dir: Path, fragments_dir: Path, file_pref # save report text with highlighted/replaced matches into \\fragments\\ directory base_path = file_name[:file_name.rfind(os.sep)] file_name_short = file_name[file_name.rfind(os.sep) + 1:] - target_file = '{}{}{}'.format(fragments_dir, os.sep, file_name_short) + target_file = fragments_dir / file_name_short save_modified_cert_file( target_file, modified_cert_file[0], modified_cert_file[1]) # store results into file with fixed name if write_output_file: with open("{}_data_keywords_all.json".format(file_prefix), "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - all_items_found, indent=4, sort_keys=True)) + json.dump(all_items_found, write_file, indent=4, sort_keys=True) # print('\nTotal matches found in separate files:') # print_total_matches_in_files(all_items_found_count) @@ -1227,15 +1224,13 @@ def extract_certificates_pdfmeta(walk_dir: Path, file_prefix, write_output_file= # store results into file with fixed name with open("{}_data_pdfmeta_{}.json".format(file_prefix, counter), "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - all_items_found, indent=4, sort_keys=True)) + json.dump(all_items_found, write_file, indent=4, sort_keys=True) counter += 1 # store allresults into file with fixed name if write_output_file: with open("{}_data_pdfmeta_all.json".format(file_prefix), "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - all_items_found, indent=4, sort_keys=True)) + json.dump(all_items_found, write_file, indent=4, sort_keys=True) return all_items_found @@ -1835,8 +1830,7 @@ def extract_certificates_html(base_dir: Path, write_output_file: bool = True): if write_output_file: with open("certificate_data_html_active.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - items_found_all_active, indent=4, sort_keys=True)) + json.dump(items_found_all_active, write_file, indent=4, sort_keys=True) generate_download_script('download_active_certs.bat', 'certs', 'targets', CC_WEB_URL, download_files_certs) @@ -1851,8 +1845,7 @@ def extract_certificates_html(base_dir: Path, write_output_file: bool = True): if write_output_file: with open("certificate_data_html_archived.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - items_found_all_archived, indent=4, sort_keys=True)) + json.dump(items_found_all_archived, write_file, indent=4, sort_keys=True) generate_download_script('download_archived_certs.bat', 'certs', 'targets', CC_WEB_URL, download_files_certs) @@ -1863,8 +1856,7 @@ def extract_certificates_html(base_dir: Path, write_output_file: bool = True): if write_output_file: with open("certificate_data_html_all.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, indent=4, sort_keys=True) return items_found_all @@ -1884,8 +1876,7 @@ def extract_certificates_csv(base_dir: Path, write_output_file: bool = True): if write_output_file: with open("certificate_data_csv_all.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, ndent=4, sort_keys=True) return items_found_all @@ -1917,8 +1908,7 @@ def extract_protectionprofiles_csv(base_dir: Path, write_output_file: bool = Tru if write_output_file: with open("pp_data_csv_all.json", "w", errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - items_found_all, indent=4, sort_keys=True)) + json.dump(items_found_all, write_file, indent=4, sort_keys=True) return items_found_all diff --git a/sec_certs/fips_certificates.py b/sec_certs/fips_certificates.py index 3f473ecd..1647f255 100755 --- a/sec_certs/fips_certificates.py +++ b/sec_certs/fips_certificates.py @@ -149,8 +149,7 @@ def fips_search_html(base_dir, output_file, dump_to_file=False): if dump_to_file: with open(output_file, 'w', errors=FILE_ERRORS_STRATEGY) as write_file: - write_file.write(json.dumps( - all_found_items, indent=4, sort_keys=True)) + json.dump(all_found_items, write_file, indent=4, sort_keys=True) return all_found_items @@ -412,7 +411,7 @@ def main(): os.path.join(FIPS_BASE_DIR, 'fragments'), 'fips', fips_items=fips_items, should_censure_right_away=True, write_output_file=True) with open(FIPS_RESULTS_DIR + 'fips_data_keywords_all.json', 'w') as f: - f.write(json.dumps(items, indent=4, sort_keys=True)) + json.dump(items, f, indent=4, sort_keys=True) break print("EXTRACTION DONE") @@ -423,7 +422,7 @@ def main(): print("NOT DECODED:", not_decoded) with open(FIPS_RESULTS_DIR + 'broken_files.json', 'w') as f: - f.write(json.dumps(not_decoded)) + json.dump(not_decoded, f) print("REMOVING ALGORITHMS") remove_algorithms_from_extracted_data(items, html) @@ -431,7 +430,7 @@ def main(): print("VALIDATING RESULTS") validate_results(items, html) with open(FIPS_RESULTS_DIR + 'fips_html_all.json', 'w') as f: - f.write(json.dumps(html, indent=4, sort_keys=True)) + json.dump(html, f, indent=4, sort_keys=True) print("PLOTTING GRAPH") get_dot_graph(html, 'output') diff --git a/sec_certs/process_certificates.py b/sec_certs/process_certificates.py index 41f44247..ee5f35bb 100755 --- a/sec_certs/process_certificates.py +++ b/sec_certs/process_certificates.py @@ -214,15 +214,15 @@ def main(directory, do_complete_extraction, do_download_certs, do_extraction, do # save joined results with open("certificate_data_csv_all.json", "w") as write_file: - write_file.write(json.dumps(all_csv, indent=4, sort_keys=True)) + json.dump(all_csv, write_file, indent=4, sort_keys=True) with open("certificate_data_html_all.json", "w") as write_file: - write_file.write(json.dumps(all_html, indent=4, sort_keys=True)) + json.dump(all_html, write_file, indent=4, sort_keys=True) with open("certificate_data_frontpage_all.json", "w") as write_file: - write_file.write(json.dumps(all_front, indent=4, sort_keys=True)) + json.dump(all_front, write_file, indent=4, sort_keys=True) with open("certificate_data_keywords_all.json", "w") as write_file: - write_file.write(json.dumps(all_keywords, indent=4, sort_keys=True)) + json.dump(all_keywords, write_file, indent=4, sort_keys=True) with open("certificate_data_pdfmeta_all.json", "w") as write_file: - write_file.write(json.dumps(all_pdf_meta, indent=4, sort_keys=True)) + json.dump(all_pdf_meta, write_file, indent=4, sort_keys=True) # if do_extraction_pp: # all_pp_csv = extract_protectionprofiles_csv(cc_pp_web_files_dir) @@ -266,7 +266,7 @@ def main(directory, do_complete_extraction, do_download_certs, do_extraction, do # write collated result with open("certificate_data_complete.json", "w") as write_file: - write_file.write(json.dumps(all_cert_items, indent=4, sort_keys=True)) + json.dump(all_cert_items, write_file, indent=4, sort_keys=True) if do_processing: # load information about protection profiles as extracted by sec-certs-pp tool @@ -279,7 +279,7 @@ def main(directory, do_complete_extraction, do_download_certs, do_extraction, do all_cert_items = process_certificates_data(all_cert_items, all_pp_items) with open("certificate_data_complete_processed.json", "w") as write_file: - write_file.write(json.dumps(all_cert_items, indent=4, sort_keys=True)) + json.dump(all_cert_items, write_file, indent=4, sort_keys=True) if do_analysis: with open('certificate_data_complete_processed.json') as json_file: @@ -303,7 +303,7 @@ def main(directory, do_complete_extraction, do_download_certs, do_extraction, do do_analysis_everything(all_cert_items, results_folder) with open("certificate_data_complete_processed_analyzed.json", "w") as write_file: - write_file.write(json.dumps(all_cert_items, indent=4, sort_keys=True)) + json.dump(all_cert_items, write_file, indent=4, sort_keys=True) if __name__ == "__main__": |
