GenFds Tool: Add FdfClassObject.
[people/mcb30/basetools.git] / Source / Python / GenFds / GuidSection.py
1 import Section\r
2 import subprocess\r
3 from Ffs import Ffs\r
4 import os\r
5 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
6 from CommonDataClass.FdfClassObject import GuidSectionClassObject\r
7 from Common import ToolDefClassObject\r
8 \r
9 class GuidSection(GuidSectionClassObject) :\r
10     \r
11     def __init__(self):\r
12 ##        self.Alignment = None\r
13 ##        self.NameGuid = None\r
14 ##        self.SectionList = []\r
15 ##        self.SectionType = None\r
16 ##        self.ProcessRequired = False\r
17 ##        self.AuthStatusValid = False\r
18         GuidSectionClassObject.__init__(self)\r
19         \r
20     def GenSection(self, OutputPath, ModuleName , KeyStringList, FfsInf = None):\r
21         #\r
22         # Generate all section\r
23         #\r
24         self.keyStringList = KeyStringList\r
25         \r
26         if FfsInf != None:\r
27             self.Alignment = FfsInf.__ExtendMarco__(self.Alignment)\r
28             self.NameGuid = FfsInf.__ExtendMarco__(self.NameGuid)\r
29             self.SectionType = FfsInf.__ExtendMarco__(self.SectionType)\r
30             \r
31         SectFile = ''\r
32         for Sect in self.SectionList:\r
33             sect, align = Sect.GenSection(OutputPath, ModuleName, KeyStringList,FfsInf)\r
34             if sect != None:\r
35                 SectFile = SectFile + \\r
36                            '  '     + \\r
37                            sect\r
38                        \r
39 \r
40         OutputFile = OutputPath + \\r
41                      os.sep     + \\r
42                      ModuleName + \\r
43                      Ffs.SectionSuffix['GUIDED']\r
44         OutputFile = os.path.normpath(OutputFile)\r
45         \r
46         ExternalTool = self.__FindExtendTool__()\r
47         #\r
48         # If not have GUID or GUID not in External Tool List, call default\r
49         # GENCRC32 section\r
50         #\r
51         if self.NameGuid == None or ExternalTool == None :\r
52             print "Use GenSection function Generate CRC32 Section"\r
53             GenSectionCmd = 'GenSec -o '                                   + \\r
54                              OutputFile                                    + \\r
55                              ' -s '                                        + \\r
56                              Section.Section.SectionType[self.SectionType] + \\r
57                              SectFile\r
58                              \r
59             print GenSectionCmd\r
60             GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
61             return OutputFile, self.Alignment\r
62         else:\r
63             #\r
64             # Call GenSection with DUMMY section type.\r
65             #\r
66             GenSectionCmd = 'GenSec -o '                                   + \\r
67                              OutputFile                                    + \\r
68                              SectFile\r
69         \r
70             print GenSectionCmd\r
71             GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
72             #\r
73             # Use external tool process the Output\r
74             #\r
75             InputFile = OutputFile\r
76             TempFile = OutputPath + \\r
77                        os.sep     + \\r
78                        ModuleName + \\r
79                        '.tmp'\r
80             TempFile = os.path.normpath(TempFile)\r
81             \r
82             ExternalToolCmd = ExternalTool                             + \\r
83                               ' -e '                                   + \\r
84                               ' -o '                                   + \\r
85                               TempFile                                 + \\r
86                               ' '                                      + \\r
87                               InputFile\r
88 \r
89             #\r
90             # Call external tool\r
91             #\r
92             print ExternalToolCmd\r
93             GenFdsGlobalVariable.CallExternalTool(ExternalToolCmd, "Gensec Failed!")\r
94             #\r
95             # Call Gensection Add Secntion Header\r
96             #\r
97             PROCSSING_REQUIRED = ''\r
98             AUTH_STATUS_VALID = ''\r
99             if self.ProcessRequired == True:\r
100                 PROCSSING_REQUIRED = "PROCSSING_REQUIRED"\r
101             if self.AuthStatusValid == True:\r
102                 AUTH_STATUS_VALID = "AUTH_STATUS_VALID"\r
103             if PROCSSING_REQUIRED != '' or AUTH_STATUS_VALID != '':\r
104                 attribute = ' -a '              + \\r
105                              PROCSSING_REQUIRED + \\r
106                              AUTH_STATUS_VALID\r
107             else :\r
108                 attribute = ''\r
109             GenSectionCmd = 'GenSec -o '                            + \\r
110                              OutputFile                             + \\r
111                              ' -s '                                 + \\r
112                              Section.Section.SectionType['GUIDED']  + \\r
113                              ' -g '                                 + \\r
114                              self.NameGuid                          + \\r
115                              attribute                              + \\r
116                              ' '                                    + \\r
117                              TempFile\r
118                         \r
119             print GenSectionCmd\r
120             GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
121             \r
122             return OutputFile, self.Alignment\r
123         \r
124     def __FindExtendTool__(self):\r
125         tool = None\r
126         if self.keyStringList == None or self.keyStringList == []:\r
127             return tool\r
128         toolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.WorkSpaceDir).ToolsDefTxtDictionary\r
129         for toolDef in toolDefinition.items():\r
130             if self.NameGuid == toolDef[1]:\r
131                 keyList = toolDef[0].split('_')\r
132                 key = keyList[0] + \\r
133                       '_'        + \\r
134                       keyList[1] + \\r
135                       '_'        + \\r
136                       keyList[2]\r
137                 if key in self.keyStringList and keyList[4] == 'GUID':\r
138                     toolMaro = keyList[3]\r
139                     toolName = toolDefinition.get( key        + \\r
140                                                    '_'        + \\r
141                                                    keyList[3] + \\r
142                                                    '_'        + \\r
143                                                    'NAME')\r
144                     toolPath = toolDefinition.get( key        + \\r
145                                                    '_'        + \\r
146                                                    keyList[3] + \\r
147                                                    '_'        + \\r
148                                                    'PATH')\r
149                     tool = os.path.join (toolPath, toolName)\r
150                     return tool\r
151         return tool\r
152 \r
153 \r
154                 \r