Esempio n. 1
0
    def do(self):
        # calls doFile on all appropriate files -- can be overridden by
        # subclasses
        if not self.filetree:
            return

        if self.filetree & PACKAGE:
            pkg = self.recipe.autopkg
            for thispath in sorted(pkg.pathMap):
                if self._pathAllowed(thispath):
                    self.doFile(thispath)
            return

        assert (self.filetree & DIR)
        if self.subtrees:
            self.invariantsubtrees.extend(self.subtrees)
        if not self.invariantsubtrees:
            self.invariantsubtrees.append('/')
        for self.currentsubtree in self.invariantsubtrees:
            fullpath = (self.rootdir + self.currentsubtree) % self.macros
            dirs = util.braceGlob(fullpath)
            for d in dirs:
                if self.recursive:
                    os.path.walk(d, self.walkDir, None)
                else:
                    # only one level
                    if os.path.isdir(d):
                        self.walkDir(None, d, os.listdir(d))
Esempio n. 2
0
    def do(self):
        # calls doFile on all appropriate files -- can be overridden by
        # subclasses
        if not self.filetree:
            return

        if self.filetree & PACKAGE:
            pkg = self.recipe.autopkg
            for thispath in sorted(pkg.pathMap):
                if self._pathAllowed(thispath):
                    self.doFile(thispath)
            return

        assert(self.filetree & DIR)
        if self.subtrees:
            self.invariantsubtrees.extend(self.subtrees)
        if not self.invariantsubtrees:
            self.invariantsubtrees.append('/')
        for self.currentsubtree in self.invariantsubtrees:
            fullpath = (self.rootdir+self.currentsubtree) %self.macros
            dirs = util.braceGlob(fullpath)
            for d in dirs:
                if self.recursive:
                    os.path.walk(d, self.walkDir, None)
                else:
                    # only one level
                    if os.path.isdir(d):
                        self.walkDir(None, d, os.listdir(d))
Esempio n. 3
0
 def includeConfigFile(self, val, fileName = "override",
                       lineno = '<No line>'):
     abspath = self._absPath(val)
     if self.isUrl(abspath):
         self.readUrl(abspath, resetSection = False)
     else:
         for cfgfile in sorted(util.braceGlob(abspath)):
             self.read(cfgfile, resetSection = False)
Esempio n. 4
0
 def includeConfigFile(self, val, fileName = "override",
                       lineno = '<No line>'):
     abspath = self._absPath(val)
     if self.isUrl(abspath):
         self.readUrl(abspath, resetSection = False)
     else:
         for cfgfile in sorted(util.braceGlob(abspath)):
             self.read(cfgfile, resetSection = False)
Esempio n. 5
0
def _expandPaths(paths, macros, defaultDir=None, braceGlob=True, error=False):
    """
    Expand braces, globs, and macros in path names, and root all path names
    to either the build dir or dest dir.  Relative paths (not starting with
    a /) are relative to builddir.  All absolute paths to are relative to
    destdir.
    """
    destdir = macros.destdir
    if defaultDir is None:
        defaultDir = macros.builddir
    expPaths = []
    for item in paths:
        if isinstance(item, Regexp):
            isRegexp = True
            path = item.pattern
        elif isinstance(item, Glob):
            isRegexp = False
            braceGlob = True
            path = item.pattern
        else:
            isRegexp = False
            path = item
        path = path % macros
        if path[0] == '/':
            if path.startswith(destdir):
                log.warning(
                    "remove destdir from path name %s;"
                    " absolute paths are automatically relative to destdir" %
                    path)
            else:
                path = destdir + path
            baseDir = destdir
        else:
            path = defaultDir + os.sep + path
            baseDir = defaultDir
        if isRegexp:
            expPaths.extend(matchRegexp(baseDir, path, item))
        elif braceGlob:
            expPaths.extend(util.braceGlob(path))
        else:
            expPaths.append(path)
    if error:
        notfound = []
        for path in expPaths:
            if not os.path.exists(path):
                notfound.append(path)
        if notfound:
            raise RuntimeError, "No such file(s) '%s'" % "', '".join(notfound)
    return expPaths
