Esempio n. 1
0
    def db_read(self, name):
        if not self.dbdir or not os.path.isdir(self.dbdir):
            return None

        dbentry = None
        if self.read_dircache is None:
            self.read_dircache = os.listdir(self.dbdir)
        for entry in self.read_dircache:
            if entry == "ALPM_DB_VERSION":
                continue
            [pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
            if pkgname == name:
                dbentry = entry
                break
        if dbentry is None:
            return None

        if pkgname in self.read_pkgcache:
            return self.read_pkgcache[pkgname]

        pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel)
        self.read_pkgcache[pkgname] = pkg

        path = os.path.join(self.dbdir, dbentry)
        # desc
        filename = os.path.join(path, "desc")
        if not os.path.isfile(filename):
            tap.bail("invalid db entry found (desc missing) for pkg " +
                     pkgname)
            return None
        fd = open(filename, "r")
        while 1:
            line = fd.readline()
            if not line:
                break
            line = line.strip("\n")
            if line == "%DESC%":
                pkg.desc = fd.readline().strip("\n")
            elif line == "%GROUPS%":
                pkg.groups = _getsection(fd)
            elif line == "%URL%":
                pkg.url = fd.readline().strip("\n")
            elif line == "%LICENSE%":
                pkg.license = _getsection(fd)
            elif line == "%ARCH%":
                pkg.arch = fd.readline().strip("\n")
            elif line == "%BUILDDATE%":
                pkg.builddate = fd.readline().strip("\n")
            elif line == "%INSTALLDATE%":
                pkg.installdate = fd.readline().strip("\n")
            elif line == "%PACKAGER%":
                pkg.packager = fd.readline().strip("\n")
            elif line == "%REASON%":
                try:
                    pkg.reason = int(fd.readline().strip("\n"))
                except ValueError:
                    pkg.reason = -1
                    raise
            elif line == "%SIZE%" or line == "%CSIZE%":
                try:
                    pkg.size = int(fd.readline().strip("\n"))
                except ValueError:
                    pkg.size = -1
                    raise
            elif line == "%MD5SUM%":
                pkg.md5sum = fd.readline().strip("\n")
            elif line == "%PGPSIG%":
                pkg.pgpsig = fd.readline().strip("\n")
            elif line == "%REPLACES%":
                pkg.replaces = _getsection(fd)
            elif line == "%DEPENDS%":
                pkg.depends = _getsection(fd)
            elif line == "%OPTDEPENDS%":
                pkg.optdepends = _getsection(fd)
            elif line == "%CONFLICTS%":
                pkg.conflicts = _getsection(fd)
            elif line == "%PROVIDES%":
                pkg.provides = _getsection(fd)
        fd.close()

        # files
        filename = os.path.join(path, "files")
        if not os.path.isfile(filename):
            tap.bail("invalid db entry found (files missing) for pkg " +
                     pkgname)
            return None
        fd = open(filename, "r")
        while 1:
            line = fd.readline()
            if not line:
                break
            line = line.strip("\n")
            if line == "%FILES%":
                while line:
                    line = fd.readline().strip("\n")
                    if line:
                        pkg.files.append(line)
            if line == "%BACKUP%":
                pkg.backup = _getsection(fd)
        fd.close()

        # install
        filename = os.path.join(path, "install")

        return pkg
Esempio n. 2
0
                      dest="review",
                      default=False,
                      help="review test files, test output, and saved logs")
    parser.add_option("--editor",
                      action="store",
                      dest="editor",
                      default=os.getenv('EDITOR', 'vim'),
                      help="editor to use for viewing files")
    return parser


if __name__ == "__main__":

    if sys.hexversion < 0x02070000:
        # bailing now with clear message better than mid-run with unhelpful one
        tap.bail("Python versions before 2.7 are not supported.")
        sys.exit(1)

    # parse options
    opt_parser = create_parser()
    (opts, args) = opt_parser.parse_args()

    if args is None or len(args) == 0:
        tap.bail("no tests defined, nothing to do")
        sys.exit(2)

    # instantiate env
    root_path = tempfile.mkdtemp(prefix='pactest-')
    env = pmenv.pmenv(root=root_path)

    # add parsed options to env object
