예제 #1
0
    def generate(self, pacman):
        print "==> Generating test environment"

        # Cleanup leftover files from a previous test session
        if os.path.isdir(self.root):
            shutil.rmtree(self.root)
        vprint("\t%s" % self.root)

        # Create directory structure
        vprint("    Creating directory structure:")
        dbdir = os.path.join(self.root, util.PM_SYNCDBPATH)
        cachedir = os.path.join(self.root, util.PM_CACHEDIR)
        syncdir = os.path.join(self.root, util.SYNCREPO)
        tmpdir = os.path.join(self.root, util.TMPDIR)
        logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE))
        etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF))
        bindir = os.path.join(self.root, "bin")
        ldconfig = os.path.basename(pacman["ldconfig"])
        ldconfigdir = os.path.join(self.root, os.path.dirname(pacman["ldconfig"][1:]))
        shell = pacman["scriptlet-shell"][1:]
        shelldir = os.path.join(self.root, os.path.dirname(shell))
        sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir,
                    ldconfigdir, shelldir]
        for sys_dir in sys_dirs:
            if not os.path.isdir(sys_dir):
                vprint("\t%s" % sys_dir[len(self.root)+1:])
                os.makedirs(sys_dir, 0755)
        # Only the dynamically linked binary is needed for fakechroot
        shutil.copy("/bin/sh", bindir)
        if shell != "bin/sh":
            shutil.copy("/bin/sh", os.path.join(self.root, shell))
        shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"),
            os.path.join(ldconfigdir, ldconfig))
        ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w")
        ld_so_conf.close()

        # Configuration file
        vprint("    Creating configuration file")
        util.mkcfgfile(util.PACCONF, self.root, self.option, self.db)

        # Creating packages
        vprint("    Creating package archives")
        for pkg in self.localpkgs:
            vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
            pkg.finalize()
            pkg.makepkg(tmpdir)
        for key, value in self.db.iteritems():
            for pkg in value.pkgs:
                pkg.finalize()
            if key == "local" and not self.createlocalpkgs:
                continue
            for pkg in value.pkgs:
                vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename()))
                if self.cachepkgs:
                    pkg.makepkg(cachedir)
                else:
                    pkg.makepkg(os.path.join(syncdir, value.treename))
                pkg.md5sum = util.getmd5sum(pkg.path)
                pkg.csize = os.stat(pkg.path)[stat.ST_SIZE]

        # Creating sync database archives
        vprint("    Creating databases")
        for key, value in self.db.iteritems():
            vprint("\t" + value.treename)
            value.generate()

        # Filesystem
        vprint("    Populating file system")
        for f in self.filesystem:
            vprint("\t%s" % f)
            util.mkfile(self.root, f, f)
            path = os.path.join(self.root, f)
            if os.path.isfile(path):
                os.utime(path, (355, 355))
        for pkg in self.db["local"].pkgs:
            vprint("\tinstalling %s" % pkg.fullname())
            pkg.install_package(self.root)

        # Done.
        vprint("    Taking a snapshot of the file system")
        for roots, dirs, files in os.walk(self.root):
            for i in files:
                filename = os.path.join(roots, i)
                f = pmfile.PacmanFile(self.root, filename.replace(self.root + "/", ""))
                self.files.append(f)
                vprint("\t%s" % f.name)
