示例#1
0
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))
示例#2
0
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
示例#3
0
 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:
示例#4
0
    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);
示例#5
0
    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
示例#6
0
 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:
示例#7
0
    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)
示例#8
0
    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
示例#9
0
def rename(old, new):
    return os.rename(LongFilePath(old), LongFilePath(new))
示例#10
0
def chdir(path):
    return os.chdir(LongFilePath(path))
示例#11
0
def mkdir(path):
    return os.mkdir(LongFilePath(path))
示例#12
0
def makedirs(name, mode=0777):
    return os.makedirs(LongFilePath(name), mode)
def getctime(filename):
    return os.path.getctime(LongFilePath(filename))
示例#14
0
def rmdir(path):
    return os.rmdir(LongFilePath(path))
示例#15
0
def access(path, mode):
    return os.access(LongFilePath(path), mode)
示例#16
0
def utime(path, times):
    return os.utime(LongFilePath(path), times)
def isfile(path):
    return os.path.isfile(LongFilePath(path))
示例#18
0
    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))
示例#21
0
def remove(path):
    return os.remove(LongFilePath(path))
示例#22
0
def chmod(path, mode):
    return os.chmod(LongFilePath(path), mode)
示例#23
0
 def replace(src, dst):
     return os.replace(LongFilePath(src), LongFilePath(dst))
示例#24
0
def stat(path):
    return os.stat(LongFilePath(path))
示例#25
0
def removedirs(name):
    return os.removedirs(LongFilePath(name))
示例#26
0
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))