Esempio n. 6
0
def _expandPaths(paths, macros, defaultDir=None, braceGlob=True, error=False):
    """
    Expand braces, globs, and macros in path names, and root all path names
    to either the build dir or dest dir.  Relative paths (not starting with
    a /) are relative to builddir.  All absolute paths to are relative to
    destdir.
    """
    destdir = macros.destdir
    if defaultDir is None:
        defaultDir = macros.builddir
    expPaths = []
    for item in paths:
        if isinstance(item, Regexp):
            isRegexp = True
            path = item.pattern
        elif isinstance(item, Glob):
            isRegexp = False
            braceGlob = True
            path = item.pattern
        else:
            isRegexp = False
            path = item
        path = path % macros
        if path[0] == '/':
            if path.startswith(destdir):
                log.warning(
                    "remove destdir from path name %s;"
                    " absolute paths are automatically relative to destdir"
                    %path)
            else:
                path = destdir + path
            baseDir = destdir
        else:
            path = defaultDir + os.sep + path
            baseDir = defaultDir
        if isRegexp:
            expPaths.extend(matchRegexp(baseDir, path, item))
        elif braceGlob:
            expPaths.extend(util.braceGlob(path))
        else:
            expPaths.append(path)
    if error:
        notfound = []
        for path in expPaths:
            if not os.path.exists(path):
                notfound.append(path)
        if notfound:
            raise RuntimeError, "No such file(s) '%s'" % "', '".join(notfound)
    return expPaths
Esempio n. 7
0
 def testBraceGlob(self):
     d = tempfile.mkdtemp()
     expected = []
     for sub in ('foo', 'fred'):
         subdir = os.sep.join((d, sub))
         os.mkdir(subdir)
         path = os.sep.join((subdir, 'bar'))
         expected.append(path)
         f = open(path, 'w')
         f.write('hello\n')
         f.close()
     f = open(os.sep.join((d, 'file')), 'w')
     f.write('hello\n')
     f.close()
     actual = util.braceGlob(os.sep.join((d, '*', 'bar')))
     expected.sort()
     actual.sort()
     if expected != actual:
         self.fail('glob did not yield expected results.  expected "%s" got "%s"', expected, actual)
     util.rmtree(d)
Esempio n. 8
0
 def testBraceGlob(self):
     d = tempfile.mkdtemp()
     expected = []
     for sub in ('foo', 'fred'):
         subdir = os.sep.join((d, sub))
         os.mkdir(subdir)
         path = os.sep.join((subdir, 'bar'))
         expected.append(path)
         f = open(path, 'w')
         f.write('hello\n')
         f.close()
     f = open(os.sep.join((d, 'file')), 'w')
     f.write('hello\n')
     f.close()
     actual = util.braceGlob(os.sep.join((d, '*', 'bar')))
     expected.sort()
     actual.sort()
     if expected != actual:
         self.fail('glob did not yield expected results.  expected "%s" got "%s"', expected, actual)
     util.rmtree(d)
Esempio n. 9
0
def copytree(sources, dest, symlinks=False, filemode=None, dirmode=None, fileowner=None, dirowner=None, callback=None):
    """
    Copies tree(s) from sources to dest, returning a list of
    the filenames that it has written.
    """
    sourcelist = []
    totalFiles = 0
    for source in util.braceGlob(sources):
        if os.path.isdir(source):
            if source[-1] == "/":
                source = source[:-1]
            thisdest = "%s%s%s" % (dest, os.sep, os.path.basename(source))
            log.debug("copying [tree] %s to %s", source, thisdest)
            _copytree(source, thisdest, symlinks, callback=callback)
            if dirmode:
                os.chmod(thisdest, dirmode)
            if dirowner:
                os.chown(thisdest, *dirowner)
            os.path.walk(
                source, _copyVisit, (sourcelist, len(source), thisdest, filemode, dirmode, fileowner, dirowner)
            )
        else:
            log.debug("copying [file] %s to %s", source, dest)
            shutil.copy2(source, dest)
            totalFiles += 1
            if callback:
                callback(totalFiles)

            if dest.endswith(os.sep):
                thisdest = dest + os.sep + os.path.basename(source)
            else:
                thisdest = dest
            if filemode:
                os.chmod(thisdest, filemode)
            if fileowner:
                os.chown(thisdest, *fileowner)
            sourcelist.append(thisdest)
    return sourcelist