Esempio n. 3
0
                      dest = "valgrind", default = False,
                      help = "use valgrind while calling pacman")
    parser.add_option("--manual-confirm", action = "store_true",
                      dest = "manualconfirm", default = False,
                      help = "do not use --noconfirm for pacman calls")
    parser.add_option("--scriptlet-shell", type = "string",
                      dest = "scriptletshell", default = "/bin/sh",
                      help = "specify path to shell used for install scriptlets")
    return parser


if __name__ == "__main__":

    if sys.hexversion < 0x02070000:
        # bailing now with clear message better than mid-run with unhelpful one
        tap.bail("Python versions before 2.7 are not supported.")
        sys.exit(1)

    # parse options
    opt_parser = create_parser()
    (opts, args) = opt_parser.parse_args()

    if args is None or len(args) == 0:
        tap.bail("no tests defined, nothing to do")
        sys.exit(2)

    # instantiate env
    root_path = tempfile.mkdtemp(prefix='pactest-')
    env = pmenv.pmenv(root=root_path)

    # add parsed options to env object
Esempio n. 4
0
    def run(self, pacman):
        if os.path.isfile(util.PM_LOCK):
            tap.bail("\tERROR: another pacman session is on-going -- skipping")
            return

        tap.diag("==> Running test")
        vprint("\tpacman %s" % self.args)

        cmd = []
        if os.geteuid() != 0:
            fakeroot = util.which("fakeroot")
            if not fakeroot:
                tap.diag("WARNING: fakeroot not found!")
            else:
                cmd.append("fakeroot")

            fakechroot = util.which("fakechroot")
            if not fakechroot:
                tap.diag("WARNING: fakechroot not found!")
            else:
                cmd.append("fakechroot")

        if pacman["gdb"]:
            cmd.extend(["libtool", "execute", "gdb", "--args"])
        if pacman["valgrind"]:
            suppfile = os.path.join(os.path.dirname(__file__), '..', '..',
                                    'valgrind.supp')
            cmd.extend([
                "libtool", "execute", "valgrind", "-q", "--tool=memcheck",
                "--leak-check=full", "--show-reachable=yes",
                "--gen-suppressions=all", "--child-silent-after-fork=yes",
                "--log-file=%s" % os.path.join(self.root, "var/log/valgrind"),
                "--suppressions=%s" % suppfile
            ])
            self.addrule("FILE_EMPTY=var/log/valgrind")

        # replace program name with absolute path
        prog = pacman["bin"]
        if not prog:
            prog = util.which(self.cmd[0], pacman["bindir"])
        if not prog or not os.access(prog, os.X_OK):
            if not prog:
                tap.bail("could not locate '%s' binary" % (self.cmd[0]))
                return

        cmd.append(os.path.abspath(prog))
        cmd.extend(self.cmd[1:])
        if pacman["manual-confirm"]:
            cmd.append("--confirm")
        if pacman["debug"]:
            cmd.append("--debug=%s" % pacman["debug"])
        cmd.extend(shlex.split(self.args))

        if not (pacman["gdb"] or pacman["nolog"]):
            output = open(os.path.join(self.root, util.LOGFILE), 'w')
        else:
            output = None
        vprint("\trunning: %s" % " ".join(cmd))

        # Change to the tmp dir before running pacman, so that local package
        # archives are made available more easily.
        time_start = time.time()
        self.retcode = subprocess.call(cmd,
                                       stdout=output,
                                       stderr=output,
                                       cwd=os.path.join(
                                           self.root, util.TMPDIR),
                                       env={'LC_ALL': 'C'})
        time_end = time.time()
        vprint("\ttime elapsed: %.2fs" % (time_end - time_start))

        if output:
            output.close()

        vprint("\tretcode = %s" % self.retcode)

        # Check if the lock is still there
        if os.path.isfile(util.PM_LOCK):
            tap.diag("\tERROR: %s not removed" % util.PM_LOCK)
            os.unlink(util.PM_LOCK)
        # Look for a core file
        if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")):
            tap.diag("\tERROR: pacman dumped a core file")
