コード例 #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 isdir(path):
    return os.path.isdir(LongFilePath(path))
コード例 #3
0
def isfile(path):
    return os.path.isfile(LongFilePath(path))
コード例 #4
0
 def replace(src, dst):
     return os.replace(LongFilePath(src), LongFilePath(dst))
コード例 #5
0
def listdir(path):
    List = []
    uList = os.listdir(u"%s" % LongFilePath(path))
    for Item in uList:
        List.append(Item)
    return List
コード例 #6
0
    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
コード例 #7
0
def chdir(path):
    return os.chdir(LongFilePath(path))
コード例 #8
0
def getctime(filename):
    return os.path.getctime(LongFilePath(filename))
コード例 #9
0
def makedirs(name, mode=0o777):
    return os.makedirs(LongFilePath(name), mode)
コード例 #10
0
def rename(old, new):
    return os.rename(LongFilePath(old), LongFilePath(new))
コード例 #11
0
def mkdir(path):
    return os.mkdir(LongFilePath(path))
コード例 #12
0
def rmdir(path):
    return os.rmdir(LongFilePath(path))
コード例 #13
0
def removedirs(name):
    return os.removedirs(LongFilePath(name))
コード例 #14
0
def exists(path):
    return os.path.exists(LongFilePath(path))
コード例 #15
0
def chmod(path, mode):
    return os.chmod(LongFilePath(path), mode)
コード例 #16
0
def getsize(filename):
    return os.path.getsize(LongFilePath(filename))
コード例 #17
0
def stat(path):
    return os.stat(LongFilePath(path))
コード例 #18
0
    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
コード例 #19
0
def utime(path, times):
    return os.utime(LongFilePath(path), times)
コード例 #20
0
    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
コード例 #21
0
def access(path, mode):
    return os.access(LongFilePath(path), mode)