示例#1
0
    def addFileFromPackage(self, pattern, pkg, recurse, remapList):
        pathMap = {}
        for (pathId, pkgPath, fileId, version) in pkg.iterFileList():
            pathMap[pkgPath] = (pathId, fileId, version)

        patternList = util.braceExpand(pattern)
        matches = {}
        for pattern in patternList:
            if not recurse:
                matchList = [
                    n for n in pathMap.keys() if fnmatchcase(n, pattern)
                ]
            else:
                matchList = []
                dirCount = pattern.count("/")
                for n in pathMap.iterkeys():
                    i = n.count("/")
                    if i > dirCount:
                        dirName = os.sep.join(n.split(os.sep)[:dirCount + 1])
                        match = fnmatchcase(dirName, pattern)
                    elif i == dirCount:
                        match = fnmatchcase(n, pattern)
                    else:
                        match = False

                    if match: matchList.append(n)

            for path in matchList:
                matches[path] = pathMap[path]

        if not matches:
            return False

        for path in matches.keys():
            (pathId, fileId, version) = matches[path]

            for (old, new) in remapList:
                if path == old:
                    path = new
                    break
                elif len(path) > len(old) and path.startswith(old) and \
                                              path[len(old)] == "/":
                    path = new + path[len(old):]
                    break

            if self.paths.has_key(path):
                raise builderrors.RecipeFileError(
                    "%s has been included multiple times" % path)

            self.files[pathId] = (path, fileId, version)
            self.paths[path] = 1

        return True
示例#2
0
    def testBraceExpand(self):
        data = [
            ('', []),
            ('a', ['a']),
            ('{a}', ['{a}']),
            ('{{a}}', ['{{a}}']),
            ('{a,b}', ['a', 'b']),
            ('{a,{b,c}}', ['a', 'b', 'c']),
            ('{a,{{b,c},d}}', ['a', 'b', 'c', 'd']),
            ('{a{b,c}}', ['{ab}', '{ac}']),
            ('{a{b},c}', ['a{b}', 'c']),
            ('{{a,b}{c,d}}', ['{ac}', '{ad}', '{bc}', '{bd}']),
            ('{{a,b}{c,d},{e,f}{g,h}}', [
                'ac',
                'ad',
                'bc',
                'bd',
                'eg',
                'eh',
                'fg',
                'fh',
            ]),
            ('{,a}', ['a']),
            ('a{,b}', ['a', 'ab']),
            ('a{b,}', ['ab', 'a']),
            ('{a}{b}', ['{a}{b}']),
            ('{{ab,}}', ['{ab}', '{}']),
            ('{{a,}}', ['{a}', '{}']),
            ('abc', ['abc']),
            ('aa{bb,cc}dd', ['aabbdd', 'aaccdd']),
            ('aa{bb,cc}dd{e}', ['aabbdd{e}', 'aaccdd{e}']),
            ('{a,b}}', ['a}', 'b}']),
            ('{{a,b}', ['{a', '{b']),
            ('{{{a,b}', ['{{a', '{{b']),
            ('c{{{a,b}', ['c{{a', 'c{{b']),
            ('a{,{a,b}', ['a{,a', 'a{,b']),
            (r'\{a,b}', ['{a,b}']),
            (r'{a,b\}', ['{a,b}']),
            (r'{a,b\\}', ['a', 'b\\']),
            (r'{a\,b}', ['{a,b}']),
            (r'{a\\,b}', ['a\\', 'b']),
            (r'a\b', ['ab']),
            (r'{a\b}', ['{ab}']),
        ]
        for inString, expected in data:
            self.assertEqual(util.braceExpand(inString), expected)

        # This is so we have coverage for __repr__
        l = util.BraceExpander.Alternative(['a', 'b'])
        self.assertEqual(repr(l), "Alternative['a', 'b']")
        l = util.BraceExpander.Product(['a', 'b'])
        self.assertEqual(repr(l), "Product['a', 'b']")
