|
1 #============================================================================ |
|
2 #Name : ini2sysdef.py |
|
3 #Part of : Helium |
|
4 |
|
5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 #All rights reserved. |
|
7 #This component and the accompanying materials are made available |
|
8 #under the terms of the License "Eclipse Public License v1.0" |
|
9 #which accompanies this distribution, and is available |
|
10 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 #Initial Contributors: |
|
13 #Nokia Corporation - initial contribution. |
|
14 # |
|
15 #Contributors: |
|
16 # |
|
17 #Description: |
|
18 #=============================================================================== |
|
19 |
|
20 |
|
21 import os |
|
22 import sys |
|
23 import shutil |
|
24 import string |
|
25 |
|
26 |
|
27 if __name__ == "__main__": |
|
28 argc = len(sys.argv) |
|
29 if argc >= 4 or argc < 2: |
|
30 print 'Simple tool for one-time converting ini-files to SystemDefinitions' |
|
31 print 'remeber to manually edit the outputs' |
|
32 print 'usage:', sys.argv[0], 'infile [outfile] ' |
|
33 sys.exit(1) |
|
34 |
|
35 |
|
36 filename = sys.argv[1] |
|
37 ## r"C:\USERS\work\systemdefinitionXML\spp_config\build\spp_convcom.ini" |
|
38 if argc == 3: |
|
39 filename2 = sys.argv[2] |
|
40 else: |
|
41 filename2, ext = os.path.splitext(filename) |
|
42 filename2 += ".xml" |
|
43 print "outfilename is %s" % filename2 |
|
44 |
|
45 |
|
46 |
|
47 ##r"C:\USERS\work\systemdefinitionXML\spp_config\build\spp_convcom.xml" |
|
48 #filename = "logparse_rules.txt" |
|
49 |
|
50 file = open (filename,"r") |
|
51 global DATA |
|
52 DATA = file.readlines() |
|
53 |
|
54 try: |
|
55 shutil.copyfile("spp_dtd.xml", filename2) |
|
56 except: |
|
57 pass |
|
58 |
|
59 outfile = open(filename2,"a") |
|
60 component = "" |
|
61 compname = "" |
|
62 bld_path = "" |
|
63 |
|
64 outfile.write('<SystemDefinition name="spp_SystemModel" schema="1.4.0">\n') |
|
65 outfile.write(' <systemModel>\n') |
|
66 outfile.write('<layer name="%s">\n' % filename) |
|
67 outfile.write(' <logicalset name="%s">\n' % filename) |
|
68 |
|
69 |
|
70 #print DATA |
|
71 for line in DATA: |
|
72 if '[' in line: |
|
73 if not component == "": |
|
74 #the first one |
|
75 outfile.write('</component> \n') |
|
76 outfile.write('</module> \n') |
|
77 component = line.split('[')[1].split(']')[0] |
|
78 print "we have component here : ", component |
|
79 |
|
80 outfile.write('<module name="%s"> \n' % component.strip()) |
|
81 if "name" in line: |
|
82 compname = line.split('=')[1] |
|
83 # print "we have name here : ", compname |
|
84 outfile.write('<component name="%s"> \n' % compname.strip()) |
|
85 if "bld_path" in line: |
|
86 bldpath = line.split('=')[1] |
|
87 bldpath = bldpath.strip() |
|
88 bldpath = bldpath.strip('\\') |
|
89 bldpath = bldpath.replace('<', '') |
|
90 bldpath = bldpath.replace('>', '') |
|
91 |
|
92 |
|
93 |
|
94 # print "we have path here : ", bldpath |
|
95 outfile.write('<unit unitID="%s_%s" name="%s" bldFile="%s" mrp=""/> \n' % |
|
96 (os.path.basename(filename), component.strip(), compname.strip(), bldpath.strip())) |
|
97 |
|
98 |
|
99 |
|
100 print "finishing" |
|
101 outfile.write('</component> \n') |
|
102 outfile.write('</module> \n') |
|
103 outfile.write(' </logicalset>\n') |
|
104 outfile.write(' </layer>\n') |
|
105 |
|
106 outfile.write(' </systemModel>\n') |
|
107 outfile.write('</SystemDefinition>\n') |
|
108 |
|
109 |
|
110 |
|
111 outfile.close() |