예제 #2
0
파일: pmtest.py 프로젝트: sandsmark/pacman
    def generate(self):
        print "==> Generating test environment"

        # Cleanup leftover files from a previous test session
        if os.path.isdir(self.root):
            shutil.rmtree(self.root)
        vprint("\t%s" % self.root)

        # Create directory structure
        vprint("    Creating directory structure:")
        dbdir = os.path.join(self.root, util.PM_SYNCDBPATH)
        cachedir = os.path.join(self.root, util.PM_CACHEDIR)
        syncdir = os.path.join(self.root, util.SYNCREPO)
        tmpdir = os.path.join(self.root, util.TMPDIR)
        logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE))
        etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF))
        bindir = os.path.join(self.root, "bin")
        sbindir = os.path.join(self.root, "sbin")
        sys_dirs = [
            dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, sbindir
        ]
        for sys_dir in sys_dirs:
            if not os.path.isdir(sys_dir):
                vprint("\t%s" % sys_dir[len(self.root) + 1:])
                os.makedirs(sys_dir, 0755)
        # Only the dynamically linked binary is needed for fakechroot
        shutil.copy("/bin/sh", bindir)
        shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"),
                    os.path.join(sbindir, "ldconfig"))
        ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w")
        ld_so_conf.close()

        # Configuration file
        vprint("    Creating configuration file")
        util.mkcfgfile(util.PACCONF, self.root, self.option, self.db)

        # Creating packages
        vprint("    Creating package archives")
        for pkg in self.localpkgs:
            vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
            pkg.makepkg(tmpdir)
        for key, value in self.db.iteritems():
            if key == "local" and not self.createlocalpkgs:
                continue
            for pkg in value.pkgs:
                vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename()))
                if self.cachepkgs:
                    pkg.makepkg(cachedir)
                else:
                    pkg.makepkg(os.path.join(syncdir, value.treename))
                pkg.md5sum = util.getmd5sum(pkg.path)
                pkg.csize = os.stat(pkg.path)[stat.ST_SIZE]

        # Creating sync database archives
        vprint("    Creating databases")
        for key, value in self.db.iteritems():
            vprint("\t" + value.treename)
            value.generate()

        # Filesystem
        vprint("    Populating file system")
        for pkg in self.db["local"].pkgs:
            vprint("\tinstalling %s" % pkg.fullname())
            pkg.install_package(self.root)
        for f in self.filesystem:
            vprint("\t%s" % f)
            util.mkfile(self.root, f, f)
            path = os.path.join(self.root, f)
            if os.path.isfile(path):
                os.utime(path, (355, 355))

        # Done.
        vprint("    Taking a snapshot of the file system")
        for roots, dirs, files in os.walk(self.root):
            for i in files:
                filename = os.path.join(roots, i)
                f = pmfile.PacmanFile(self.root,
                                      filename.replace(self.root + "/", ""))
                self.files.append(f)
                vprint("\t%s" % f.name)
예제 #3
0
    def generate(self, pacman):
        tap.diag("==> Generating test environment")

        # Cleanup leftover files from a previous test session
        if os.path.isdir(self.root):
            shutil.rmtree(self.root)
        vprint("\t%s" % self.root)

        # Create directory structure
        vprint("    Creating directory structure:")
        dbdir = os.path.join(self.root, util.PM_SYNCDBPATH)
        cachedir = os.path.join(self.root, util.PM_CACHEDIR)
        syncdir = os.path.join(self.root, util.SYNCREPO)
        tmpdir = os.path.join(self.root, util.TMPDIR)
        logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE))
        etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF))
        bindir = os.path.join(self.root, "bin")
        shell = pacman["scriptlet-shell"][1:]
        shelldir = os.path.join(self.root, os.path.dirname(shell))
        sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir,
                    shelldir]
        for sys_dir in sys_dirs:
            if not os.path.isdir(sys_dir):
                vprint("\t%s" % sys_dir[len(self.root)+1:])
                os.makedirs(sys_dir, 0o755)
        # Only the dynamically linked binary is needed for fakechroot
        shutil.copy("/bin/sh", bindir)
        if shell != "bin/sh":
            shutil.copy("/bin/sh", os.path.join(self.root, shell))

        # Configuration file
        vprint("    Creating configuration file")
        util.mkcfgfile(util.PACCONF, self.root, self.option, self.db)

        # Creating packages
        vprint("    Creating package archives")
        for pkg in self.localpkgs:
            vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
            pkg.finalize()
            pkg.makepkg(tmpdir)
        for key, value in self.db.items():
            for pkg in value.pkgs:
                pkg.finalize()
            if key == "local" and not self.createlocalpkgs:
                continue
            for pkg in value.pkgs:
                vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename()))
                if self.cachepkgs:
                    pkg.makepkg(cachedir)
                else:
                    pkg.makepkg(os.path.join(syncdir, value.treename))
                pkg.md5sum = util.getmd5sum(pkg.path)
                pkg.csize = os.stat(pkg.path)[stat.ST_SIZE]

        # Creating sync database archives
        vprint("    Creating databases")
        for key, value in self.db.items():
            vprint("\t" + value.treename)
            value.generate()

        # Filesystem
        vprint("    Populating file system")
        for f in self.filesystem:
            if type(f) is pmfile.pmfile:
                vprint("\t%s" % f.path)
                f.mkfile(self.root);
            else:
                vprint("\t%s" % f)
                path = util.mkfile(self.root, f, f)
                if os.path.isfile(path):
                    os.utime(path, (355, 355))
        for pkg in self.db["local"].pkgs:
            vprint("\tinstalling %s" % pkg.fullname())
            pkg.install_package(self.root)
        if self.db["local"].pkgs and self.dbver >= 9:
            path = os.path.join(self.root, util.PM_DBPATH, "local")
            util.mkfile(path, "ALPM_DB_VERSION", str(self.dbver))

        # Done.
        vprint("    Taking a snapshot of the file system")
        for filename in self.snapshots_needed():
            f = pmfile.snapshot(self.root, filename)
            self.files.append(f)
            vprint("\t%s" % f.name)
