author | Sebastian Brannstrom <sebastianb@symbian.org> |
Fri, 04 Dec 2009 10:06:14 +0000 | |
changeset 18 | e2c612a7088c |
parent 13 | 32a0da1099d8 |
permissions | -rw-r--r-- |
13
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
1 |
# compare_baselines.py takes two lists of baselines produced by find_public_apis.pl |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
2 |
# and compares them for added, removed and moved headers as well as api class change |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
3 |
# |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
4 |
# outputs report as csv |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
5 |
# |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
6 |
# usage: python compare_baselines.py <baseline1> <baseline2> |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
7 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
8 |
import sys |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
9 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
10 |
# parse a baseline file produced by find_public_apis.pl into a map |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
11 |
def parse_baseline(filename): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
12 |
file = open(filename) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
13 |
count = 0 |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
14 |
db = {} |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
15 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
16 |
for line in file: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
17 |
if count > 0: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
18 |
tokens = line.split() |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
19 |
pathname = tokens[0].strip().lower() # watch out for lowecasing here! |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
20 |
apiclass = tokens[1].strip() |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
21 |
apiclassreason = tokens[2].strip() |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
22 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
23 |
dbentry = {'pathname': pathname, 'class': apiclass, 'reason': apiclassreason, 'duplicate':''} |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
24 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
25 |
filename = strip_path(pathname) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
26 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
27 |
if db.has_key(filename): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
28 |
db[filename]['duplicate'] = pathname |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
29 |
# print >> sys.stderr, 'duplicate filename at paths %s and %s' % (pathname, db[filename]['pathname']) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
30 |
else: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
31 |
db[filename] = dbentry |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
32 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
33 |
count = count + 1 |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
34 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
35 |
return db |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
36 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
37 |
# strip pathnames from filenames |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
38 |
def strip_path(pathname): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
39 |
while pathname.find('/') != -1: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
40 |
x=pathname.find('/') |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
41 |
pathname = pathname[x+1:] |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
42 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
43 |
return pathname.lower() |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
44 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
45 |
def compare_dbs(db1, db2): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
46 |
print 'apiname,status,classchange,class1,class2,pathname1,pathname2,duplicate1,duplicate2' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
47 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
48 |
for key in db1.keys(): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
49 |
db1entry = db1[key] |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
50 |
status = 'ok' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
51 |
if db2.has_key(key): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
52 |
db2entry = db2[key] |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
53 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
54 |
# filename exists, does path match? |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
55 |
if db1entry['pathname'] != db2entry['pathname']: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
56 |
status = 'moved' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
57 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
58 |
# does class match? |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
59 |
if db1entry['class'] != db2entry['class']: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
60 |
classchange = 'yes' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
61 |
else: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
62 |
classchange = 'no' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
63 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
64 |
print '%s,%s,%s,%s,%s,%s,%s,%s,%s' % (key, status, classchange,db1entry['class'],db2entry['class'],db1entry['pathname'], db2entry['pathname'],db1entry['duplicate'],db2entry['duplicate']) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
65 |
else: |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
66 |
status = 'removed' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
67 |
print '%s,%s,%s,%s,%s,%s,%s,%s,%s' % (key, status, 'no',db1entry['class'],'',db1entry['pathname'], '',db1entry['duplicate'],'') |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
68 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
69 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
70 |
for key in db2.keys(): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
71 |
if not db1.has_key(key): |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
72 |
db2entry = db2[key] |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
73 |
status = 'added' |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
74 |
print '%s,%s,%s,%s,%s,%s,%s,%s,%s' % (key, status, 'no','',db2entry['class'],'',db2entry['pathname'], '',db2entry['duplicate']) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
75 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
76 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
77 |
# handle duplicates |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
78 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
79 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
80 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
81 |
# read the list of published filenames |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
82 |
bl1name = sys.argv[1] |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
83 |
bl2name = sys.argv[2] |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
84 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
85 |
db1 = parse_baseline(bl1name) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
86 |
db2 = parse_baseline(bl2name) |
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
87 |
|
32a0da1099d8
Added my new compare_header_lists.py script
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff
changeset
|
88 |
compare_dbs(db1, db2) |