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 listdir(path): List = [] path = LongFilePath(path) encoding = locale.getdefaultlocale()[1] if encoding and not isinstance(path, unicode): path = path.decode(encoding) uList = os.listdir(path) for Item in uList: if encoding: Item = Item.encode(encoding) 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 = self.OpenUniFile(LongFilePath(File.Path)) except UnicodeError, X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File); except:
def PreProcess(self, File): if not os.path.exists(File.Path) or not os.path.isfile(File.Path): EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) try: FileIn = self.OpenUniFile(LongFilePath(File.Path)) except UnicodeError, X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path);
def LoadIdfFile(self, File=None): if File == None: EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.') self.File = File 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 = self.StripComments(Line) if len(Line) == 0: continue if Line.find('#image ') >= 0: LineDetails = Line.split() LineNo = GetLineNo(FileIn, Line, False) 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 = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', LineDetails[1], re.UNICODE) if MatchString == None or MatchString.end(0) != len( LineDetails[1]): 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 GetLangDef(self, File, Line): Lang = distutils.util.split_quoted((Line.split(u"//")[0])) if len(Lang) != 3: try: FileIn = codecs.open(LongFilePath(File.Path), mode='rb', encoding='utf-16').read() except UnicodeError, X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File) except:
def PreProcess(self, File): if not os.path.exists(File.Path) or not os.path.isfile(File.Path): EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) try: FileIn = codecs.open(LongFilePath(File.Path), mode='rb', encoding='utf-16').readlines() except UnicodeError, X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path)
def GetLangDef(self, File, Line): Lang = shlex.split(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 rename(old, new): return os.rename(LongFilePath(old), LongFilePath(new))
def chdir(path): return os.chdir(LongFilePath(path))
def mkdir(path): return os.mkdir(LongFilePath(path))
def makedirs(name, mode=0777): return os.makedirs(LongFilePath(name), mode)
def getctime(filename): return os.path.getctime(LongFilePath(filename))
def rmdir(path): return os.rmdir(LongFilePath(path))
def access(path, mode): return os.access(LongFilePath(path), mode)
def utime(path, times): return os.utime(LongFilePath(path), times)
def isfile(path): return os.path.isfile(LongFilePath(path))
def PreProcess(self, File): if not os.path.exists(File.Path) or not os.path.isfile(File.Path): EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) 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: 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 isdir(path): return os.path.isdir(LongFilePath(path))
def exists(path): return os.path.exists(LongFilePath(path))
def remove(path): return os.remove(LongFilePath(path))
def chmod(path, mode): return os.chmod(LongFilePath(path), mode)
def replace(src, dst): return os.replace(LongFilePath(src), LongFilePath(dst))
def stat(path): return os.stat(LongFilePath(path))
def removedirs(name): return os.removedirs(LongFilePath(name))
def listdir(path): List = [] uList = os.listdir(u"%s" % LongFilePath(path)) for Item in uList: List.append(UniToStr(Item)) return List
def getsize(filename): return os.path.getsize(LongFilePath(filename))