tofrodos-native: created
[openembedded.git] / contrib / oeaudit / oe_audit.py
blobe57bfdfda3723c70fa6846c2922bba6a0a17aeeb
1 #!/usr/bin/env python
3 import freebsd, oe
5 try:
6 import bb
7 except Exception, e:
8 import sys
9 sys.stderr.write("Set PYTHONPATH to bitbake/lib and restart.\n")
10 sys.stderr.write("The backtrace can be seen below.\n")
11 raise e
14 def strip_oe_version(oe_version):
15 """
16 We need to strip the package epoch... and the PR to compare
17 it to the FreeBSD versions. Also FreeBSD seems to use _N as
18 PR so we might need to do more..
19 """
20 split = oe_version.split(':', 1)
21 ver = split[1]
23 split = ver.rsplit('-r', 1)
24 ver = split[0]
25 return ver
27 def compare_versions(oe, freebsd_dict, not_known):
28 def handle_package(oe_name, bsd_name):
29 if not oe_name in oe:
30 if oe_name == bsd_name:
31 print >> not_known, "%s is not in OE" % oe_name
32 return
34 oe_version = strip_oe_version(oe[oe_name])
35 for ver in freebsd_dict[bsd_name]:
36 affected = True
37 str = []
38 for (cmp, vers) in ver.versions:
39 (bsd_ver, bsd_pr) = freebsd.prepare_version(vers)
40 cmp_res = bb.utils.vercmp(('0', oe_version, 'r0'), ('0', bsd_ver, bsd_pr))
41 if cmp == '<':
42 if cmp_res >= 0:
43 affected = False
44 pass
45 elif cmp == '<=':
46 if cmp_res > 0:
47 affected = False
48 pass
49 elif cmp == '>':
50 if cmp_res <= 0:
51 affected = False
52 pass
53 elif cmp == '>=':
54 if cmp_res < 0:
55 affected = False
56 pass
57 elif cmp == '=':
58 if cmp_res > 0:
59 affected = False
60 else:
61 print cmp
62 assert True
64 str.append("%s %s %s %s" % (oe_name, oe_version, cmp, bsd_ver))
65 if affected:
66 print " && ".join(str), ver.link
68 for package in freebsd_dict.keys():
69 # handle the various versions of OE packages
70 handle_package(package, package)
71 handle_package("%s-native" % package, package)
72 handle_package("%s-full-native" % package, package)
73 handle_package("%s-sdk" % package, package)
74 handle_package("%s-essential" % package, package)
75 handle_package("%s-cross" % package, package)
76 handle_package("%s-initial" % package, package)
77 handle_package("%s-trim" % package, package)
78 handle_package("%s-canadian" % package, package)
79 handle_package("%s-cross-sdk" % package, package)
81 def handle_options(args):
82 import optparse
83 parser = optparse.OptionParser(version = "OE Audit version 0.1",
84 usage = "%prog [options]")
85 parser.add_option("-a", "--auditfile", help = "FreeBSD auditfile to use",
86 action = "store", dest = "freebsd_auditfile", default = None)
87 parser.add_option("-p", "--available", help = "Output of bitbake -s",
88 action = "store", dest = "oe_available", default = None)
89 parser.add_option("-b", "--buggy", help = "Write out unmaped packets",
90 action = "store", dest = "buggy", default = "not_in_oe.bugs")
91 parser.add_option("-f", "--fetch", help = "Fetch a new auditfile",
92 action = "store_true", dest = "fetch", default = False)
94 options, args = parser.parse_args(args)
95 return options
97 # read the input data
98 import sys
99 opts = handle_options(sys.argv)
101 if opts.fetch:
102 import os
103 print "Fetching new auditfile with wget and unpacking to the local directory"
104 os.system("(rm auditfile.tbz || true) && wget -c http://ports.freebsd.org/auditfile.tbz; tar xjf auditfile.tbz auditfile && rm auditfile.tbz")
106 if not opts.oe_available or not opts.freebsd_auditfile:
107 print "You need to specific -a and -p."
108 sys.exit(0)
110 oe_packages = oe.read_available(opts.oe_available)
111 freebsd_vuln = freebsd.read_auditfile(opts.freebsd_auditfile)
112 buggy = open(opts.buggy, "w+")
114 compare_versions(oe=oe_packages, freebsd_dict=freebsd_vuln, not_known=buggy)