Home | History | Annotate | Download | only in MetaFileWorkspace
      1 ## @file

      2 # This file is used to create/update/query/erase a meta file table

      3 #

      4 # Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>

      5 # This program and the accompanying materials

      6 # are licensed and made available under the terms and conditions of the BSD License

      7 # which accompanies this distribution.  The full text of the license may be found at

      8 # http://opensource.org/licenses/bsd-license.php

      9 #

     10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

     11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

     12 #

     13 
     14 ##

     15 # Import Modules

     16 #

     17 import uuid
     18 
     19 import Common.EdkLogger as EdkLogger
     20 import EccGlobalData
     21 
     22 from MetaDataTable import Table
     23 from MetaDataTable import ConvertToSqlString
     24 from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \
     25                                       MODEL_FILE_OTHERS
     26 
     27 class MetaFileTable(Table):
     28     ## Constructor 

     29     def __init__(self, Cursor, MetaFile, FileType, TableName, Temporary = False):
     30         self.MetaFile = MetaFile
     31         self.TblFile = EccGlobalData.gDb.TblFile
     32         if (FileType == MODEL_FILE_INF):
     33             TableName = "Inf"
     34         if (FileType == MODEL_FILE_DSC):
     35             if Temporary:
     36                 TableName = "_%s_%s" % ("Dsc", uuid.uuid4().hex)
     37             else:
     38                 TableName = "Dsc"
     39         if (FileType == MODEL_FILE_DEC):
     40             TableName = "Dec"
     41 
     42         Table.__init__(self, Cursor, TableName, 0, Temporary)
     43         self.Create(False)
     44 
     45 
     46 ## Python class representation of table storing module data

     47 class ModuleTable(MetaFileTable):
     48     _COLUMN_ = '''
     49         ID REAL PRIMARY KEY,
     50         Model INTEGER NOT NULL,
     51         Value1 TEXT NOT NULL,
     52         Value2 TEXT,
     53         Value3 TEXT,
     54         Usage  TEXT,
     55         Scope1 TEXT,
     56         Scope2 TEXT,
     57         BelongsToItem REAL NOT NULL,
     58         BelongsToFile SINGLE NOT NULL,
     59         StartLine INTEGER NOT NULL,
     60         StartColumn INTEGER NOT NULL,
     61         EndLine INTEGER NOT NULL,
     62         EndColumn INTEGER NOT NULL,
     63         Enabled INTEGER DEFAULT 0
     64         '''
     65     # used as table end flag, in case the changes to database is not committed to db file

     66     _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
     67 
     68     ## Constructor

     69     def __init__(self, Cursor):
     70         MetaFileTable.__init__(self, Cursor, '', MODEL_FILE_INF, "Inf", False)
     71 
     72     ## Insert a record into table Inf

     73     #

     74     # @param Model:          Model of a Inf item

     75     # @param Value1:         Value1 of a Inf item

     76     # @param Value2:         Value2 of a Inf item

     77     # @param Value3:         Value3 of a Inf item

     78     # @param Scope1:         Arch of a Inf item

     79     # @param Scope2          Platform os a Inf item

     80     # @param BelongsToItem:  The item belongs to which another item

     81     # @param StartLine:      StartLine of a Inf item

     82     # @param StartColumn:    StartColumn of a Inf item

     83     # @param EndLine:        EndLine of a Inf item

     84     # @param EndColumn:      EndColumn of a Inf item

     85     # @param Enabled:        If this item enabled

     86     #

     87     def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',
     88                BelongsToItem=-1, BelongsToFile = -1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0, Usage=''):
     89         (Value1, Value2, Value3, Usage, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Usage, Scope1, Scope2))
     90         return Table.Insert(
     91                         self, 
     92                         Model, 
     93                         Value1, 
     94                         Value2, 
     95                         Value3, 
     96                         Usage,                         
     97                         Scope1, 
     98                         Scope2,
     99                         BelongsToItem,
    100                         BelongsToFile, 
    101                         StartLine, 
    102                         StartColumn, 
    103                         EndLine, 
    104                         EndColumn, 
    105                         Enabled
    106                         )
    107 
    108     ## Query table

    109     #

    110     # @param    Model:      The Model of Record 

    111     # @param    Arch:       The Arch attribute of Record 

    112     # @param    Platform    The Platform attribute of Record 

    113     #

    114     # @retval:       A recordSet of all found records 

    115     #

    116     def Query(self, Model, Arch=None, Platform=None):
    117         ConditionString = "Model=%s AND Enabled>=0" % Model
    118         ValueString = "Value1,Value2,Value3,Usage,Scope1,Scope2,ID,StartLine"
    119 
    120         if Arch != None and Arch != 'COMMON':
    121             ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
    122         if Platform != None and Platform != 'COMMON':
    123             ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform
    124 
    125         SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
    126         return self.Exec(SqlCommand)
    127 
    128 ## Python class representation of table storing package data

    129 class PackageTable(MetaFileTable):
    130     _COLUMN_ = '''
    131         ID REAL PRIMARY KEY,
    132         Model INTEGER NOT NULL,
    133         Value1 TEXT NOT NULL,
    134         Value2 TEXT,
    135         Value3 TEXT,
    136         Scope1 TEXT,
    137         Scope2 TEXT,
    138         BelongsToItem REAL NOT NULL,
    139         BelongsToFile SINGLE NOT NULL,
    140         StartLine INTEGER NOT NULL,
    141         StartColumn INTEGER NOT NULL,
    142         EndLine INTEGER NOT NULL,
    143         EndColumn INTEGER NOT NULL,
    144         Enabled INTEGER DEFAULT 0
    145         '''
    146     # used as table end flag, in case the changes to database is not committed to db file

    147     _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
    148 
    149     ## Constructor

    150     def __init__(self, Cursor):
    151         MetaFileTable.__init__(self, Cursor, '', MODEL_FILE_DEC, "Dec", False)
    152 
    153     ## Insert table

    154     #

    155     # Insert a record into table Dec

    156     #

    157     # @param Model:          Model of a Dec item

    158     # @param Value1:         Value1 of a Dec item

    159     # @param Value2:         Value2 of a Dec item

    160     # @param Value3:         Value3 of a Dec item

    161     # @param Scope1:         Arch of a Dec item

    162     # @param Scope2:         Module type of a Dec item

    163     # @param BelongsToItem:  The item belongs to which another item

    164     # @param StartLine:      StartLine of a Dec item

    165     # @param StartColumn:    StartColumn of a Dec item

    166     # @param EndLine:        EndLine of a Dec item

    167     # @param EndColumn:      EndColumn of a Dec item

    168     # @param Enabled:        If this item enabled

    169     #

    170     def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',
    171                BelongsToItem=-1, BelongsToFile = -1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):
    172         (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))
    173         return Table.Insert(
    174                         self, 
    175                         Model, 
    176                         Value1, 
    177                         Value2, 
    178                         Value3, 
    179                         Scope1, 
    180                         Scope2,
    181                         BelongsToItem,
    182                         BelongsToFile, 
    183                         StartLine, 
    184                         StartColumn, 
    185                         EndLine, 
    186                         EndColumn, 
    187                         Enabled
    188                         )
    189 
    190     ## Query table

    191     #

    192     # @param    Model:  The Model of Record 

    193     # @param    Arch:   The Arch attribute of Record 

    194     #

    195     # @retval:       A recordSet of all found records 

    196     #

    197     def Query(self, Model, Arch=None):
    198         ConditionString = "Model=%s AND Enabled>=0" % Model
    199         ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine"
    200 
    201         if Arch != None and Arch != 'COMMON':
    202             ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
    203 
    204         SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
    205         return self.Exec(SqlCommand)
    206 
    207 ## Python class representation of table storing platform data

    208 class PlatformTable(MetaFileTable):
    209     _COLUMN_ = '''
    210         ID REAL PRIMARY KEY,
    211         Model INTEGER NOT NULL,
    212         Value1 TEXT NOT NULL,
    213         Value2 TEXT,
    214         Value3 TEXT,
    215         Scope1 TEXT,
    216         Scope2 TEXT,
    217         BelongsToItem REAL NOT NULL,
    218         BelongsToFile SINGLE NOT NULL,
    219         FromItem REAL NOT NULL,
    220         StartLine INTEGER NOT NULL,
    221         StartColumn INTEGER NOT NULL,
    222         EndLine INTEGER NOT NULL,
    223         EndColumn INTEGER NOT NULL,
    224         Enabled INTEGER DEFAULT 0
    225         '''
    226     # used as table end flag, in case the changes to database is not committed to db file

    227     _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1, -1"
    228 
    229     ## Constructor

    230     def __init__(self, Cursor, MetaFile = '', FileType = MODEL_FILE_DSC, Temporary = False):
    231         MetaFileTable.__init__(self, Cursor, MetaFile, FileType, "Dsc", Temporary)
    232 
    233     ## Insert table

    234     #

    235     # Insert a record into table Dsc

    236     #

    237     # @param Model:          Model of a Dsc item

    238     # @param Value1:         Value1 of a Dsc item

    239     # @param Value2:         Value2 of a Dsc item

    240     # @param Value3:         Value3 of a Dsc item

    241     # @param Scope1:         Arch of a Dsc item

    242     # @param Scope2:         Module type of a Dsc item

    243     # @param BelongsToItem:  The item belongs to which another item

    244     # @param FromItem:       The item belongs to which dsc file

    245     # @param StartLine:      StartLine of a Dsc item

    246     # @param StartColumn:    StartColumn of a Dsc item

    247     # @param EndLine:        EndLine of a Dsc item

    248     # @param EndColumn:      EndColumn of a Dsc item

    249     # @param Enabled:        If this item enabled

    250     #

    251     def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1, BelongsToFile = -1,
    252                FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):
    253         (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))
    254         return Table.Insert(
    255                         self, 
    256                         Model, 
    257                         Value1, 
    258                         Value2, 
    259                         Value3, 
    260                         Scope1, 
    261                         Scope2,
    262                         BelongsToItem, 
    263                         BelongsToFile,
    264                         FromItem,
    265                         StartLine, 
    266                         StartColumn, 
    267                         EndLine, 
    268                         EndColumn, 
    269                         Enabled
    270                         )
    271 
    272     ## Query table

    273     #

    274     # @param Model:          The Model of Record 

    275     # @param Scope1:         Arch of a Dsc item

    276     # @param Scope2:         Module type of a Dsc item

    277     # @param BelongsToItem:  The item belongs to which another item

    278     # @param FromItem:       The item belongs to which dsc file

    279     #

    280     # @retval:       A recordSet of all found records 

    281     #

    282     def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):
    283         ConditionString = "Model=%s AND Enabled>0" % Model
    284         ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
    285 
    286         if Scope1 != None and Scope1 != 'COMMON':
    287             ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1
    288         if Scope2 != None and Scope2 != 'COMMON':
    289             ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2
    290 
    291         if BelongsToItem != None:
    292             ConditionString += " AND BelongsToItem=%s" % BelongsToItem
    293         else:
    294             ConditionString += " AND BelongsToItem<0"
    295 
    296         if FromItem != None:
    297             ConditionString += " AND FromItem=%s" % FromItem
    298 
    299         SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
    300         return self.Exec(SqlCommand)
    301 
    302 ## Factory class to produce different storage for different type of meta-file

    303 class MetaFileStorage(object):
    304     _FILE_TABLE_ = {
    305         MODEL_FILE_INF      :   ModuleTable,
    306         MODEL_FILE_DEC      :   PackageTable,
    307         MODEL_FILE_DSC      :   PlatformTable,
    308         MODEL_FILE_OTHERS   :   MetaFileTable,
    309     }
    310 
    311     _FILE_TYPE_ = {
    312         ".inf"  : MODEL_FILE_INF,
    313         ".dec"  : MODEL_FILE_DEC,
    314         ".dsc"  : MODEL_FILE_DSC,
    315     }
    316 
    317     ## Constructor

    318     def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):
    319         # no type given, try to find one

    320         if not FileType:
    321             if MetaFile.Type in self._FILE_TYPE_:
    322                 FileType = Class._FILE_TYPE_[MetaFile.Type]
    323             else:
    324                 FileType = MODEL_FILE_OTHERS
    325 
    326         # don't pass the type around if it's well known

    327         if FileType == MODEL_FILE_OTHERS:
    328             Args = (Cursor, MetaFile, FileType, Temporary)
    329         else:
    330             Args = (Cursor, MetaFile, FileType, Temporary)
    331 
    332         # create the storage object and return it to caller

    333         return Class._FILE_TABLE_[FileType](*Args)
    334 
    335