def remove(path): Timeout = 0.0 while Timeout < 5.0: try: return os.remove(LongFilePath(path)) except: time.sleep(0.1) Timeout = Timeout + 0.1 return os.remove(LongFilePath(path))
def isdir(path): return os.path.isdir(LongFilePath(path))
def isfile(path): return os.path.isfile(LongFilePath(path))
def replace(src, dst): return os.replace(LongFilePath(src), LongFilePath(dst))
def listdir(path): List = [] uList = os.listdir(u"%s" % LongFilePath(path)) for Item in uList: List.append(Item) return List
def GetLangDef(self, File, Line): Lang = distutils.util.split_quoted((Line.split(u"//")[0])) if len(Lang) != 3: try: FileIn = UniFileClassObject.OpenUniFile(LongFilePath( File.Path)) except UnicodeError as X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File) except: EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File) LineNo = GetLineNo(FileIn, Line, False) EdkLogger.error( "Unicode File Parser", PARSER_ERROR, "Wrong language definition", ExtraData= """%s\n\t*Correct format is like '#langdef en-US "English"'""" % Line, File=File, Line=LineNo) else: LangName = GetLanguageCode(Lang[1], self.IsCompatibleMode, self.File) LangPrintName = Lang[2] IsLangInDef = False for Item in self.LanguageDef: if Item[0] == LangName: IsLangInDef = True break if not IsLangInDef: self.LanguageDef.append([LangName, LangPrintName]) # # Add language string # self.AddStringToList(u'$LANGUAGE_NAME', LangName, LangName, 0, True, Index=0) self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', LangName, LangPrintName, 1, True, Index=1) if not IsLangInDef: # # The found STRING tokens will be added into new language string list # so that the unique STRING identifier is reserved for all languages in the package list. # FirstLangName = self.LanguageDef[0][0] if LangName != FirstLangName: for Index in range(2, len(self.OrderedStringList[FirstLangName])): Item = self.OrderedStringList[FirstLangName][Index] if Item.UseOtherLangDef != '': OtherLang = Item.UseOtherLangDef else: OtherLang = FirstLangName self.OrderedStringList[LangName].append( StringDefClassObject(Item.StringName, '', Item.Referenced, Item.Token, OtherLang)) self.OrderedStringDict[LangName][Item.StringName] = len( self.OrderedStringList[LangName]) - 1 return True
def chdir(path): return os.chdir(LongFilePath(path))
def getctime(filename): return os.path.getctime(LongFilePath(filename))
def makedirs(name, mode=0o777): return os.makedirs(LongFilePath(name), mode)
def rename(old, new): return os.rename(LongFilePath(old), LongFilePath(new))
def mkdir(path): return os.mkdir(LongFilePath(path))
def rmdir(path): return os.rmdir(LongFilePath(path))
def removedirs(name): return os.removedirs(LongFilePath(name))
def exists(path): return os.path.exists(LongFilePath(path))
def chmod(path, mode): return os.chmod(LongFilePath(path), mode)
def getsize(filename): return os.path.getsize(LongFilePath(filename))
def stat(path): return os.stat(LongFilePath(path))
def __init__(self, FileList=[]): self.ImageFilesDict = {} self.ImageIDList = [] for File in FileList: if File is None: EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.') try: IdfFile = open(LongFilePath(File.Path), mode='r') FileIn = IdfFile.read() IdfFile.close() except: EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File) ImageFileList = [] for Line in FileIn.splitlines(): Line = Line.strip() Line = StripComments(Line) if len(Line) == 0: continue LineNo = GetLineNo(FileIn, Line, False) if not Line.startswith('#image '): EdkLogger.error( "Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is invalid.' % (Line, LineNo, File.Path)) if Line.find('#image ') >= 0: LineDetails = Line.split() Len = len(LineDetails) if Len != 3 and Len != 4: EdkLogger.error( "Image Definition File Parser", PARSER_ERROR, 'The format is not match #image IMAGE_ID [TRANSPARENT] ImageFileName in Line %s of File %s.' % (LineNo, File.Path)) if Len == 4 and LineDetails[2] != 'TRANSPARENT': EdkLogger.error( "Image Definition File Parser", PARSER_ERROR, 'Please use the keyword "TRANSPARENT" to describe the transparency setting in Line %s of File %s.' % (LineNo, File.Path)) MatchString = gIdentifierPattern.match(LineDetails[1]) if MatchString is None: EdkLogger.error( 'Image Definition File Parser', FORMAT_INVALID, 'The Image token name %s defined in Idf file %s contains the invalid character.' % (LineDetails[1], File.Path)) if LineDetails[1] not in self.ImageIDList: self.ImageIDList.append(LineDetails[1]) else: EdkLogger.error( "Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is already defined.' % (LineDetails[1], LineNo, File.Path)) if Len == 4: ImageFile = ImageFileObject(LineDetails[Len - 1], LineDetails[1], True) else: ImageFile = ImageFileObject(LineDetails[Len - 1], LineDetails[1], False) ImageFileList.append(ImageFile) if ImageFileList: self.ImageFilesDict[File] = ImageFileList
def utime(path, times): return os.utime(LongFilePath(path), times)
def PreProcess(self, File): try: FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path)) except UnicodeError as X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path) except OSError: EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) except: EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File.Path) Lines = [] # # Use unique identifier # for Line in FileIn: Line = Line.strip() Line = Line.replace(u'\\\\', BACK_SLASH_PLACEHOLDER) Line = StripComments(Line) # # Ignore empty line # if len(Line) == 0: continue Line = Line.replace(u'/langdef', u'#langdef') Line = Line.replace(u'/string', u'#string') Line = Line.replace(u'/language', u'#language') Line = Line.replace(u'/include', u'#include') Line = Line.replace(UNICODE_WIDE_CHAR, WIDE_CHAR) Line = Line.replace(UNICODE_NARROW_CHAR, NARROW_CHAR) Line = Line.replace(UNICODE_NON_BREAKING_CHAR, NON_BREAKING_CHAR) Line = Line.replace(u'\\r\\n', CR + LF) Line = Line.replace(u'\\n', CR + LF) Line = Line.replace(u'\\r', CR) Line = Line.replace(u'\\t', u' ') Line = Line.replace(u'\t', u' ') Line = Line.replace(u'\\"', u'"') Line = Line.replace(u"\\'", u"'") Line = Line.replace(BACK_SLASH_PLACEHOLDER, u'\\') StartPos = Line.find(u'\\x') while (StartPos != -1): EndPos = Line.find(u'\\', StartPos + 1, StartPos + 7) if EndPos != -1 and EndPos - StartPos == 6: if g4HexChar.match(Line[StartPos + 2:EndPos], re.UNICODE): EndStr = Line[EndPos:] UniStr = Line[StartPos + 2:EndPos] if EndStr.startswith(u'\\x') and len(EndStr) >= 7: if EndStr[6] == u'\\' and g4HexChar.match( EndStr[2:6], re.UNICODE): Line = Line[0:StartPos] + UniStr + EndStr else: Line = Line[0:StartPos] + UniStr + EndStr[1:] StartPos = Line.find(u'\\x', StartPos + 1) IncList = gIncludePattern.findall(Line) if len(IncList) == 1: for Dir in [File.Dir] + self.IncludePathList: IncFile = PathClass(str(IncList[0]), Dir) if os.path.isfile(IncFile.Path): Lines.extend(self.PreProcess(IncFile)) break else: EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, Message="Cannot find include file", ExtraData=str(IncList[0])) continue Lines.append(Line) return Lines
def access(path, mode): return os.access(LongFilePath(path), mode)