security_tools/tools/ubuntu_package_puller/export_to_json.py

32 lines
898 B
Python
Raw Normal View History

2022-08-17 01:52:44 -05:00
#!/usr/bin/env python3
# export job that will use existing class code to export to json
import json
from package_version_history import PackageVersionHistory as pvh
2022-08-17 03:00:09 -05:00
# start with just ubuntu 22.04
distro_version = '22.04'
2022-08-17 01:52:44 -05:00
2022-08-17 03:00:09 -05:00
source_pkgs_filepath = './package_data/ubuntu_22.04_source_packages.container'
2022-08-17 01:52:44 -05:00
source_file = open(source_pkgs_filepath, 'r')
lines = source_file.readlines()
results = []
for source_pkgname in lines:
pkg = source_pkgname.strip()
print(pkg)
name_and_versions = pvh(
pkg, distro_version).package_name_and_version_history()
results.append(name_and_versions)
print(name_and_versions)
# create json of the results
json_obj = json.dumps(results)
json_arr = json.loads(json_obj)
# write to a file
2022-08-17 03:00:09 -05:00
with open('./version_history_data/ubuntu_latest_source_package_version_history.container', 'w') as outfile:
2022-08-17 01:52:44 -05:00
json.dump(json_arr, outfile, indent=4)