## @file
# This is the base class for applications that operate on an EDK II Workspace
#
# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
from DataType import *
## EdkIIWorkspace
#
# Collect WorkspaceDir from the environment, the Verbose command line flag, and detect an icon bitmap file.
#
# @var StartTime: Time of build system starting
# @var PrintRunTime: Printable time of build system running
# @var PrintRunStatus: Printable status of build system running
# @var RunStatus: Status of build system running
#
class EdkIIWorkspace:
#
# Check environment valiable 'WORKSPACE'
#
print 'ERROR: WORKSPACE not defined. Please run EdkSetup from the EDK II install directory.'
return False
if Drive == '':
if Drive != '':
else:
try:
#
# Load TianoCoreOrgLogo, used for GUI tool
#
except:
## Close build system
#
# Close build system and print running time and status
#
if self.PrintRunTime:
if Seconds < 60:
print 'Run Time: %d seconds' % (Seconds)
else:
if Minutes < 60:
else:
## Convert to a workspace relative filename
#
# Convert a full path filename to a workspace relative filename.
#
# @param FileName: The filename to be Converted
#
# @retval None Workspace dir is not found in the full path
# @retval string The relative filename
#
return None
## Convert to a full path filename
#
# Convert a workspace relative filename to a full path filename.
#
# @param FileName: The filename to be Converted
#
# @retval string The full path filename
#
## Convert to a real path filename
#
# Convert ${WORKSPACE} to real path
#
# @param FileName: The filename to be Converted
#
# @retval string The full path filename
#
## Convert XML into a DOM
#
# Parse an XML file into a DOM and return the DOM.
#
# @param FileName: The filename to be parsed
#
# @retval XmlParseFile (self.WorkspaceFile(FileName))
#
print FileName
## Convert a XML section
#
# Parse a section of an XML file into a DOM(Document Object Model) and return the DOM.
#
# @param FileName: The filename to be parsed
# @param SectionTag: The tag name of the section to be parsed
#
# @retval XmlParseFileSection (self.WorkspaceFile(FileName), SectionTag)
#
print FileName
## Save a XML file
#
# Save a DOM(Document Object Model) into an XML file.
#
# @param Dom: The Dom to be saved
# @param FileName: The filename
#
# @retval XmlSaveFile (Dom, self.WorkspaceFile(FileName))
#
print FileName
## Convert Text File To Dictionary
#
# Convert a workspace relative text file to a dictionary of (name:value) pairs.
#
# @param FileName: Text filename
# @param Dictionary: Dictionary to store data
# @param CommentCharacter: Comment char, be used to ignore comment content
# @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
# @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
# @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
#
# @retval ConvertTextFileToDictionary(self.WorkspaceFile(FileName), Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter)
#
def ConvertTextFileToDictionary(self, FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
print FileName
return ConvertTextFileToDictionary(self.WorkspaceFile(FileName), Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter)
## Convert Dictionary To Text File
#
# Convert a dictionary of (name:value) pairs to a workspace relative text file.
#
# @param FileName: Text filename
# @param Dictionary: Dictionary to store data
# @param CommentCharacter: Comment char, be used to ignore comment content
# @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
# @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
# @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
#
# @retval ConvertDictionaryToTextFile(self.WorkspaceFile(FileName), Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter)
#
def ConvertDictionaryToTextFile(self, FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
print FileName
return ConvertDictionaryToTextFile(self.WorkspaceFile(FileName), Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter)
## Convert Text File To Dictionary
#
# Convert a text file to a dictionary of (name:value) pairs.
#
# @param FileName: Text filename
# @param Dictionary: Dictionary to store data
# @param CommentCharacter: Comment char, be used to ignore comment content
# @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
# @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
# @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
#
# @retval True Convert successfully
# @retval False Open file failed
#
def ConvertTextFileToDictionary(FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
try:
except:
return False
Keys = []
for Line in F:
if ValueSplitFlag:
else:
F.close()
return True
## Convert Dictionary To Text File
#
# Convert a dictionary of (name:value) pairs to a text file.
#
# @param FileName: Text filename
# @param Dictionary: Dictionary to store data
# @param CommentCharacter: Comment char, be used to ignore comment content
# @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
# @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
# @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
#
# @retval True Convert successfully
# @retval False Open file failed
#
def ConvertDictionaryToTextFile(FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
try:
Lines = []
F.close()
except:
Lines = []
MaxLength = 0
Index = 0
if ValueSplitFlag:
else:
Index += 1
for RemainingKey in Keys:
if ValueSplitFlag:
Line = '%-*s %c %s\n' % (MaxLength, RemainingKey, KeySplitCharacter,' '.join(Dictionary[RemainingKey]))
else:
try:
except:
return False
F.writelines(Lines)
F.close()
return True
## Create a new directory
#
# @param Directory: Directory to be created
#
## Create a new file
#
# @param Directory: Directory to be created
# @param FileName: Filename to be created
# @param Mode: The mode of open file, defautl is 'w'
#
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
# Nothing to do here. Could do some unit tests
pass