-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-decoder.py
More file actions
executable file
·52 lines (48 loc) · 1.4 KB
/
json-decoder.py
File metadata and controls
executable file
·52 lines (48 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python2.7
from __future__ import print_function
import sys
import json
def print_key(k1,k2):
return str("%s:%s" %(k1,k2))
def main():
try:
f = sys.argv[1]
except IndexError:
print("Missing command line argument - file name")
return 1
try:
with open(f, 'r') as jsonfile:
data = json.load(jsonfile)
except IOError, err:
print("Missing command line argument - file name")
return 1
# filter out duplicates in this loop
# to avoid duplicates pkg_name:cve save seen values
seen = dict()
for pkg_name in data:
#print("DEBUG: %s: %s\n" %(pkg_name, data[pkg_name]))
cve = data[pkg_name]
for c in cve:
#print("DEBUG: %s: %s\n" % (c, cve[c]))
keys = cve[c]
for k in keys:
#print("DEBUG: %s: %s\n" % (k, keys[k]))
#only 'jessie' records are taken
if 'jessie' in keys['releases']:
# to avoid duplicates - save current pkg_name:cve
key_new = print_key(pkg_name,c)
if key_new in seen:
#if combination okg_name:cve has been seen - do not duplicate it
continue
# add new unique key
seen[key_new] = 1
if 'description' in keys:
seen[key_new] = str("%s: %s: %s\n" %(pkg_name, c, keys['description']))
else:
seen[key_new] = str("%s: %s: No description\n" %(pkg_name, c))
#for k in seen:
# print("DEBUG: %s : %s" % (k, seen[k]))
if seen:
for k in sorted(seen):
print("%s" %(seen[k]))
if __name__ == '__main__': main()