|
1 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 |
|
15 import sys, re |
|
16 |
|
17 if len(sys.argv) not in (2, 3): |
|
18 print "Expected 1 or 2 arguments: " |
|
19 print " <target_file> <revision> - Set revision to the supplied value" |
|
20 print " <target_file> - Set revision to ''" |
|
21 sys.exit(1) |
|
22 |
|
23 filename = sys.argv[1] |
|
24 |
|
25 if len(sys.argv) == 3: |
|
26 svnrevision = sys.argv[2] |
|
27 # Use the revision provided from command line only if it's valid |
|
28 if re.match('^[0-9]+(:[0-9]+)?M?S?$', svnrevision) is None: |
|
29 svnrevision = '' |
|
30 else: |
|
31 svnrevision = '' |
|
32 |
|
33 f = open(filename, "rt") |
|
34 lines = f.readlines() |
|
35 f.close() |
|
36 |
|
37 # Replace the line with the svn revision variable |
|
38 replaced = False |
|
39 for i, line in enumerate(lines): |
|
40 if line.startswith('_svnrevision = "'): |
|
41 lines[i] = '_svnrevision = "%s"' % svnrevision |
|
42 replaced = True |
|
43 else: |
|
44 lines[i] = line.rstrip('\r\n') |
|
45 |
|
46 if replaced: |
|
47 f = open(filename, "wt") |
|
48 for line in lines: |
|
49 print >>f, line |
|
50 f.close() |
|
51 print "Revision updated to '%s'" % svnrevision |
|
52 else: |
|
53 print "Revision not updated: _svnrevision not found" |