1 #============================================================================ |
|
2 #Name : txt2sysdef.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 os.path |
|
23 import sys |
|
24 import shutil |
|
25 import string |
|
26 |
|
27 |
|
28 if __name__ == "__main__": |
|
29 argc = len(sys.argv) |
|
30 if argc >= 4 or argc < 2: |
|
31 print 'Simple tool for one-time converting txt-files to SystemDefinitions' |
|
32 print 'remeber to manually edit the outputs' |
|
33 print 'usage:', sys.argv[0], 'infile [outfile] ' |
|
34 sys.exit(1) |
|
35 |
|
36 |
|
37 filename = sys.argv[1] |
|
38 |
|
39 if argc == 3: |
|
40 filename2 = sys.argv[2] |
|
41 else: |
|
42 filename2, ext = os.path.splitext(filename) |
|
43 filename2 += ".xml" |
|
44 print "outfilename is %s" % filename2 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 file = open (filename,"r") |
|
50 global DATA |
|
51 DATA = file.readlines() |
|
52 |
|
53 try: |
|
54 shutil.copyfile("dtd.xml", filename2) |
|
55 except: |
|
56 pass |
|
57 |
|
58 outfile = open(filename2,"a") |
|
59 component = "" |
|
60 compname = "" |
|
61 bld_path = "" |
|
62 |
|
63 outfile.write('<SystemDefinition name="SystemModel" schema="1.4.0">\n') |
|
64 outfile.write(' <systemModel>\n') |
|
65 outfile.write('<layer name="%s">\n' % os.path.basename(filename)) |
|
66 |
|
67 |
|
68 #print DATA |
|
69 for line in DATA: |
|
70 # ignore outcommented lines in input |
|
71 if '#Components' in line: |
|
72 continue |
|
73 if 'Component' in line: |
|
74 try: |
|
75 # we are expecting lines "Component /path/to/named/group componentName" |
|
76 component, bldpath, comname = line.split() |
|
77 print ("prosessing component %s \n" % comname.strip()) |
|
78 outfile.write('<unit unitID="%s_%s" name="%s" bldFile="%s" mrp=""/> \n' % |
|
79 (os.path.basename(filename), comname.strip(), comname.strip(), bldpath.strip())) |
|
80 except: |
|
81 print ("Problems with Line:\n %s\n" % line) |
|
82 |
|
83 |
|
84 print "finishing" |
|
85 outfile.write('</component> \n') |
|
86 outfile.write('</module> \n') |
|
87 outfile.write(' </layer>\n') |
|
88 |
|
89 outfile.write(' </systemModel>\n') |
|
90 outfile.write('</SystemDefinition>\n') |
|
91 |
|
92 outfile.close() |
|