Esempio n. 5
0
    def run(self, pacman):
        if os.path.isfile(util.PM_LOCK):
            tap.bail("\tERROR: another pacman session is on-going -- skipping")
            return

        tap.diag("==> Running test")
        vprint("\tpacman %s" % self.args)

        cmd = []
        if os.geteuid() != 0:
            fakeroot = util.which("fakeroot")
            if not fakeroot:
                tap.diag("WARNING: fakeroot not found!")
            else:
                cmd.append("fakeroot")

            fakechroot = util.which("fakechroot")
            if not fakechroot:
                tap.diag("WARNING: fakechroot not found!")
            else:
                cmd.append("fakechroot")

        if pacman["gdb"]:
            cmd.extend(["libtool", "execute", "gdb", "--args"])
        if pacman["valgrind"]:
            suppfile = os.path.join(os.path.dirname(__file__),
                    '..', '..', 'valgrind.supp')
            cmd.extend(["libtool", "execute", "valgrind", "-q",
                "--tool=memcheck", "--leak-check=full",
                "--show-reachable=yes",
                "--gen-suppressions=all",
                "--child-silent-after-fork=yes",
                "--log-file=%s" % os.path.join(self.root, "var/log/valgrind"),
                "--suppressions=%s" % suppfile])
            self.addrule("FILE_EMPTY=var/log/valgrind")

        # replace program name with absolute path
        prog = pacman["bin"]
        if not prog:
            prog = util.which(self.cmd[0], pacman["bindir"])
        if not prog or not os.access(prog, os.X_OK):
            if not prog:
                tap.bail("could not locate '%s' binary" % (self.cmd[0]))
                return

        cmd.append(os.path.abspath(prog))
        cmd.extend(self.cmd[1:])
        if pacman["manual-confirm"]:
            cmd.append("--confirm")
        if pacman["debug"]:
            cmd.append("--debug=%s" % pacman["debug"])
        cmd.extend(shlex.split(self.args))

        if not (pacman["gdb"] or pacman["nolog"]):
            output = open(os.path.join(self.root, util.LOGFILE), 'w')
        else:
            output = None
        vprint("\trunning: %s" % " ".join(cmd))

        # Change to the tmp dir before running pacman, so that local package
        # archives are made available more easily.
        time_start = time.time()
        self.retcode = subprocess.call(cmd, stdout=output, stderr=output,
                cwd=os.path.join(self.root, util.TMPDIR), env={'LC_ALL': 'C'})
        time_end = time.time()
        vprint("\ttime elapsed: %.2fs" % (time_end - time_start))

        if output:
            output.close()

        vprint("\tretcode = %s" % self.retcode)

        # Check if the lock is still there
        if os.path.isfile(util.PM_LOCK):
            tap.diag("\tERROR: %s not removed" % util.PM_LOCK)
            os.unlink(util.PM_LOCK)
        # Look for a core file
        if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")):
            tap.diag("\tERROR: pacman dumped a core file")
Esempio n. 6
0
    # add parsed options to env object
    util.verbose = opts.verbose
    env.pacman["debug"] = opts.debug
    env.pacman["bin"] = opts.bin
    env.pacman["nolog"] = opts.nolog
    env.pacman["gdb"] = opts.gdb
    env.pacman["valgrind"] = opts.valgrind
    env.pacman["manual-confirm"] = opts.manualconfirm
    env.pacman["scriptlet-shell"] = opts.scriptletshell
    env.pacman["ldconfig"] = opts.ldconfig

    opts.testcases = []
    for path in args:
        opts.testcases += glob.glob(path)
    if opts.testcases is None or len(opts.testcases) == 0:
        tap.bail("no tests defined, nothing to do")
        os.rmdir(root_path)
        sys.exit(2)

    for i in opts.testcases:
        env.addtest(i)

    # run tests
    env.run()

    if not opts.keeproot:
        shutil.rmtree(root_path)
    else:
        tap.diag("pacman testing root saved: %s" % root_path)

    if env.failed > 0:
