|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 import socket, sys, os |
|
18 import traceback |
|
19 |
|
20 def main(): |
|
21 try: |
|
22 # Assuming key-value pairs like key=value |
|
23 inputFile = sys.argv[1] |
|
24 outputFile = sys.argv[2] |
|
25 |
|
26 values = {} |
|
27 |
|
28 for pair in sys.argv[3:]: |
|
29 key, value = pair.split("=", 1) |
|
30 values[key] = value |
|
31 |
|
32 replaceInFile(inputFile, outputFile, values) |
|
33 |
|
34 except: |
|
35 print "Usage: %s inputFile outputFile <key=value> ..." % sys.argv[0] |
|
36 print "Replaces all occurrences of <key> with <value> <file>" |
|
37 traceback.print_exc() |
|
38 sys.exit(1) |
|
39 |
|
40 |
|
41 def replaceInFile(srcFile, dstFile, values={}): |
|
42 # Binary mode => no line feed conversions |
|
43 f = open(srcFile, "rb") |
|
44 data = f.read() |
|
45 f.close() |
|
46 |
|
47 for key, value in values.items(): |
|
48 data = data.replace("${%s}" % key, value) |
|
49 |
|
50 # Binary mode => no line feed conversions |
|
51 f = open(dstFile, "wb") |
|
52 f.write(data) |
|
53 f.close() |
|
54 |
|
55 |
|
56 if __name__ == "__main__": |
|
57 main() |