2006-10-15 15:04:27 -04:00
|
|
|
# Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
|
2014-01-01 05:24:48 -05:00
|
|
|
# Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org>
|
2011-08-17 17:56:07 -04:00
|
|
|
#
|
2006-10-15 15:04:27 -04:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-11-29 23:33:45 -05:00
|
|
|
import os
|
2010-10-26 22:30:22 -04:00
|
|
|
import stat
|
|
|
|
|
2013-07-29 15:22:07 -04:00
|
|
|
import tap
|
2010-10-26 22:30:22 -04:00
|
|
|
import util
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2011-01-22 17:28:43 -05:00
|
|
|
class pmrule(object):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""Rule object
|
|
|
|
"""
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
def __init__(self, rule):
|
|
|
|
self.rule = rule
|
|
|
|
self.false = 0
|
|
|
|
self.result = 0
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
def __str__(self):
|
2013-10-09 09:48:09 -04:00
|
|
|
return self.rule
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2014-08-01 17:19:45 -04:00
|
|
|
def snapshots_needed(self):
|
|
|
|
(testname, args) = self.rule.split("=")
|
|
|
|
if testname == "FILE_MODIFIED" or testname == "!FILE_MODIFIED":
|
|
|
|
return [args]
|
|
|
|
return []
|
|
|
|
|
2011-01-29 12:23:55 -05:00
|
|
|
def check(self, test):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
success = 1
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2011-01-29 12:23:55 -05:00
|
|
|
[testname, args] = self.rule.split("=")
|
|
|
|
if testname[0] == "!":
|
2007-02-21 01:33:13 -05:00
|
|
|
self.false = 1
|
2011-07-29 19:49:38 -04:00
|
|
|
testname = testname[1:]
|
2011-01-29 12:23:55 -05:00
|
|
|
[kind, case] = testname.split("_")
|
2007-02-21 01:33:13 -05:00
|
|
|
if "|" in args:
|
|
|
|
[key, value] = args.split("|", 1)
|
|
|
|
else:
|
|
|
|
[key, value] = [args, None]
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
if kind == "PACMAN":
|
|
|
|
if case == "RETCODE":
|
2011-01-29 12:23:55 -05:00
|
|
|
if test.retcode != int(key):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = 0
|
|
|
|
elif case == "OUTPUT":
|
2011-01-29 12:23:55 -05:00
|
|
|
logfile = os.path.join(test.root, util.LOGFILE)
|
2007-11-29 23:33:45 -05:00
|
|
|
if not os.access(logfile, os.F_OK):
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("LOGFILE not found, cannot validate 'OUTPUT' rule")
|
2007-11-29 23:33:45 -05:00
|
|
|
success = 0
|
2011-01-29 12:23:55 -05:00
|
|
|
elif not util.grep(logfile, key):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = 0
|
|
|
|
else:
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("PACMAN rule '%s' not found" % case)
|
2007-02-21 01:33:13 -05:00
|
|
|
success = -1
|
|
|
|
elif kind == "PKG":
|
2011-01-29 12:23:55 -05:00
|
|
|
localdb = test.db["local"]
|
2007-02-21 01:33:13 -05:00
|
|
|
newpkg = localdb.db_read(key)
|
|
|
|
if not newpkg:
|
|
|
|
success = 0
|
|
|
|
else:
|
|
|
|
if case == "EXIST":
|
|
|
|
success = 1
|
|
|
|
elif case == "VERSION":
|
|
|
|
if value != newpkg.version:
|
|
|
|
success = 0
|
2010-12-21 13:19:26 -05:00
|
|
|
elif case == "DESC":
|
|
|
|
if value != newpkg.desc:
|
|
|
|
success = 0
|
2007-02-21 01:33:13 -05:00
|
|
|
elif case == "GROUPS":
|
|
|
|
if not value in newpkg.groups:
|
|
|
|
success = 0
|
2007-02-27 23:00:21 -05:00
|
|
|
elif case == "PROVIDES":
|
|
|
|
if not value in newpkg.provides:
|
|
|
|
success = 0
|
2007-02-21 01:33:13 -05:00
|
|
|
elif case == "DEPENDS":
|
|
|
|
if not value in newpkg.depends:
|
|
|
|
success = 0
|
2007-11-02 18:26:31 -04:00
|
|
|
elif case == "OPTDEPENDS":
|
2012-03-13 07:33:56 -04:00
|
|
|
success = 0
|
|
|
|
for optdep in newpkg.optdepends:
|
|
|
|
if value == optdep.split(':', 1)[0]:
|
|
|
|
success = 1
|
|
|
|
break
|
2007-02-21 01:33:13 -05:00
|
|
|
elif case == "REASON":
|
2007-02-28 11:37:24 -05:00
|
|
|
if newpkg.reason != int(value):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = 0
|
|
|
|
elif case == "FILES":
|
|
|
|
if not value in newpkg.files:
|
|
|
|
success = 0
|
|
|
|
elif case == "BACKUP":
|
2014-10-06 03:55:06 -04:00
|
|
|
success = 0
|
2007-02-21 01:33:13 -05:00
|
|
|
for f in newpkg.backup:
|
2014-10-06 03:55:06 -04:00
|
|
|
if f.startswith(value + "\t"):
|
|
|
|
success = 1
|
|
|
|
break;
|
2007-02-21 01:33:13 -05:00
|
|
|
else:
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("PKG rule '%s' not found" % case)
|
2007-02-21 01:33:13 -05:00
|
|
|
success = -1
|
|
|
|
elif kind == "FILE":
|
2011-01-29 12:23:55 -05:00
|
|
|
filename = os.path.join(test.root, key)
|
2007-02-21 01:33:13 -05:00
|
|
|
if case == "EXIST":
|
|
|
|
if not os.path.isfile(filename):
|
|
|
|
success = 0
|
2014-02-03 12:05:47 -05:00
|
|
|
elif case == "EMPTY":
|
|
|
|
if not (os.path.isfile(filename)
|
|
|
|
and os.path.getsize(filename) == 0):
|
|
|
|
success = 0
|
2007-07-01 20:03:15 -04:00
|
|
|
elif case == "MODIFIED":
|
2011-01-29 12:23:55 -05:00
|
|
|
for f in test.files:
|
2007-07-01 20:03:15 -04:00
|
|
|
if f.name == key:
|
|
|
|
if not f.ismodified():
|
|
|
|
success = 0
|
2010-10-26 23:55:31 -04:00
|
|
|
break
|
2007-07-01 20:03:15 -04:00
|
|
|
elif case == "MODE":
|
2009-07-17 13:33:13 -04:00
|
|
|
if not os.path.isfile(filename):
|
2007-07-01 20:03:15 -04:00
|
|
|
success = 0
|
2009-07-17 13:33:13 -04:00
|
|
|
else:
|
2010-10-26 22:30:22 -04:00
|
|
|
mode = os.lstat(filename)[stat.ST_MODE]
|
|
|
|
if int(value, 8) != stat.S_IMODE(mode):
|
2009-07-17 13:33:13 -04:00
|
|
|
success = 0
|
2007-07-01 20:03:15 -04:00
|
|
|
elif case == "TYPE":
|
|
|
|
if value == "dir":
|
|
|
|
if not os.path.isdir(filename):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = 0
|
2007-07-01 20:03:15 -04:00
|
|
|
elif value == "file":
|
|
|
|
if not os.path.isfile(filename):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = 0
|
2007-07-01 20:03:15 -04:00
|
|
|
elif value == "link":
|
|
|
|
if not os.path.islink(filename):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = 0
|
2007-07-01 20:03:15 -04:00
|
|
|
elif case == "PACNEW":
|
2010-10-26 22:30:22 -04:00
|
|
|
if not os.path.isfile("%s.pacnew" % filename):
|
2007-07-01 20:03:15 -04:00
|
|
|
success = 0
|
|
|
|
elif case == "PACSAVE":
|
2010-10-26 22:30:22 -04:00
|
|
|
if not os.path.isfile("%s.pacsave" % filename):
|
2007-07-01 20:03:15 -04:00
|
|
|
success = 0
|
|
|
|
else:
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("FILE rule '%s' not found" % case)
|
2007-07-01 20:03:15 -04:00
|
|
|
success = -1
|
2011-07-16 11:07:25 -04:00
|
|
|
elif kind == "DIR":
|
|
|
|
filename = os.path.join(test.root, key)
|
|
|
|
if case == "EXIST":
|
|
|
|
if not os.path.isdir(filename):
|
|
|
|
success = 0
|
|
|
|
else:
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("DIR rule '%s' not found" % case)
|
2011-07-16 11:07:25 -04:00
|
|
|
success = -1
|
2011-05-16 12:08:32 -04:00
|
|
|
elif kind == "LINK":
|
|
|
|
filename = os.path.join(test.root, key)
|
|
|
|
if case == "EXIST":
|
|
|
|
if not os.path.islink(filename):
|
|
|
|
success = 0
|
|
|
|
else:
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("LINK rule '%s' not found" % case)
|
2011-05-16 12:08:32 -04:00
|
|
|
success = -1
|
2011-01-29 12:25:56 -05:00
|
|
|
elif kind == "CACHE":
|
|
|
|
cachedir = os.path.join(test.root, util.PM_CACHEDIR)
|
|
|
|
if case == "EXISTS":
|
|
|
|
pkg = test.findpkg(key, value, allow_local=True)
|
|
|
|
if not pkg or not os.path.isfile(
|
|
|
|
os.path.join(cachedir, pkg.filename())):
|
|
|
|
success = 0
|
2007-02-21 01:33:13 -05:00
|
|
|
else:
|
2013-07-29 15:22:07 -04:00
|
|
|
tap.diag("Rule kind '%s' not found" % kind)
|
2007-02-21 01:33:13 -05:00
|
|
|
success = -1
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
if self.false and success != -1:
|
|
|
|
success = not success
|
|
|
|
self.result = success
|
|
|
|
return success
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
# vim: set ts=4 sw=4 et:
|