Esempio n. 7
0
File: pmdb.py Progetto: 7799/pacman
    def db_read(self, name):
        if not self.dbdir or not os.path.isdir(self.dbdir):
            return None

        dbentry = None
        if self.read_dircache is None:
            self.read_dircache = os.listdir(self.dbdir)
        for entry in self.read_dircache:
            [pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
            if pkgname == name:
                dbentry = entry
                break
        if dbentry is None:
            return None

        if pkgname in self.read_pkgcache:
            return self.read_pkgcache[pkgname]

        pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel)
        self.read_pkgcache[pkgname] = pkg

        path = os.path.join(self.dbdir, dbentry)
        # desc
        filename = os.path.join(path, "desc")
        if not os.path.isfile(filename):
            tap.bail("invalid db entry found (desc missing) for pkg " + pkgname)
            return None
        fd = open(filename, "r")
        while 1:
            line = fd.readline()
            if not line:
                break
            line = line.strip("\n")
            if line == "%DESC%":
                pkg.desc = fd.readline().strip("\n")
            elif line == "%GROUPS%":
                pkg.groups = _getsection(fd)
            elif line == "%URL%":
                pkg.url = fd.readline().strip("\n")
            elif line == "%LICENSE%":
                pkg.license = _getsection(fd)
            elif line == "%ARCH%":
                pkg.arch = fd.readline().strip("\n")
            elif line == "%BUILDDATE%":
                pkg.builddate = fd.readline().strip("\n")
            elif line == "%INSTALLDATE%":
                pkg.installdate = fd.readline().strip("\n")
            elif line == "%PACKAGER%":
                pkg.packager = fd.readline().strip("\n")
            elif line == "%REASON%":
                try:
                    pkg.reason = int(fd.readline().strip("\n"))
                except ValueError:
                    pkg.reason = -1
                    raise
            elif line == "%SIZE%" or line == "%CSIZE%":
                try:
                    pkg.size = int(fd.readline().strip("\n"))
                except ValueError:
                    pkg.size = -1
                    raise
            elif line == "%MD5SUM%":
                pkg.md5sum = fd.readline().strip("\n")
            elif line == "%PGPSIG%":
                pkg.pgpsig = fd.readline().strip("\n")
            elif line == "%REPLACES%":
                pkg.replaces = _getsection(fd)
            elif line == "%DEPENDS%":
                pkg.depends = _getsection(fd)
            elif line == "%OPTDEPENDS%":
                pkg.optdepends = _getsection(fd)
            elif line == "%CONFLICTS%":
                pkg.conflicts = _getsection(fd)
            elif line == "%PROVIDES%":
                pkg.provides = _getsection(fd)
        fd.close()

        # files
        filename = os.path.join(path, "files")
        if not os.path.isfile(filename):
            tap.bail("invalid db entry found (files missing) for pkg " + pkgname)
            return None
        fd = open(filename, "r")
        while 1:
            line = fd.readline()
            if not line:
                break
            line = line.strip("\n")
            if line == "%FILES%":
                while line:
                    line = fd.readline().strip("\n")
                    if line and line[-1] != "/":
                        pkg.files.append(line)
            if line == "%BACKUP%":
                pkg.backup = _getsection(fd)
        fd.close()

        # install
        filename = os.path.join(path, "install")

        return pkg