예제 #4
0
파일: pmtest.py 프로젝트: guimmp92/pacman-1
    def generate(self, pacman):
        tap.diag("==> Generating test environment")

        # Cleanup leftover files from a previous test session
        if os.path.isdir(self.root):
            shutil.rmtree(self.root)
        vprint("\t%s" % self.root)

        # Create directory structure
        vprint("    Creating directory structure:")
        dbdir = os.path.join(self.root, util.PM_SYNCDBPATH)
        cachedir = os.path.join(self.root, util.PM_CACHEDIR)
        syncdir = os.path.join(self.root, util.SYNCREPO)
        tmpdir = os.path.join(self.root, util.TMPDIR)
        logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE))
        etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF))
        bindir = os.path.join(self.root, "bin")
        ldconfig = os.path.basename(pacman["ldconfig"])
        ldconfigdir = os.path.join(self.root, os.path.dirname(pacman["ldconfig"][1:]))
        shell = pacman["scriptlet-shell"][1:]
        shelldir = os.path.join(self.root, os.path.dirname(shell))
        sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir,
                    ldconfigdir, shelldir]
        for sys_dir in sys_dirs:
            if not os.path.isdir(sys_dir):
                vprint("\t%s" % sys_dir[len(self.root)+1:])
                os.makedirs(sys_dir, 0o755)
        # Only the dynamically linked binary is needed for fakechroot
        shutil.copy("/bin/sh", bindir)
        if shell != "bin/sh":
            shutil.copy("/bin/sh", os.path.join(self.root, shell))
        shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"),
            os.path.join(ldconfigdir, ldconfig))
        ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w")
        ld_so_conf.close()

        # Configuration file
        vprint("    Creating configuration file")
        util.mkcfgfile(util.PACCONF, self.root, self.option, self.db)

        # Creating packages
        vprint("    Creating package archives")
        for pkg in self.localpkgs:
            vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
            pkg.finalize()
            pkg.makepkg(tmpdir)
        for key, value in self.db.items():
            for pkg in value.pkgs:
                pkg.finalize()
            if key == "local" and not self.createlocalpkgs:
                continue
            for pkg in value.pkgs:
                vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename()))
                if self.cachepkgs:
                    pkg.makepkg(cachedir)
                else:
                    pkg.makepkg(os.path.join(syncdir, value.treename))
                pkg.md5sum = util.getmd5sum(pkg.path)
                pkg.csize = os.stat(pkg.path)[stat.ST_SIZE]

        # Creating sync database archives
        vprint("    Creating databases")
        for key, value in self.db.items():
            vprint("\t" + value.treename)
            value.generate()

        # Filesystem
        vprint("    Populating file system")
        for f in self.filesystem:
            if type(f) is pmfile.pmfile:
                vprint("\t%s" % f.path)
                f.mkfile(self.root);
            else:
                vprint("\t%s" % f)
                path = util.mkfile(self.root, f, f)
                if os.path.isfile(path):
                    os.utime(path, (355, 355))
        for pkg in self.db["local"].pkgs:
            vprint("\tinstalling %s" % pkg.fullname())
            pkg.install_package(self.root)
        if self.db["local"].pkgs and self.dbver >= 9:
            path = os.path.join(self.root, util.PM_DBPATH, "local")
            util.mkfile(path, "ALPM_DB_VERSION", str(self.dbver))

        # Done.
        vprint("    Taking a snapshot of the file system")
        for filename in self.snapshots_needed():
            f = pmfile.snapshot(self.root, filename)
            self.files.append(f)
            vprint("\t%s" % f.name)