示例#3
0
    def addFileFromPackage(self, pattern, pkg, recurse, remapList):
        pathMap = {}
        for (pathId, pkgPath, fileId, version) in pkg.iterFileList():
            pathMap[pkgPath] = (pathId, fileId, version)

        patternList = util.braceExpand(pattern)
        matches = {}
        for pattern in patternList:
            if not recurse:
                matchList = [ n for n in pathMap.keys() if
                                    fnmatchcase(n, pattern)]
            else:
                matchList = []
                dirCount = pattern.count("/")
                for n in pathMap.iterkeys():
                    i = n.count("/")
                    if i > dirCount:
                        dirName = os.sep.join(n.split(os.sep)[:dirCount + 1])
                        match = fnmatchcase(dirName, pattern)
                    elif i == dirCount:
                        match = fnmatchcase(n, pattern)
                    else:
                        match = False

                    if match: matchList.append(n)

            for path in matchList:
                matches[path] = pathMap[path]

        if not matches:
            return False

        for path in matches.keys():
            (pathId, fileId, version) = matches[path]

            for (old, new) in remapList:
                if path == old:
                    path = new
                    break
                elif len(path) > len(old) and path.startswith(old) and \
                                              path[len(old)] == "/":
                    path = new + path[len(old):]
                    break

            if self.paths.has_key(path):
                raise builderrors.RecipeFileError(
                        "%s has been included multiple times" % path)

            self.files[pathId] = (path, fileId, version)
            self.paths[path] = 1

        return True
示例#4
0
文件: utiltest.py 项目: pombr/conary
    def testBraceExpand(self):
        data = [
            ('', []),
            ('a', ['a']),
            ('{a}', ['{a}']),
            ('{{a}}', ['{{a}}']),
            ('{a,b}', ['a', 'b']),
            ('{a,{b,c}}', ['a', 'b', 'c']),
            ('{a,{{b,c},d}}', ['a', 'b', 'c', 'd']),
            ('{a{b,c}}', ['{ab}', '{ac}']),
            ('{a{b},c}', ['a{b}', 'c']),
            ('{{a,b}{c,d}}', ['{ac}', '{ad}', '{bc}', '{bd}']),
            ('{{a,b}{c,d},{e,f}{g,h}}',
                ['ac', 'ad', 'bc', 'bd', 'eg', 'eh', 'fg', 'fh',]),
            ('{,a}', ['a']),
            ('a{,b}', ['a', 'ab']),
            ('a{b,}', ['ab', 'a']),
            ('{a}{b}', ['{a}{b}']),
            ('{{ab,}}', ['{ab}', '{}']),
            ('{{a,}}', ['{a}', '{}']),
            ('abc', ['abc']),
            ('aa{bb,cc}dd', ['aabbdd', 'aaccdd']),
            ('aa{bb,cc}dd{e}', ['aabbdd{e}', 'aaccdd{e}']),
            ('{a,b}}', ['a}', 'b}']),
            ('{{a,b}', ['{a', '{b']),
            ('{{{a,b}', ['{{a', '{{b']),
            ('c{{{a,b}', ['c{{a', 'c{{b']),
            ('a{,{a,b}', ['a{,a', 'a{,b']),
            (r'\{a,b}', ['{a,b}']),
            (r'{a,b\}', ['{a,b}']),
            (r'{a,b\\}', ['a', 'b\\']),
            (r'{a\,b}', ['{a,b}']),
            (r'{a\\,b}', ['a\\', 'b']),
            (r'a\b', ['ab']),
            (r'{a\b}', ['{ab}']),
        ]
        for inString, expected in data:
            self.assertEqual(util.braceExpand(inString), expected)

        # This is so we have coverage for __repr__
        l = util.BraceExpander.Alternative(['a', 'b'])
        self.assertEqual(repr(l), "Alternative['a', 'b']")
        l = util.BraceExpander.Product(['a', 'b'])
        self.assertEqual(repr(l), "Product['a', 'b']")
示例#5
0
def get_bootloader(parent, image_root, geometry, override=None):
    """
    Choose an appropriate bootloader for the given image and return a
    Bootloader instance used to prepare and install the bootloader.
    """

    grubpath = util.searchFile("grub", util.braceExpand("%s/{sbin,usr/sbin}" % image_root))
    if override == "extlinux" or (
        not override
        and os.path.exists(util.joinPaths(image_root, "sbin/bootman"))
        and os.path.exists(util.joinPaths(image_root, "sbin/extlinux"))
    ):
        return ExtLinuxInstaller(parent, image_root, geometry)
    elif override == "grub2" or (not override and os.path.exists(util.joinPaths(image_root, "usr/sbin/grub2-install"))):
        return Grub2Installer(parent, image_root, geometry)
    elif override == "grub" or (not override and grubpath):
        return GrubInstaller(parent, image_root, geometry, grubpath.replace(image_root, ""))
    log.warning("Could not find extlinux (with bootman) or grub")
    log.warning("No bootloader will be installed!")
    return DummyInstaller(parent, image_root, geometry)