Esempio n. 8
0
    def run(self, pacman):
        if os.path.isfile(util.PM_LOCK):
            tap.bail("\tERROR: another pacman session is on-going -- skipping")
            return

        tap.diag("==> Running test")
        vprint("\tpacman %s" % self.args)

        cmd = []
        if os.geteuid() != 0:
            fakeroot = util.which("fakeroot")
            if not fakeroot:
                tap.diag("WARNING: fakeroot not found!")
            else:
                cmd.append("fakeroot")

            fakechroot = util.which("fakechroot")
            if not fakechroot:
                tap.diag("WARNING: fakechroot not found!")
            else:
                cmd.append("fakechroot")

        if pacman["gdb"]:
            cmd.extend(["libtool", "execute", "gdb", "--args"])
        if pacman["valgrind"]:
            suppfile = os.path.join(os.path.dirname(__file__),
                    '..', '..', 'valgrind.supp')
            cmd.extend(["libtool", "execute", "valgrind", "-q",
                "--tool=memcheck", "--leak-check=full",
                "--show-reachable=yes",
                "--suppressions=%s" % suppfile])
        cmd.extend([pacman["bin"],
            "--config", os.path.join(self.root, util.PACCONF),
            "--root", self.root,
            "--dbpath", os.path.join(self.root, util.PM_DBPATH),
            "--cachedir", os.path.join(self.root, util.PM_CACHEDIR)])
        if not pacman["manual-confirm"]:
            cmd.append("--noconfirm")
        if pacman["debug"]:
            cmd.append("--debug=%s" % pacman["debug"])
        cmd.extend(shlex.split(self.args))
        if not (pacman["gdb"] or pacman["valgrind"] or pacman["nolog"]):
            output = open(os.path.join(self.root, util.LOGFILE), 'w')
        else:
            output = None
        vprint("\trunning: %s" % " ".join(cmd))

        # Change to the tmp dir before running pacman, so that local package
        # archives are made available more easily.
        time_start = time.time()
        self.retcode = subprocess.call(cmd, stdout=output, stderr=output,
                cwd=os.path.join(self.root, util.TMPDIR), env={'LC_ALL': 'C'})
        time_end = time.time()
        vprint("\ttime elapsed: %.2fs" % (time_end - time_start))

        if output:
            output.close()

        vprint("\tretcode = %s" % self.retcode)

        # Check if the lock is still there
        if os.path.isfile(util.PM_LOCK):
            tap.diag("\tERROR: %s not removed" % util.PM_LOCK)
            os.unlink(util.PM_LOCK)
        # Look for a core file
        if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")):
            tap.diag("\tERROR: pacman dumped a core file")
Esempio n. 9
0
    def run(self, pacman):
        if os.path.isfile(util.PM_LOCK):
            tap.bail("\tERROR: another pacman session is on-going -- skipping")
            return

        tap.diag("==> Running test")
        vprint("\tpacman %s" % self.args)

        cmd = []
        if os.geteuid() != 0:
            fakeroot = util.which("fakeroot")
            if not fakeroot:
                tap.diag("WARNING: fakeroot not found!")
            else:
                cmd.append("fakeroot")

            fakechroot = util.which("fakechroot")
            if not fakechroot:
                tap.diag("WARNING: fakechroot not found!")
            else:
                cmd.append("fakechroot")

        if pacman["gdb"]:
            cmd.extend(["libtool", "execute", "gdb", "--args"])
        if pacman["valgrind"]:
            suppfile = os.path.join(os.path.dirname(__file__), '..', '..',
                                    'valgrind.supp')
            cmd.extend([
                "libtool", "execute", "valgrind", "-q", "--tool=memcheck",
                "--leak-check=full", "--show-reachable=yes",
                "--suppressions=%s" % suppfile
            ])
        cmd.extend([
            pacman["bin"], "--config",
            os.path.join(self.root, util.PACCONF), "--root", self.root,
            "--dbpath",
            os.path.join(self.root, util.PM_DBPATH), "--cachedir",
            os.path.join(self.root, util.PM_CACHEDIR)
        ])
        if not pacman["manual-confirm"]:
            cmd.append("--noconfirm")
        if pacman["debug"]:
            cmd.append("--debug=%s" % pacman["debug"])
        cmd.extend(shlex.split(self.args))
        if not (pacman["gdb"] or pacman["valgrind"] or pacman["nolog"]):
            output = open(os.path.join(self.root, util.LOGFILE), 'w')
        else:
            output = None
        vprint("\trunning: %s" % " ".join(cmd))

        # Change to the tmp dir before running pacman, so that local package
        # archives are made available more easily.
        time_start = time.time()
        self.retcode = subprocess.call(cmd,
                                       stdout=output,
                                       stderr=output,
                                       cwd=os.path.join(
                                           self.root, util.TMPDIR),
                                       env={'LC_ALL': 'C'})
        time_end = time.time()
        vprint("\ttime elapsed: %.2fs" % (time_end - time_start))

        if output:
            output.close()

        vprint("\tretcode = %s" % self.retcode)

        # Check if the lock is still there
        if os.path.isfile(util.PM_LOCK):
            tap.diag("\tERROR: %s not removed" % util.PM_LOCK)
            os.unlink(util.PM_LOCK)
        # Look for a core file
        if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")):
            tap.diag("\tERROR: pacman dumped a core file")