diff options
author | Aaron Griffin <aaron@archlinux.org> | 2007-02-21 06:33:13 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2007-02-21 06:33:13 +0000 |
commit | 786cd38c0a1cfeff96e5c755852a7e1c7f5e7d75 (patch) | |
tree | 3dbf7d7a1a314665602df9e1c0465afd3f2728e1 /pactest | |
parent | a8dd8d5770094ad8c925a56d47c3607c96363a51 (diff) |
* Indentation changes - 4 spaces for python, we standardized this before (and
it's a PEP)
* Modified some sync tests
Diffstat (limited to 'pactest')
-rwxr-xr-x | pactest/pactest.py | 67 | ||||
-rwxr-xr-x | pactest/pmdb.py | 645 | ||||
-rwxr-xr-x | pactest/pmenv.py | 177 | ||||
-rwxr-xr-x | pactest/pmfile.py | 55 | ||||
-rwxr-xr-x | pactest/pmpkg.py | 297 | ||||
-rwxr-xr-x | pactest/pmrule.py | 199 | ||||
-rwxr-xr-x | pactest/pmtest.py | 437 | ||||
-rw-r--r-- | pactest/tests/sync897.py | 1 | ||||
-rw-r--r-- | pactest/tests/sync899.py | 2 | ||||
-rwxr-xr-x | pactest/util.py | 319 |
10 files changed, 1104 insertions, 1095 deletions
diff --git a/pactest/pactest.py b/pactest/pactest.py index 2f7358ac..d9227ba4 100755 --- a/pactest/pactest.py +++ b/pactest/pactest.py @@ -32,42 +32,43 @@ __version__ = "0.3" def usage(retcode): - """ - """ - print "Usage: %s [options] [[--test=<path/to/testfile.py>] ...]\n\n" % __file__ - sys.exit(retcode) + """ + """ + print "Usage: %s [options] [[--test=<path/to/testfile.py>] ...]\n\n" % __file__ + sys.exit(retcode) if __name__ == "__main__": - env = pmenv.pmenv() - testcases = [] + env = pmenv.pmenv() + testcases = [] - try: - opts, args = getopt.getopt(sys.argv[1:], - "d:hp:t:v", - ["debug=", "gdb", "help", "pacman=", "test=", "valgrind", "verbose", "nolog"]) - except getopt.GetoptError: - usage(1) + try: + opts, args = getopt.getopt(sys.argv[1:], + "d:hp:t:v", + ["debug=", "gdb", "help", "pacman=", "test=", "valgrind", "verbose", "nolog"]) + except getopt.GetoptError: + usage(1) - for (cmd, param) in opts: - if cmd == "-v" or cmd == "--verbose": - util.verbose += 1 - elif cmd == "-d" or cmd == "--debug": - env.pacman["debug"] = int(param) - elif cmd == "-t" or cmd == "--test": - testcases.extend(glob.glob(param)) - elif cmd == "-p" or cmd == "--pacman": - env.pacman["bin"] = os.path.abspath(param) - elif cmd == "-h" or cmd == "--help": - usage(0) - elif cmd == "--nolog": - env.pacman["nolog"] = 1 - elif cmd == "--gdb": - env.pacman["gdb"] = 1 - elif cmd == "--valgrind": - env.pacman["valgrind"] = 1 + for (cmd, param) in opts: + if cmd == "-v" or cmd == "--verbose": + util.verbose += 1 + elif cmd == "-d" or cmd == "--debug": + env.pacman["debug"] = int(param) + elif cmd == "-t" or cmd == "--test": + testcases.extend(glob.glob(param)) + elif cmd == "-p" or cmd == "--pacman": + env.pacman["bin"] = os.path.abspath(param) + elif cmd == "-h" or cmd == "--help": + usage(0) + elif cmd == "--nolog": + env.pacman["nolog"] = 1 + elif cmd == "--gdb": + env.pacman["gdb"] = 1 + elif cmd == "--valgrind": + env.pacman["valgrind"] = 1 - for i in testcases: - env.addtest(i) + for i in testcases: + env.addtest(i) - env.run() - env.results() + env.run() + env.results() +# vim: set ts=4 sw=4 et: diff --git a/pactest/pmdb.py b/pactest/pmdb.py index ebac9372..1d5f7459 100755 --- a/pactest/pmdb.py +++ b/pactest/pmdb.py @@ -27,337 +27,338 @@ from util import * def _mkfilelist(files): - """Generate a list of files from the list supplied as an argument. - - Each path is decomposed to generate the list of all directories leading - to the file. - - Example with 'usr/local/bin/dummy': - The resulting list will be - usr/ - usr/local/ - usr/local/bin/ - usr/local/bin/dummy - """ - i = [] - for f in files: - dir = getfilename(f) - i.append(dir) - while "/" in dir: - [dir, tmp] = dir.rsplit("/", 1) - if not dir + "/" in files: - i.append(dir + "/") - i.sort() - return i + """Generate a list of files from the list supplied as an argument. + + Each path is decomposed to generate the list of all directories leading + to the file. + + Example with 'usr/local/bin/dummy': + The resulting list will be + usr/ + usr/local/ + usr/local/bin/ + usr/local/bin/dummy + """ + i = [] + for f in files: + dir = getfilename(f) + i.append(dir) + while "/" in dir: + [dir, tmp] = dir.rsplit("/", 1) + if not dir + "/" in files: + i.append(dir + "/") + i.sort() + return i def _mkbackuplist(backup): - """ - """ - return ["%s\t%s" % (getfilename(i), mkmd5sum(i)) for i in backup] + """ + """ + return ["%s\t%s" % (getfilename(i), mkmd5sum(i)) for i in backup] def _getsection(fd): - """ - """ - i = [] - while 1: - line = fd.readline().strip("\n") - if not line: - break - i.append(line) - return i + """ + """ + i = [] + while 1: + line = fd.readline().strip("\n") + if not line: + break + i.append(line) + return i def _mksection(title, data): - """ - """ - s = "" - if isinstance(data, list): - s = "\n".join(data) - else: - s = data - return "%%%s%%\n" \ - "%s\n" % (title, s) + """ + """ + s = "" + if isinstance(data, list): + s = "\n".join(data) + else: + s = data + return "%%%s%%\n" \ + "%s\n" % (title, s) class pmdb: - """Database object - """ - - def __init__(self, treename, dbdir): - self.treename = treename - self.dbdir = dbdir - self.pkgs = [] - - def __str__(self): - return "%s" % self.treename - - def getpkg(self, name): - """ - """ - for pkg in self.pkgs: - if name == pkg.name: - return pkg - - def db_read(self, name): - """ - """ - - path = os.path.join(self.dbdir, self.treename) - if not os.path.isdir(path): - return None - - dbentry = "" - for roots, dirs, files in os.walk(path): - for i in dirs: - [pkgname, pkgver, pkgrel] = i.rsplit("-", 2) - if pkgname == name: - dbentry = i - break - if not dbentry: - return None - path = os.path.join(path, dbentry) - - [pkgname, pkgver, pkgrel] = dbentry.rsplit("-", 2) - pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel) - - # desc - filename = os.path.join(path, "desc") - fd = file(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%": - pkg.reason = int(fd.readline().strip("\n")) - elif line == "%SIZE%" or line == "%CSIZE%": - pkg.size = int(fd.readline().strip("\n")) - elif line == "%MD5SUM%": - pkg.md5sum = fd.readline().strip("\n") - elif line == "%REPLACES%": - pkg.replaces = _getsection(fd) - elif line == "%FORCE%": - fd.readline() - pkg.force = 1 - fd.close() - pkg.checksum["desc"] = getmd5sum(filename) - pkg.mtime["desc"] = getmtime(filename) - - # files - filename = os.path.join(path, "files") - fd = file(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() - pkg.checksum["files"] = getmd5sum(filename) - pkg.mtime["files"] = getmtime(filename) - - # depends - filename = os.path.join(path, "depends") - fd = file(filename, "r") - while 1: - line = fd.readline() - if not line: - break - line = line.strip("\n") - if line == "%DEPENDS%": - pkg.depends = _getsection(fd) - elif line == "%REQUIREDBY%": - pkg.requiredby = _getsection(fd) - elif line == "%CONFLICTS%": - pkg.conflicts = _getsection(fd) - elif line == "%PROVIDES%": - pkg.provides = _getsection(fd) - elif line == "%REPLACES%": - pkg.replaces = _getsection(fd) - elif line == "%FORCE%": - fd.readline() - pkg.force = 1 - fd.close() - pkg.checksum["depends"] = getmd5sum(filename) - pkg.mtime["depends"] = getmtime(filename) - - # install - filename = os.path.join(path, "install") - if os.path.isfile(filename): - pkg.checksum["install"] = getmd5sum(filename) - pkg.mtime["install"] = getmtime(filename) - - return pkg - - # - # db_write is used to add both 'local' and 'sync' db entries - # - def db_write(self, pkg): - """ - """ - - path = os.path.join(self.dbdir, self.treename, pkg.fullname()) - if not os.path.isdir(path): - os.makedirs(path); - - # desc - # for local db entries: name, version, desc, groups, url, license, - # arch, builddate, installdate, packager, - # size, reason - # for sync entries: name, version, desc, groups, csize, md5sum, - # replaces, force - data = [_mksection("NAME", pkg.name)] - data.append(_mksection("VERSION", pkg.version)) - if pkg.desc: - data.append(_mksection("DESC", pkg.desc)) - if pkg.groups: - data.append(_mksection("GROUPS", pkg.groups)) - if self.treename == "local": - if pkg.url: - data.append(_mksection("URL", pkg.url)) - if pkg.license: - data.append(_mksection("LICENSE", pkg.license)) - if pkg.arch: - data.append(_mksection("ARCH", pkg.arch)) - if pkg.builddate: - data.append(_mksection("BUILDDATE", pkg.builddate)) - if pkg.installdate: - data.append(_mksection("INSTALLDATE", pkg.installdate)) - if pkg.packager: - data.append(_mksection("PACKAGER", pkg.packager)) - if pkg.size: - data.append(_mksection("SIZE", pkg.size)) - if pkg.reason: - data.append(_mksection("REASON", pkg.reason)) - else: - if pkg.csize: - data.append(_mksection("CSIZE", pkg.csize)) - if pkg.md5sum: - data.append(_mksection("MD5SUM", pkg.md5sum)) - if data: - data.append("") - filename = os.path.join(path, "desc") - mkfile(filename, "\n".join(data)) - pkg.checksum["desc"] = getmd5sum(filename) - pkg.mtime["desc"] = getmtime(filename) - - # files - # for local entries, fields are: files, backup - # for sync ones: none - if self.treename == "local": - data = [] - if pkg.files: - data.append(_mksection("FILES", _mkfilelist(pkg.files))) - if pkg.backup: - data.append(_mksection("BACKUP", _mkbackuplist(pkg.backup))) - if data: - data.append("") - filename = os.path.join(path, "files") - mkfile(filename, "\n".join(data)) - pkg.checksum["files"] = getmd5sum(filename) - pkg.mtime["files"] = getmtime(filename) - - # depends - # for local db entries: depends, requiredby, conflicts, provides - # for sync ones: depends, conflicts, provides - data = [] - if pkg.depends: - data.append(_mksection("DEPENDS", pkg.depends)) - if self.treename == "local": - if pkg.requiredby: - data.append(_mksection("REQUIREDBY", pkg.requiredby)) - if pkg.conflicts: - data.append(_mksection("CONFLICTS", pkg.conflicts)) - if pkg.provides: - data.append(_mksection("PROVIDES", pkg.provides)) - if not self.treename == "local": - if pkg.replaces: - data.append(_mksection("REPLACES", pkg.replaces)) - if pkg.force: - data.append(_mksection("FORCE", "")) - if data: - data.append("") - filename = os.path.join(path, "depends") - mkfile(filename, "\n".join(data)) - pkg.checksum["depends"] = getmd5sum(filename) - pkg.mtime["depends"] = getmtime(filename) - - # install - if self.treename == "local": - empty = 1 - for value in pkg.install.values(): - if value: - empty = 0 - if not empty: - filename = os.path.join(path, "install") - mkinstallfile(filename, pkg.install) - pkg.checksum["install"] = getmd5sum(filename) - pkg.mtime["install"] = getmtime(filename) - - def gensync(self, path): - """ - """ - - curdir = os.getcwd() - tmpdir = tempfile.mkdtemp() - os.chdir(tmpdir) - - for pkg in self.pkgs: - mkdescfile(pkg.fullname(), pkg) - - # Generate database archive - os.makedirs(path, 0755) - archive = os.path.join(path, "%s%s" % (self.treename, PM_EXT_DB)) - os.system("tar zcf %s *" % archive) - - os.chdir(curdir) - shutil.rmtree(tmpdir) - - def ispkgmodified(self, pkg): - """ - """ - - modified = 0 - - oldpkg = self.getpkg(pkg.name) - if not oldpkg: - return 0 - - dbg("oldpkg.checksum : %s" % oldpkg.checksum) - dbg("oldpkg.mtime : %s" % oldpkg.mtime) - - for key in pkg.mtime.keys(): - if key == "install" \ - and oldpkg.mtime[key] == (0, 0, 0) \ - and pkg.mtime[key] == (0, 0, 0): - continue - if not oldpkg.mtime[key][1:3] == pkg.mtime[key][1:3]: - modified += 1 - - return modified + """Database object + """ + + def __init__(self, treename, dbdir): + self.treename = treename + self.dbdir = dbdir + self.pkgs = [] + + def __str__(self): + return "%s" % self.treename + + def getpkg(self, name): + """ + """ + for pkg in self.pkgs: + if name == pkg.name: + return pkg + + def db_read(self, name): + """ + """ + + path = os.path.join(self.dbdir, self.treename) + if not os.path.isdir(path): + return None + + dbentry = "" + for roots, dirs, files in os.walk(path): + for i in dirs: + [pkgname, pkgver, pkgrel] = i.rsplit("-", 2) + if pkgname == name: + dbentry = i + break + if not dbentry: + return None + path = os.path.join(path, dbentry) + + [pkgname, pkgver, pkgrel] = dbentry.rsplit("-", 2) + pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel) + + # desc + filename = os.path.join(path, "desc") + fd = file(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%": + pkg.reason = int(fd.readline().strip("\n")) + elif line == "%SIZE%" or line == "%CSIZE%": + pkg.size = int(fd.readline().strip("\n")) + elif line == "%MD5SUM%": + pkg.md5sum = fd.readline().strip("\n") + elif line == "%REPLACES%": + pkg.replaces = _getsection(fd) + elif line == "%FORCE%": + fd.readline() + pkg.force = 1 + fd.close() + pkg.checksum["desc"] = getmd5sum(filename) + pkg.mtime["desc"] = getmtime(filename) + + # files + filename = os.path.join(path, "files") + fd = file(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() + pkg.checksum["files"] = getmd5sum(filename) + pkg.mtime["files"] = getmtime(filename) + + # depends + filename = os.path.join(path, "depends") + fd = file(filename, "r") + while 1: + line = fd.readline() + if not line: + break + line = line.strip("\n") + if line == "%DEPENDS%": + pkg.depends = _getsection(fd) + elif line == "%REQUIREDBY%": + pkg.requiredby = _getsection(fd) + elif line == "%CONFLICTS%": + pkg.conflicts = _getsection(fd) + elif line == "%PROVIDES%": + pkg.provides = _getsection(fd) + elif line == "%REPLACES%": + pkg.replaces = _getsection(fd) + elif line == "%FORCE%": + fd.readline() + pkg.force = 1 + fd.close() + pkg.checksum["depends"] = getmd5sum(filename) + pkg.mtime["depends"] = getmtime(filename) + + # install + filename = os.path.join(path, "install") + if os.path.isfile(filename): + pkg.checksum["install"] = getmd5sum(filename) + pkg.mtime["install"] = getmtime(filename) + + return pkg + + # + # db_write is used to add both 'local' and 'sync' db entries + # + def db_write(self, pkg): + """ + """ + + path = os.path.join(self.dbdir, self.treename, pkg.fullname()) + if not os.path.isdir(path): + os.makedirs(path); + + # desc + # for local db entries: name, version, desc, groups, url, license, + # arch, builddate, installdate, packager, + # size, reason + # for sync entries: name, version, desc, groups, csize, md5sum, + # replaces, force + data = [_mksection("NAME", pkg.name)] + data.append(_mksection("VERSION", pkg.version)) + if pkg.desc: + data.append(_mksection("DESC", pkg.desc)) + if pkg.groups: + data.append(_mksection("GROUPS", pkg.groups)) + if self.treename == "local": + if pkg.url: + data.append(_mksection("URL", pkg.url)) + if pkg.license: + data.append(_mksection("LICENSE", pkg.license)) + if pkg.arch: + data.append(_mksection("ARCH", pkg.arch)) + if pkg.builddate: + data.append(_mksection("BUILDDATE", pkg.builddate)) + if pkg.installdate: + data.append(_mksection("INSTALLDATE", pkg.installdate)) + if pkg.packager: + data.append(_mksection("PACKAGER", pkg.packager)) + if pkg.size: + data.append(_mksection("SIZE", pkg.size)) + if pkg.reason: + data.append(_mksection("REASON", pkg.reason)) + else: + if pkg.csize: + data.append(_mksection("CSIZE", pkg.csize)) + if pkg.md5sum: + data.append(_mksection("MD5SUM", pkg.md5sum)) + if data: + data.append("") + filename = os.path.join(path, "desc") + mkfile(filename, "\n".join(data)) + pkg.checksum["desc"] = getmd5sum(filename) + pkg.mtime["desc"] = getmtime(filename) + + # files + # for local entries, fields are: files, backup + # for sync ones: none + if self.treename == "local": + data = [] + if pkg.files: + data.append(_mksection("FILES", _mkfilelist(pkg.files))) + if pkg.backup: + data.append(_mksection("BACKUP", _mkbackuplist(pkg.backup))) + if data: + data.append("") + filename = os.path.join(path, "files") + mkfile(filename, "\n".join(data)) + pkg.checksum["files"] = getmd5sum(filename) + pkg.mtime["files"] = getmtime(filename) + + # depends + # for local db entries: depends, requiredby, conflicts, provides + # for sync ones: depends, conflicts, provides + data = [] + if pkg.depends: + data.append(_mksection("DEPENDS", pkg.depends)) + if self.treename == "local": + if pkg.requiredby: + data.append(_mksection("REQUIREDBY", pkg.requiredby)) + if pkg.conflicts: + data.append(_mksection("CONFLICTS", pkg.conflicts)) + if pkg.provides: + data.append(_mksection("PROVIDES", pkg.provides)) + if not self.treename == "local": + if pkg.replaces: + data.append(_mksection("REPLACES", pkg.replaces)) + if pkg.force: + data.append(_mksection("FORCE", "")) + if data: + data.append("") + filename = os.path.join(path, "depends") + mkfile(filename, "\n".join(data)) + pkg.checksum["depends"] = getmd5sum(filename) + pkg.mtime["depends"] = getmtime(filename) + + # install + if self.treename == "local": + empty = 1 + for value in pkg.install.values(): + if value: + empty = 0 + if not empty: + filename = os.path.join(path, "install") + mkinstallfile(filename, pkg.install) + pkg.checksum["install"] = getmd5sum(filename) + pkg.mtime["install"] = getmtime(filename) + + def gensync(self, path): + """ + """ + + curdir = os.getcwd() + tmpdir = tempfile.mkdtemp() + os.chdir(tmpdir) + + for pkg in self.pkgs: + mkdescfile(pkg.fullname(), pkg) + + # Generate database archive + os.makedirs(path, 0755) + archive = os.path.join(path, "%s%s" % (self.treename, PM_EXT_DB)) + os.system("tar zcf %s *" % archive) + + os.chdir(curdir) + shutil.rmtree(tmpdir) + + def ispkgmodified(self, pkg): + """ + """ + + modified = 0 + + oldpkg = self.getpkg(pkg.name) + if not oldpkg: + return 0 + + #dbg("oldpkg.checksum : %s" % oldpkg.checksum) + #dbg("oldpkg.mtime : %s" % oldpkg.mtime) + + for key in pkg.mtime.keys(): + if key == "install" \ + and oldpkg.mtime[key] == (0, 0, 0) \ + and pkg.mtime[key] == (0, 0, 0): + continue + if not oldpkg.mtime[key][1:3] == pkg.mtime[key][1:3]: + modified += 1 + + return modified if __name__ == "__main__": - db = pmdb("local") - print db + db = pmdb("local") + print db +# vim: set ts=4 sw=4 et: diff --git a/pactest/pmenv.py b/pactest/pmenv.py index 5093612c..1665c522 100755 --- a/pactest/pmenv.py +++ b/pactest/pmenv.py @@ -25,94 +25,95 @@ import pmtest class pmenv: - """Environment object - """ - - def __init__(self, root = "root"): - self.root = os.path.abspath(root) - self.pacman = { - "bin": "pacman", - "debug": 0, - "gdb": 0, - "valgrind": 0, - "nolog": 0 - } - self.testcases = [] - - def __str__(self): - return "root = %s\n" \ - "pacman = %s" \ - % (self.root, self.pacman) - - def addtest(self, testcase): - """ - """ - if not os.path.isfile(testcase): - err("file %s not found" % testcase) - return - test = pmtest.pmtest(testcase, self.root) - self.testcases.append(test) - - def run(self): - """ - """ - - for t in self.testcases: - print "=========="*8 - print "Running '%s'" % t.name.strip(".py") - - t.load() - print t.description - print "----------"*8 - - t.generate() - # Hack for mtimes consistency - modified = 0 - for i in t.rules: - if i.rule.find("MODIFIED") != -1: - modified = 1 - if modified: - time.sleep(3) - - t.run(self.pacman) - - t.check() - print "==> Test result" - if t.result["ko"] == 0: - print "\tPASSED" - else: - print "\tFAILED" - print - - def results(self): - """ - """ - passed = 0 - print "=========="*8 - print "Results" - print "----------"*8 - for test in self.testcases: - ok = test.result["ok"] - ko = test.result["ko"] - rules = len(test.rules) - if ko == 0: - print "[PASSED]", - passed += 1 - else: - print "[FAILED]", - print test.name.strip(".py").ljust(38), - print "Rules:", - print "OK = %2u KO = %2u SKIP = %2u" % (ok, ko, rules-(ok+ko)) - print "----------"*8 - total = len(self.testcases) - failed = total - passed - print "TOTAL = %3u" % total - if total: - print "PASSED = %3u (%6.2f%%)" % (passed, float(passed)*100/total) - print "FAILED = %3u (%6.2f%%)" % (failed, float(failed)*100/total) - print + """Environment object + """ + + def __init__(self, root = "root"): + self.root = os.path.abspath(root) + self.pacman = { + "bin": "pacman", + "debug": 0, + "gdb": 0, + "valgrind": 0, + "nolog": 0 + } + self.testcases = [] + + def __str__(self): + return "root = %s\n" \ + "pacman = %s" \ + % (self.root, self.pacman) + + def addtest(self, testcase): + """ + """ + if not os.path.isfile(testcase): + err("file %s not found" % testcase) + return + test = pmtest.pmtest(testcase, self.root) + self.testcases.append(test) + + def run(self): + """ + """ + + for t in self.testcases: + print "=========="*8 + print "Running '%s'" % t.name.strip(".py") + + t.load() + print t.description + print "----------"*8 + + t.generate() + # Hack for mtimes consistency + modified = 0 + for i in t.rules: + if i.rule.find("MODIFIED") != -1: + modified = 1 + if modified: + time.sleep(3) + + t.run(self.pacman) + + t.check() + print "==> Test result" + if t.result["fail"] == 0: + print "\tPASSED" + else: + print "\tFAILED" + print + + def results(self): + """ + """ + passed = 0 + print "=========="*8 + print "Results" + print "----------"*8 + for test in self.testcases: + success = test.result["success"] + fail = test.result["fail"] + rules = len(test.rules) + if fail == 0: + print "[PASSED]", + passed += 1 + else: + print "[FAILED]", + print test.name.strip(".py").ljust(38), + print "Rules:", + print " OK = %2u FAIL = %2u SKIP = %2u" % (success, fail, rules-(success+fail)) + print "----------"*8 + total = len(self.testcases) + failed = total - passed + print "TOTAL = %3u" % total + if total: + print "PASSED = %3u (%6.2f%%)" % (passed, float(passed)*100/total) + print "FAILED = %3u (%6.2f%%)" % (failed, float(failed)*100/total) + print if __name__ == "__main__": - env = pmenv("/tmp") - print env + env = pmenv("/tmp") + print env +# vim: set ts=4 sw=4 et: diff --git a/pactest/pmfile.py b/pactest/pmfile.py index d78b09fa..597c0992 100755 --- a/pactest/pmfile.py +++ b/pactest/pmfile.py @@ -24,42 +24,43 @@ from util import * class pmfile: - """File object - """ + """File object + """ - def __init__(self, root, name): - self.name = name - self.root = root + def __init__(self, root, name): + self.name = name + self.root = root - filename = os.path.join(self.root, self.name) - self.checksum = getmd5sum(filename) - self.mtime = getmtime(filename) + filename = os.path.join(self.root, self.name) + self.checksum = getmd5sum(filename) + self.mtime = getmtime(filename) - def __str__(self): - return "%s (%s / %lu)" % (self.name, self.checksum, self.mtime) + def __str__(self): + return "%s (%s / %lu)" % (self.name, self.checksum, self.mtime) - def ismodified(self): - """ - """ + def ismodified(self): + """ + """ - retval = 0 + retval = 0 - filename = os.path.join(self.root, self.name) - checksum = getmd5sum(filename) - mtime = getmtime(filename) + filename = os.path.join(self.root, self.name) + checksum = getmd5sum(filename) + mtime = getmtime(filename) - if debug: - print "ismodified(%s)" % self.name - print "old: %s / %s" % (self.checksum, self.mtime) - print "new: %s / %s" % (checksum, mtime) + if debug: + print "ismodified(%s)" % self.name + print "old: %s / %s" % (self.checksum, self.mtime) + print "new: %s / %s" % (checksum, mtime) - if not self.checksum == checksum \ - or not (self.mtime[1], self.mtime[2]) == (mtime[1], mtime[2]): - retval = 1 + if not self.checksum == checksum \ + or not (self.mtime[1], self.mtime[2]) == (mtime[1], mtime[2]): + retval = 1 - return retval + return retval if __name__ == "__main__": - f = pmfile("/tmp", "foobar") - print f + f = pmfile("/tmp", "foobar") + print f +# vim: set ts=4 sw=4 et: diff --git a/pactest/pmpkg.py b/pactest/pmpkg.py index b2a28f96..22adaeb8 100755 --- a/pactest/pmpkg.py +++ b/pactest/pmpkg.py @@ -27,154 +27,155 @@ from util import * class pmpkg: - """Package object. - - Object holding data from an ArchLinux package. - """ - - def __init__(self, name, version = "1.0-1"): - # desc - self.name = name - self.version = version - self.desc = "" - self.groups = [] - self.url = "" - self.license = [] - self.arch = "" - self.builddate = "" - self.installdate = "" - self.packager = "" - self.size = 0 - self.csize = 0 - self.reason = 0 - self.md5sum = "" # sync only - self.replaces = [] # sync only (will be moved to depends) - self.force = 0 # sync only (will be moved to depends) - # depends - self.depends = [] - self.requiredby = [] # local only - self.conflicts = [] - self.provides = [] - # files - self.files = [] - self.backup = [] - # install - self.install = { - "pre_install": "", - "post_install": "", - "pre_remove": "", - "post_remove": "", - "pre_upgrade": "", - "post_upgrade": "" - } - self.checksum = { - "desc": "", - "depends": "", - "files": "", - "install": "" - } - self.mtime = { - "desc": (0, 0, 0), - "depends": (0, 0, 0), - "files": (0, 0, 0), - "install": (0, 0, 0) - } - - def __str__(self): - s = ["%s" % self.fullname()] - s.append("description: %s" % self.desc) - s.append("url: %s" % self.url) - s.append("depends: %s" % " ".join(self.depends)) - s.append("files: %s" % " ".join(self.files)) - s.append("reason: %d" % self.reason) - return "\n".join(s) - - def fullname(self): - """Long name of a package. - - Returns a string formatted as follows: "pkgname-pkgver". - """ - return "%s-%s" % (self.name, self.version) - - def filename(self): - """File name of a package, including its extension. - - Returns a string formatted as follows: "pkgname-pkgver.PKG_EXT_PKG". - """ - return "%s%s" % (self.fullname(), PM_EXT_PKG) - - def install_files(self, root): - """Install files in the filesystem located under "root". - - Files are created with content generated automatically. - """ - [mkfile(os.path.join(root, f), f) for f in self.files] - - def makepkg(self, path): - """Creates an ArchLinux package archive. - - A package archive is generated in the location 'path', based on the data - from the object. - """ - archive = os.path.join(path, self.filename()) - - curdir = os.getcwd() - tmpdir = tempfile.mkdtemp() - os.chdir(tmpdir) - - # Generate package file system - for f in self.files: - mkfile(f, f) - self.size += os.stat(getfilename(f))[stat.ST_SIZE] - - # .PKGINFO - data = ["pkgname = %s" % self.name] - data.append("pkgver = %s" % self.version) - data.append("pkgdesc = %s" % self.desc) - data.append("url = %s" % self.url) - data.append("builddate = %s" % self.builddate) - data.append("packager = %s" % self.packager) - data.append("size = %s" % self.size) - if self.arch: - data.append("arch = %s" % self.arch) - for i in self.license: - data.append("license = %s" % i) - for i in self.replaces: - data.append("replaces = %s" % i) - for i in self.groups: - data.append("group = %s" % i) - for i in self.depends: - data.append("depend = %s" % i) - for i in self.conflicts: - data.append("conflict = %s" % i) - for i in self.provides: - data.append("provides = %s" % i) - for i in self.backup: - data.append("backup = %s" % i) - mkfile(".PKGINFO", "\n".join(data)) - targets = ".PKGINFO" - - # .INSTALL - empty = 1 - for value in self.install.values(): - if value: - empty = 0 - if not empty: - mkinstallfile(".INSTALL", self.install) - targets += " .INSTALL" - - # .FILELIST - if self.files: - os.system("tar cvf /dev/null * | sort >.FILELIST") - targets += " .FILELIST *" - - # Generate package archive - os.system("tar zcf %s %s" % (archive, targets)) - - os.chdir(curdir) - shutil.rmtree(tmpdir) + """Package object. + + Object holding data from an ArchLinux package. + """ + + def __init__(self, name, version = "1.0-1"): + # desc + self.name = name + self.version = version + self.desc = "" + self.groups = [] + self.url = "" + self.license = [] + self.arch = "" + self.builddate = "" + self.installdate = "" + self.packager = "" + self.size = 0 + self.csize = 0 + self.reason = 0 + self.md5sum = "" # sync only + self.replaces = [] # sync only (will be moved to depends) + self.force = 0 # sync only (will be moved to depends) + # depends + self.depends = [] + self.requiredby = [] # local only + self.conflicts = [] + self.provides = [] + # files + self.files = [] + self.backup = [] + # install + self.install = { + "pre_install": "", + "post_install": "", + "pre_remove": "", + "post_remove": "", + "pre_upgrade": "", + "post_upgrade": "" + } + self.checksum = { + "desc": "", + "depends": "", + "files": "", + "install": "" + } + self.mtime = { + "desc": (0, 0, 0), + "depends": (0, 0, 0), + "files": (0, 0, 0), + "install": (0, 0, 0) + } + + def __str__(self): + s = ["%s" % self.fullname()] + s.append("description: %s" % self.desc) + s.append("url: %s" % self.url) + s.append("depends: %s" % " ".join(self.depends)) + s.append("files: %s" % " ".join(self.files)) + s.append("reason: %d" % self.reason) + return "\n".join(s) + + def fullname(self): + """Long name of a package. + + Returns a string formatted as follows: "pkgname-pkgver". + """ + return "%s-%s" % (self.name, self.version) + + def filename(self): + """File name of a package, including its extension. + + Returns a string formatted as follows: "pkgname-pkgver.PKG_EXT_PKG". + """ + return "%s%s" % (self.fullname(), PM_EXT_PKG) + + def install_files(self, root): + """Install files in the filesystem located under "root". + + Files are created with content generated automatically. + """ + [mkfile(os.path.join(root, f), f) for f in self.files] + + def makepkg(self, path): + """Creates an ArchLinux package archive. + + A package archive is generated in the location 'path', based on the data + from the object. + """ + archive = os.path.join(path, self.filename()) + + curdir = os.getcwd() + tmpdir = tempfile.mkdtemp() + os.chdir(tmpdir) + + # Generate package file system + for f in self.files: + mkfile(f, f) + self.size += os.stat(getfilename(f))[stat.ST_SIZE] + + # .PKGINFO + data = ["pkgname = %s" % self.name] + data.append("pkgver = %s" % self.version) + data.append("pkgdesc = %s" % self.desc) + data.append("url = %s" % self.url) + data.append("builddate = %s" % self.builddate) + data.append("packager = %s" % self.packager) + data.append("size = %s" % self.size) + if self.arch: + data.append("arch = %s" % self.arch) + for i in self.license: + data.append("license = %s" % i) + for i in self.replaces: + data.append("replaces = %s" % i) + for i in self.groups: + data.append("group = %s" % i) + for i in self.depends: + data.append("depend = %s" % i) + for i in self.conflicts: + data.append("conflict = %s" % i) + for i in self.provides: + data.append("provides = %s" % i) + for i in self.backup: + data.append("backup = %s" % i) + mkfile(".PKGINFO", "\n".join(data)) + targets = ".PKGINFO" + + # .INSTALL + empty = 1 + for value in self.install.values(): + if value: + empty = 0 + if not empty: + mkinstallfile(".INSTALL", self.install) + targets += " .INSTALL" + + # .FILELIST + if self.files: + os.system("tar cvf /dev/null * | sort >.FILELIST") + targets += " .FILELIST *" + + # Generate package archive + os.system("tar zcf %s %s" % (archive, targets)) + + os.chdir(curdir) + shutil.rmtree(tmpdir) if __name__ == "__main__": - pkg = pmpkg("dummy") - print pkg + pkg = pmpkg("dummy") + print pkg +# vim: set ts=4 sw=4 et: diff --git a/pactest/pmrule.py b/pactest/pmrule.py index ad2e8930..43310bfd 100755 --- a/pactest/pmrule.py +++ b/pactest/pmrule.py @@ -22,112 +22,113 @@ from util import * class pmrule: - """Rule object - """ + """Rule object + """ - def __init__(self, rule): - self.rule = rule - self.false = 0 - self.result = 0 + def __init__(self, rule): + self.rule = rule + self.false = 0 + self.result = 0 - def __str__(self): - return "rule = %s" % self.rule + def __str__(self): + return "rule = %s" % self.rule - def check(self, root, retcode, localdb, files): - """ - """ + def check(self, root, retcode, localdb, files): + """ + """ - success = 1 + success = 1 - [test, args] = self.rule.split("=") - if test[0] == "!": - self.false = 1 - test = test.lstrip("!") - [kind, case] = test.split("_") - if "|" in args: - [key, value] = args.split("|", 1) - else: - [key, value] = [args, None] + [test, args] = self.rule.split("=") + if test[0] == "!": + self.false = 1 + test = test.lstrip("!") + [kind, case] = test.split("_") + if "|" in args: + [key, value] = args.split("|", 1) + else: + [key, value] = [args, None] - if kind == "PACMAN": - if case == "RETCODE": - if retcode != int(key): - success = 0 - elif case == "OUTPUT": - if not grep(os.path.join(root, LOGFILE), key): - success = 0 - else: - success = -1 - elif kind == "PKG": - newpkg = localdb.db_read(key) - if not newpkg: - success = 0 - else: - dbg("newpkg.checksum : %s" % newpkg.checksum) - dbg("newpkg.mtime : %s" % newpkg.mtime) - if case == "EXIST": - success = 1 - elif case == "MODIFIED": - if not localdb.ispkgmodified(newpkg): - success = 0 - elif case == "VERSION": - if value != newpkg.version: - success = 0 - elif case == "GROUPS": - if not value in newpkg.groups: - success = 0 - elif case == "DEPENDS": - if not value in newpkg.depends: - success = 0 - elif case == "REQUIREDBY": - if not value in newpkg.requiredby: - success = 0 - elif case == "REASON": - if not newpkg.reason == int(value): - success = 0 - elif case == "FILES": - if not value in newpkg.files: - success = 0 - elif case == "BACKUP": - found = 0 - for f in newpkg.backup: - name, md5sum = f.split("\t") - if value == name: - found = 1 - if not found: - success = 0 - else: - success = -1 - elif kind == "FILE": - filename = os.path.join(root, key) - if case == "EXIST": - if not os.path.isfile(filename): - success = 0 - else: - if case == "MODIFIED": - for f in files: - if f.name == key: - if not f.ismodified(): - success = 0 - elif case == "PACNEW": - if not os.path.isfile("%s%s" % (filename, PM_PACNEW)): - success = 0 - elif case == "PACORIG": - if not os.path.isfile("%s%s" % (filename, PM_PACORIG)): - success = 0 - elif case == "PACSAVE": - if not os.path.isfile("%s%s" % (filename, PM_PACSAVE)): - success = 0 - else: - success = -1 - else: - success = -1 + if kind == "PACMAN": + if case == "RETCODE": + if retcode != int(key): + success = 0 + elif case == "OUTPUT": + if not grep(os.path.join(root, LOGFILE), key): + success = 0 + else: + success = -1 + elif kind == "PKG": + newpkg = localdb.db_read(key) + if not newpkg: + success = 0 + else: + #dbg("newpkg.checksum : %s" % newpkg.checksum) + #dbg("newpkg.mtime : %s" % newpkg.mtime) + if case == "EXIST": + success = 1 + elif case == "MODIFIED": + if not localdb.ispkgmodified(newpkg): + success = 0 + elif case == "VERSION": + if value != newpkg.version: + success = 0 + elif case == "GROUPS": + if not value in newpkg.groups: + success = 0 + elif case == "DEPENDS": + if not value in newpkg.depends: + success = 0 + elif case == "REQUIREDBY": + if not value in newpkg.requiredby: + success = 0 + elif case == "REASON": + if not newpkg.reason == int(value): + success = 0 + elif case == "FILES": + if not value in newpkg.files: + success = 0 + elif case == "BACKUP": + found = 0 + for f in newpkg.backup: + name, md5sum = f.split("\t") + if value == name: + found = 1 + if not found: + success = 0 + else: + success = -1 + elif kind == "FILE": + filename = os.path.join(root, key) + if case == "EXIST": + if not os.path.isfile(filename): + success = 0 + else: + if case == "MODIFIED": + for f in files: + if f.name == key: + if not f.ismodified(): + success = 0 + elif case == "PACNEW": + if not os.path.isfile("%s%s" % (filename, PM_PACNEW)): + success = 0 + elif case == "PACORIG": + if not os.path.isfile("%s%s" % (filename, PM_PACORIG)): + success = 0 + elif case == "PACSAVE": + if not os.path.isfile("%s%s" % (filename, PM_PACSAVE)): + success = 0 + else: + success = -1 + else: + success = -1 - if self.false and success != -1: - success = not success - self.result = success - return success + if self.false and success != -1: + success = not success + self.result = success + return success if __name__ != "__main__": - rule = pmrule("PKG_EXIST=dummy") + rule = pmrule("PKG_EXIST=dummy") +# vim: set ts=4 sw=4 et: diff --git a/pactest/pmtest.py b/pactest/pmtest.py index 830202a5..f7538e04 100755 --- a/pactest/pmtest.py +++ b/pactest/pmtest.py @@ -30,224 +30,225 @@ from util import * class pmtest: - """Test object - """ - - def __init__(self, name, root): - self.name = name - self.root = root - - def __str__(self): - return "name = %s\n" \ - "root = %s" % (self.name, self.root) - - def addpkg2db(self, treename, pkg): - """ - """ - if not treename in self.db: - self.db[treename] = pmdb.pmdb(treename, os.path.join(self.root, PM_DBPATH)) - self.db[treename].pkgs.append(pkg) - - def addpkg(self, pkg): - """ - """ - self.localpkgs.append(pkg) - - def addrule(self, rulename): - """ - """ - rule = pmrule.pmrule(rulename) - self.rules.append(rule) - - def load(self): - """ - """ - - # Reset test parameters - self.result = { - "ok": 0, - "ko": 0 - } - self.args = "" - self.retcode = 0 - self.db = { - "local": pmdb.pmdb("local", os.path.join(self.root, PM_DBPATH)) - } - self.localpkgs = [] - self.filesystem = [] - - self.description = "" - self.option = { - "noupgrade": [], - "ignorepkg": [], - "noextract": [] - } - - # Test rules - self.rules = [] - self.files = [] - - if os.path.isfile(self.name): - execfile(self.name) - else: - err("file %s does not exist!" % self.name) - - 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, PM_DBPATH) - cachedir = os.path.join(self.root, PM_CACHEDIR) - syncdir = os.path.join(self.root, SYNCREPO) - tmpdir = os.path.join(self.root, TMPDIR) - logdir = os.path.join(self.root, os.path.dirname(LOGFILE)) - etcdir = os.path.join(self.root, os.path.dirname(PACCONF)) - for dir in [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir]: - if not os.path.isdir(dir): - vprint("\t%s" % dir[len(self.root)+1:]) - os.makedirs(dir, 0755) - - # Configuration file - vprint(" Creating configuration file") - vprint("\t%s" % PACCONF) - mkcfgfile(PACCONF, self.root, self.option, self.db) - - # Creating packages - vprint(" Creating package archives") - for pkg in self.localpkgs: - vprint("\t%s" % os.path.join(TMPDIR, pkg.filename())) - pkg.makepkg(tmpdir) - for key, value in self.db.iteritems(): - if key == "local": - continue - for pkg in value.pkgs: - archive = pkg.filename() - vprint("\t%s" % os.path.join(PM_CACHEDIR, archive)) - pkg.makepkg(cachedir) - pkg.md5sum = getmd5sum(os.path.join(cachedir, archive)) - pkg.csize = os.stat(os.path.join(cachedir, archive))[stat.ST_SIZE] - - # Populating databases - vprint(" Populating databases") - for key, value in self.db.iteritems(): - for pkg in value.pkgs: - vprint("\t%s/%s" % (key, pkg.fullname())) - if key == "local": - pkg.installdate = time.ctime() - value.db_write(pkg) - - # Creating sync database archives - vprint(" Creating sync database archives") - for key, value in self.db.iteritems(): - if key == "local": - continue - archive = value.treename + PM_EXT_DB - vprint("\t" + os.path.join(SYNCREPO, archive)) - value.gensync(os.path.join(syncdir, value.treename)) - - # Filesystem - vprint(" Populating file system") - for pkg in self.db["local"].pkgs: - vprint("\tinstalling %s" % pkg.fullname()) - pkg.install_files(self.root) - for f in self.filesystem: - vprint("\t%s" % f) - mkfile(os.path.join(self.root, f), f) - - # 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.pmfile(self.root, filename.replace(self.root + "/", "")) - self.files.append(f) - vprint("\t%s" % f.name) - - def run(self, pacman): - """ - """ - - if os.path.isfile(PM_LOCK): - print "\tERROR: another pacman session is on-going -- skipping" - return - - print "==> Running test" - vprint("\tpacman %s" % self.args) - - cmd = ["fakeroot"] - if pacman["gdb"]: - cmd.append("libtool gdb --args") - if pacman["valgrind"]: - cmd.append("valgrind --tool=memcheck --leak-check=full --show-reachable=yes") - cmd.append("%s --noconfirm --config=%s --root=%s" \ - % (pacman["bin"], os.path.join(self.root, PACCONF), self.root)) - if pacman["debug"]: - cmd.append("--debug=%s" % pacman["debug"]) - cmd.append("%s" % self.args) - if not pacman["gdb"] and not pacman["valgrind"] and not pacman["nolog"]: - cmd.append(">%s 2>&1" % os.path.join(self.root, LOGFILE)) - dbg(" ".join(cmd)) - - # Change to the tmp dir before running pacman, so that local package - # archives are made available more easily. - curdir = os.getcwd() - tmpdir = os.path.join(self.root, TMPDIR) - os.chdir(tmpdir) - - t0 = time.time() - self.retcode = os.system(" ".join(cmd)) - t1 = time.time() - vprint("\ttime elapsed: %ds" % (t1-t0)) - - if self.retcode == None: - self.retcode = 0 - else: - self.retcode /= 256 - dbg("retcode = %s" % self.retcode) - os.chdir(curdir) - - # Check if pacman failed because of bad permissions - if self.retcode \ - and grep(os.path.join(self.root, LOGFILE), - "you cannot perform this operation unless you are root"): - print "\tERROR: pacman support for fakeroot is not disabled" - # Check if the lock is still there - if os.path.isfile(PM_LOCK): - print "\tERROR: %s not removed" % PM_LOCK - os.unlink(PM_LOCK) - # Look for a core file - if os.path.isfile(os.path.join(self.root, TMPDIR, "core")): - print "\tERROR: pacman dumped a core file" - - def check(self): - """ - """ - - print "==> Checking rules" - - for i in self.rules: - success = i.check(self.root, self.retcode, self.db["local"], self.files) - if success == 1: - msg = "OK" - self.result["ok"] += 1 - elif success == 0: - msg = "KO" - self.result["ko"] += 1 - else: - msg = "SKIP" - print "\t[%s] %s" % (msg, i.rule) - i.result = success + """Test object + """ + + def __init__(self, name, root): + self.name = name + self.root = root + + def __str__(self): + return "name = %s\n" \ + "root = %s" % (self.name, self.root) + + def addpkg2db(self, treename, pkg): + """ + """ + if not treename in self.db: + self.db[treename] = pmdb.pmdb(treename, os.path.join(self.root, PM_DBPATH)) + self.db[treename].pkgs.append(pkg) + + def addpkg(self, pkg): + """ + """ + self.localpkgs.append(pkg) + + def addrule(self, rulename): + """ + """ + rule = pmrule.pmrule(rulename) + self.rules.append(rule) + + def load(self): + """ + """ + + # Reset test parameters + self.result = { + "success": 0, + "fail": 0 + } + self.args = "" + self.retcode = 0 + self.db = { + "local": pmdb.pmdb("local", os.path.join(self.root, PM_DBPATH)) + } + self.localpkgs = [] + self.filesystem = [] + + self.description = "" + self.option = { + "noupgrade": [], + "ignorepkg": [], + "noextract": [] + } + + # Test rules + self.rules = [] + self.files = [] + + if os.path.isfile(self.name): + execfile(self.name) + else: + err("file %s does not exist!" % self.name) + + 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, PM_DBPATH) + cachedir = os.path.join(self.root, PM_CACHEDIR) + syncdir = os.path.join(self.root, SYNCREPO) + tmpdir = os.path.join(self.root, TMPDIR) + logdir = os.path.join(self.root, os.path.dirname(LOGFILE)) + etcdir = os.path.join(self.root, os.path.dirname(PACCONF)) + for dir in [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir]: + if not os.path.isdir(dir): + vprint("\t%s" % dir[len(self.root)+1:]) + os.makedirs(dir, 0755) + + # Configuration file + vprint(" Creating configuration file") + vprint("\t%s" % PACCONF) + mkcfgfile(PACCONF, self.root, self.option, self.db) + + # Creating packages + vprint(" Creating package archives") + for pkg in self.localpkgs: + vprint("\t%s" % os.path.join(TMPDIR, pkg.filename())) + pkg.makepkg(tmpdir) + for key, value in self.db.iteritems(): + if key == "local": + continue + for pkg in value.pkgs: + archive = pkg.filename() + vprint("\t%s" % os.path.join(PM_CACHEDIR, archive)) + pkg.makepkg(cachedir) + pkg.md5sum = getmd5sum(os.path.join(cachedir, archive)) + pkg.csize = os.stat(os.path.join(cachedir, archive))[stat.ST_SIZE] + + # Populating databases + vprint(" Populating databases") + for key, value in self.db.iteritems(): + for pkg in value.pkgs: + vprint("\t%s/%s" % (key, pkg.fullname())) + if key == "local": + pkg.installdate = time.ctime() + value.db_write(pkg) + + # Creating sync database archives + vprint(" Creating sync database archives") + for key, value in self.db.iteritems(): + if key == "local": + continue + archive = value.treename + PM_EXT_DB + vprint("\t" + os.path.join(SYNCREPO, archive)) + value.gensync(os.path.join(syncdir, value.treename)) + + # Filesystem + vprint(" Populating file system") + for pkg in self.db["local"].pkgs: + vprint("\tinstalling %s" % pkg.fullname()) + pkg.install_files(self.root) + for f in self.filesystem: + vprint("\t%s" % f) + mkfile(os.path.join(self.root, f), f) + + # 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.pmfile(self.root, filename.replace(self.root + "/", "")) + self.files.append(f) + vprint("\t%s" % f.name) + + def run(self, pacman): + """ + """ + + if os.path.isfile(PM_LOCK): + print "\tERROR: another pacman session is on-going -- skipping" + return + + print "==> Running test" + vprint("\tpacman %s" % self.args) + + cmd = ["fakeroot"] + if pacman["gdb"]: + cmd.append("libtool gdb --args") + if pacman["valgrind"]: + cmd.append("valgrind --tool=memcheck --leak-check=full --show-reachable=yes") + cmd.append("%s --noconfirm --config=%s --root=%s" \ + % (pacman["bin"], os.path.join(self.root, PACCONF), self.root)) + if pacman["debug"]: + cmd.append("--debug=%s" % pacman["debug"]) + cmd.append("%s" % self.args) + if not pacman["gdb"] and not pacman["valgrind"] and not pacman["nolog"]: + cmd.append(">%s 2>&1" % os.path.join(self.root, LOGFILE)) + dbg(" ".join(cmd)) + + # Change to the tmp dir before running pacman, so that local package + # archives are made available more easily. + curdir = os.getcwd() + tmpdir = os.path.join(self.root, TMPDIR) + os.chdir(tmpdir) + + t0 = time.time() + self.retcode = os.system(" ".join(cmd)) + t1 = time.time() + vprint("\ttime elapsed: %ds" % (t1-t0)) + + if self.retcode == None: + self.retcode = 0 + else: + self.retcode /= 256 + dbg("retcode = %s" % self.retcode) + os.chdir(curdir) + + # Check if pacman failed because of bad permissions + if self.retcode and not pacman["nolog"] \ + and grep(os.path.join(self.root, LOGFILE), + "you cannot perform this operation unless you are root"): + print "\tERROR: pacman support for fakeroot is not disabled" + # Check if the lock is still there + if os.path.isfile(PM_LOCK): + print "\tERROR: %s not removed" % PM_LOCK + os.unlink(PM_LOCK) + # Look for a core file + if os.path.isfile(os.path.join(self.root, TMPDIR, "core")): + print "\tERROR: pacman dumped a core file" + + def check(self): + """ + """ + + print "==> Checking rules" + + for i in self.rules: + success = i.check(self.root, self.retcode, self.db["local"], self.files) + if success == 1: + msg = " OK " + self.result["success"] += 1 + elif success == 0: + msg = "FAIL" + self.result["fail"] += 1 + else: + msg = "SKIP" + print "\t[%s] %s" % (msg, i.rule) + i.result = success if __name__ == "__main__": - test = pmtest("test1", "./root") - print test + test = pmtest("test1", "./root") + print test +# vim: set ts=4 sw=4 et: diff --git a/pactest/tests/sync897.py b/pactest/tests/sync897.py index adaaa1c2..0a5433cd 100644 --- a/pactest/tests/sync897.py +++ b/pactest/tests/sync897.py @@ -24,3 +24,4 @@ self.args = "-Su" self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") self.addrule("!PKG_EXIST=pkg2") +self.addrule("!PKG_EXIST=pkg3") diff --git a/pactest/tests/sync899.py b/pactest/tests/sync899.py index 698c93ea..a561ae63 100644 --- a/pactest/tests/sync899.py +++ b/pactest/tests/sync899.py @@ -1,4 +1,4 @@ -self.description = "System upgrade" +self.description = "System upgrade - conflict/provide with an installed package" sp1 = pmpkg("pkg1", "1.0-2") sp1.conflicts = ["pkg2"] diff --git a/pactest/util.py b/pactest/util.py index d7bb8c8e..94c5f5cf 100755 --- a/pactest/util.py +++ b/pactest/util.py @@ -49,16 +49,16 @@ debug = 1 def err(msg): - print "error: " + msg - sys.exit(1) + print "error: " + msg + sys.exit(1) def vprint(msg): - if verbose: - print msg + if verbose: + print msg def dbg(msg): - if debug: - print msg + if debug: + print msg # @@ -66,133 +66,133 @@ def dbg(msg): # def getfilename(name): - """ - """ - filename = "" - link = "" - if not name.find(" -> ") == -1: - filename, link = name.split(" -> ") - elif name[-1] == "*": - filename = name.rstrip("*") - else: - filename = name - return filename + """ + """ + filename = "" + link = "" + if not name.find(" -> ") == -1: + filename, link = name.split(" -> ") + elif name[-1] == "*": + filename = name.rstrip("*") + else: + filename = name + return filename def mkfile(name, data = ""): - """ - """ - - isaltered = 0 - isdir = 0 - islink = 0 - link = "" - filename = "" - - if not name.find(" -> ") == -1: - islink = 1 - filename, link = name.split(" -> ") - elif name[-1] == "*": - isaltered = 1 - filename = name.rstrip("*") - else: - filename = name - if name[-1] == "/": - isdir = 1 - - if isdir: - path = filename - else: - path = os.path.dirname(filename) - try: - if path and not os.path.isdir(path): - os.makedirs(path, 0755) - except: - error("mkfile: could not create directory hierarchy '%s'" % path) - - if isdir: - return - if islink: - curdir = os.getcwd() - os.chdir(path) - os.symlink(link, os.path.basename(filename)) - os.chdir(curdir) - else: - fd = file(filename, "w") - if data: - fd.write(data) - if data[-1] != "\n": - fd.write("\n") - fd.close() + """ + """ + + isaltered = 0 + isdir = 0 + islink = 0 + link = "" + filename = "" + + if not name.find(" -> ") == -1: + islink = 1 + filename, link = name.split(" -> ") + elif name[-1] == "*": + isaltered = 1 + filename = name.rstrip("*") + else: + filename = name + if name[-1] == "/": + isdir = 1 + + if isdir: + path = filename + else: + path = os.path.dirname(filename) + try: + if path and not os.path.isdir(path): + os.makedirs(path, 0755) + except: + error("mkfile: could not create directory hierarchy '%s'" % path) + + if isdir: + return + if islink: + curdir = os.getcwd() + os.chdir(path) + os.symlink(link, os.path.basename(filename)) + os.chdir(curdir) + else: + fd = file(filename, "w") + if data: + fd.write(data) + if data[-1] != "\n": + fd.write("\n") + fd.close() def mkdescfile(filename, pkg): - """ - """ - - data = [] - - # desc - #data.append("pkgname = %s" % pkg.name) - #data.append("pkgver = %s" % pkg.version) - if pkg.desc: - data.append("pkgdesc = %s" % pkg.desc) - if pkg.url: - data.append("url = %s" % pkg.url) - if pkg.builddate: - data.append("builddate = %s" % pkg.builddate) - if pkg.packager: - data.append("packager = %s" % pkg.packager) - if pkg.size: - data.append("size = %s" % pkg.size) - if pkg.arch: - data.append("arch = %s" % pkg.arch) - for i in pkg.groups: - data.append("group = %s" % i) - for i in pkg.license: - data.append("license = %s" % i) - if pkg.md5sum: - data.append("md5sum = %s" % pkg.md5sum) - - # depends - for i in pkg.replaces: - data.append("replaces = %s" % i) - for i in pkg.depends: - data.append("depend = %s" % i) - for i in pkg.conflicts: - data.append("conflict = %s" % i) - for i in pkg.provides: - data.append("provides = %s" % i) - for i in pkg.backup: - data.append("backup = %s" % i) - if pkg.force: - data.append("force = 1") - - mkfile(filename, "\n".join(data)) + """ + """ + + data = [] + + # desc + #data.append("pkgname = %s" % pkg.name) + #data.append("pkgver = %s" % pkg.version) + if pkg.desc: + data.append("pkgdesc = %s" % pkg.desc) + if pkg.url: + data.append("url = %s" % pkg.url) + if pkg.builddate: + data.append("builddate = %s" % pkg.builddate) + if pkg.packager: + data.append("packager = %s" % pkg.packager) + if pkg.size: + data.append("size = %s" % pkg.size) + if pkg.arch: + data.append("arch = %s" % pkg.arch) + for i in pkg.groups: + data.append("group = %s" % i) + for i in pkg.license: + data.append("license = %s" % i) + if pkg.md5sum: + data.append("md5sum = %s" % pkg.md5sum) + + # depends + for i in pkg.replaces: + data.append("replaces = %s" % i) + for i in pkg.depends: + data.append("depend = %s" % i) + for i in pkg.conflicts: + data.append("conflict = %s" % i) + for i in pkg.provides: + data.append("provides = %s" % i) + for i in pkg.backup: + data.append("backup = %s" % i) + if pkg.force: + data.append("force = 1") + + mkfile(filename, "\n".join(data)) def mkinstallfile(filename, install): - """ - """ - data = [] - for key, value in install.iteritems(): - if value: - data.append("%s() {\n%s\n}" % (key, value)) - - mkfile(filename, "\n".join(data)) + """ + """ + data = [] + for key, value in install.iteritems(): + if value: + data.append("%s() {\n%s\n}" % (key, value)) + + mkfile(filename, "\n".join(data)) def mkcfgfile(filename, root, option, db): - """ - """ - # Options - data = ["[options]"] - for key, value in option.iteritems(): - data.extend(["%s = %s" % (key, j) for j in value]) + """ + """ + # Options + data = ["[options]"] + for key, value in option.iteritems(): + data.extend(["%s = %s" % (key, j) for j in value]) - # Repositories - data.extend(["[%s]\n" \ - "server = file://%s\n" \ - % (value.treename, os.path.join(root, SYNCREPO, value.treename)) \ - for key, value in db.iteritems() if not key == "local"]) + # Repositories + data.extend(["[%s]\n" \ + "server = file://%s\n" \ + % (value.treename, os.path.join(root, SYNCREPO, value.treename)) \ + for key, value in db.iteritems() if not key == "local"]) - mkfile(os.path.join(root, filename), "\n".join(data)) + mkfile(os.path.join(root, filename), "\n".join(data)) # @@ -200,26 +200,26 @@ def mkcfgfile(filename, root, option, db): # def getmd5sum(filename): - """ - """ - fd = open(filename, "rb") - checksum = md5.new() - while 1: - block = fd.read(1048576) - if not block: - break - checksum.update(block) - fd.close() - digest = checksum.digest() - return "%02x"*len(digest) % tuple(map(ord, digest)) + """ + """ + fd = open(filename, "rb") + checksum = md5.new() + while 1: + block = fd.read(1048576) + if not block: + break + checksum.update(block) + fd.close() + digest = checksum.digest() + return "%02x"*len(digest) % tuple(map(ord, digest)) def mkmd5sum(data): - """ - """ - checksum = md5.new() - checksum.update("%s\n" % data) - digest = checksum.digest() - return "%02x"*len(digest) % tuple(map(ord, digest)) + """ + """ + checksum = md5.new() + checksum.update("%s\n" % data) + digest = checksum.digest() + return "%02x"*len(digest) % tuple(map(ord, digest)) # @@ -227,15 +227,15 @@ def mkmd5sum(data): # def getmtime(filename): - """ - """ - st = os.stat(filename) - return st[stat.ST_ATIME], st[stat.ST_MTIME], st[stat.ST_CTIME] + """ + """ + st = os.stat(filename) + return st[stat.ST_ATIME], st[stat.ST_MTIME], st[stat.ST_CTIME] def diffmtime(mt1, mt2): - """ORE: TBD - """ - return not mt1 == mt2 + """ORE: TBD + """ + return not mt1 == mt2 # @@ -243,17 +243,18 @@ def diffmtime(mt1, mt2): # def grep(filename, pattern): - found = 0 - fd = file(filename, "r") - while 1 and not found: - line = fd.readline() - if not line: - break - if line.find(pattern) != -1: - found = 1 - fd.close() - return found + found = 0 + fd = file(filename, "r") + while 1 and not found: + line = fd.readline() + if not line: + break + if line.find(pattern) != -1: + found = 1 + fd.close() + return found if __name__ == "__main__": - pass + pass +# vim: set ts=4 sw=4 et: |