|
1 #!/usr/bin/python |
|
2 # |
|
3 # Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 # All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Nokia Corporation - initial contribution. |
|
12 # |
|
13 # Contributors: |
|
14 # |
|
15 # Description: |
|
16 # |
|
17 # Script for parsing TeleLogic Change ids and svn revisions from svn log. |
|
18 # |
|
19 |
|
20 import os, re, sys, traceback |
|
21 from optparse import OptionParser |
|
22 |
|
23 def main(): |
|
24 parser = OptionParser( |
|
25 usage = "python -u %prog [options] <svn_url> <svn_rev_1> <svn_rev_2>") |
|
26 parser.add_option("-r", "--release", dest="release", |
|
27 help="release to which the change is targeted, e.g. 92 or mcl") |
|
28 (opts, args) = parser.parse_args() |
|
29 svn_url = args[0] |
|
30 svn_rev_1 = args[1] |
|
31 svn_rev_2 = args[2] |
|
32 if len(args) > 3: |
|
33 print "ERROR: Too many arguments" |
|
34 sys.exit(1) |
|
35 |
|
36 try: |
|
37 svn_change_ids = get_svn_change_ids(opts.release, svn_url, svn_rev_1, svn_rev_2) |
|
38 change_ids = svn_change_ids.keys() |
|
39 change_ids.sort() |
|
40 for change_id in change_ids: |
|
41 print "%s %s" % (change_id, ",".join(svn_change_ids[change_id])) |
|
42 except: |
|
43 print "ERROR: Unexpected exception" |
|
44 traceback.print_exc() |
|
45 sys.exit(1) |
|
46 |
|
47 def get_svn_change_ids(release, url, rev_1, rev_2): |
|
48 """Return svn change id dictionary. |
|
49 |
|
50 Returns a dictionary where keys are change ids and values |
|
51 are list of svn revisions where the change is made. |
|
52 """ |
|
53 |
|
54 change_id_keyword = "changeid\s*" # Matches to change ids with no release. |
|
55 if not release is None: |
|
56 # Matches to change ids for given release only. |
|
57 change_id_keyword = "changeid[_-]?" + release + "\s*" |
|
58 re_rev = re.compile("^r(\d+) \| ", re.I | re.M) |
|
59 re_change_id = re.compile("(\w+\#\d+)\s*,?", re.I | re.M) |
|
60 re_change_id_keyword = re.compile(change_id_keyword + "[:=]?\s*(\w+\#\d+)", |
|
61 re.I | re.M) |
|
62 svn_change_ids = {} |
|
63 cmd = "svn log -r " + rev_2 + ":" + rev_1 + " " + url |
|
64 #print cmd |
|
65 for line in os.popen(cmd).readlines(): |
|
66 rev = re_rev.findall(line) |
|
67 if rev: |
|
68 current_rev = rev[0] |
|
69 change_ids = re_change_id_keyword.findall(line) |
|
70 while change_ids: |
|
71 for change_id in change_ids: |
|
72 if change_id in svn_change_ids: |
|
73 if not current_rev in svn_change_ids[change_id]: |
|
74 svn_change_ids[change_id] += [current_rev] |
|
75 else: |
|
76 svn_change_ids[change_id] = [current_rev] |
|
77 line = re_change_id.sub("", line, 1) |
|
78 change_ids = re_change_id_keyword.findall(line) |
|
79 return svn_change_ids |
|
80 |
|
81 if __name__ == "__main__": |
|
82 main() |