debian_pkgs/osv_parse.py
2024-06-17 12:19:46 +02:00

51 lines
1.3 KiB
Python

import argparse
import json
import logging
import os
logging.basicConfig()
logger = logging.getLogger()
OSV_DIR = 'osv'
DATA_DIR = 'data'
def setup_logging_level(debug=False):
log_level = logging.DEBUG if debug else logging.ERROR
logger.setLevel(log_level)
logger.debug("Debugging enabled")
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('query', nargs='*', default="", help="freeform")
parser.add_argument('--debug', dest='debug', action='store_true')
return parser.parse_args()
def main():
args = parse_args()
setup_logging_level(args.debug)
print(' '.join(args.query))
osv_aliases = {}
for file in os.listdir(OSV_DIR):
if not file.endswith('.json'):
continue
with open(os.path.join(OSV_DIR, file)) as f:
try:
jdata = json.load(f)
except Exception as e:
logger.error("ERROR READING: {}".format(e))
continue
id_ = jdata.get('id', '')
if not (id_.startswith('GHSA-') or id_.startswith('PYSEC-')):
continue
aliases = jdata.get('aliases', [])
osv_aliases[id_] = aliases
with open(os.path.join(DATA_DIR, 'osv_aliases.json'), 'w+') as f:
json.dump(osv_aliases, f, indent=2)
if __name__ == "__main__":
main()