GenFds Tool: Add FdfClassObject.
[people/mcb30/basetools.git] / Source / Python / GenFds / VerSection.py
1 from Ffs import Ffs\r
2 import Section\r
3 import os\r
4 import subprocess\r
5 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
6 from CommonDataClass.FdfClassObject import VerSectionClassObject\r
7 \r
8 class VerSection (VerSectionClassObject):\r
9     def __init__(self):\r
10 ##        self.Alignment = None\r
11 ##        self.BuildNum = None\r
12 ##        self.StringData = None\r
13 ##        self.FileName = None\r
14         VerSectionClassObject.__init__(self)\r
15         \r
16     def GenSection(self,OutputPath, ModuleName, KeyStringList, FfsInf = None):\r
17         #\r
18         # Prepare the parameter of GenSection\r
19         #\r
20         if FfsInf != None:\r
21             self.Alignment = FfsInf.__ExtendMarco__(self.Alignment)\r
22             self.BuildNum = FfsInf.__ExtendMarco__(self.BuildNum)\r
23             self.StringData = FfsInf.__ExtendMarco__(self.StringData)\r
24             self.FileName = FfsInf.__ExtendMarco__(self.FileName)\r
25             \r
26         OutputFile = os.path.join(OutputPath,\r
27                                   ModuleName+Ffs.SectionSuffix.get('VERSION'))\r
28         OutputFile = os.path.normpath(OutputFile)\r
29         \r
30         """Get Build Num """\r
31         BuildNum = ''\r
32         if not (self.BuildNum == None) :\r
33             BuildNum = ' -j ' + '%d' %self.BuildNum;\r
34  \r
35         """Get String Data"""\r
36         StringData = ''\r
37         if self.StringData != None:\r
38              StringData = self.StringData\r
39         elif self.FileName != None:\r
40             f = open (self.FileName, 'r')\r
41             StringData = f.read()\r
42             f.close()\r
43         else:\r
44             StringData = ''\r
45             \r
46         GenSectionCmd = 'GenSec -o '                + \\r
47                          OutputFile                 + \\r
48                          ' -s EFI_SECTION_VERSION ' + \\r
49                          '-n '                      + \\r
50                          '\"'                       + \\r
51                          StringData                 + \\r
52                          '\"'                       + \\r
53                          BuildNum                   \r
54                          \r
55         #\r
56         # Call GenSection\r
57         #\r
58         print GenSectionCmd\r
59         GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "Gensection Failed!")\r
60         return OutputFile, self.Alignment\r