3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 def __init__(self
, rule
):
33 if len(self
.rule
) <= 40:
35 return self
.rule
[:37] + '...'
37 def check(self
, test
):
42 [testname
, args
] = self
.rule
.split("=")
43 if testname
[0] == "!":
45 testname
= testname
[1:]
46 [kind
, case
] = testname
.split("_")
48 [key
, value
] = args
.split("|", 1)
50 [key
, value
] = [args
, None]
54 if test
.retcode
!= int(key
):
56 elif case
== "OUTPUT":
57 logfile
= os
.path
.join(test
.root
, util
.LOGFILE
)
58 if not os
.access(logfile
, os
.F_OK
):
59 print "LOGFILE not found, cannot validate 'OUTPUT' rule"
61 elif not util
.grep(logfile
, key
):
64 print "PACMAN rule '%s' not found" % case
67 localdb
= test
.db
["local"]
68 newpkg
= localdb
.db_read(key
)
74 elif case
== "VERSION":
75 if value
!= newpkg
.version
:
78 if value
!= newpkg
.desc
:
80 elif case
== "GROUPS":
81 if not value
in newpkg
.groups
:
83 elif case
== "PROVIDES":
84 if not value
in newpkg
.provides
:
86 elif case
== "DEPENDS":
87 if not value
in newpkg
.depends
:
89 elif case
== "OPTDEPENDS":
91 for optdep
in newpkg
.optdepends
:
92 if value
== optdep
.split(':', 1)[0]:
95 elif case
== "REASON":
96 if newpkg
.reason
!= int(value
):
99 if not value
in newpkg
.files
:
101 elif case
== "BACKUP":
103 for f
in newpkg
.backup
:
104 name
, md5sum
= f
.split("\t")
110 print "PKG rule '%s' not found" % case
113 filename
= os
.path
.join(test
.root
, key
)
115 if not os
.path
.isfile(filename
):
117 elif case
== "MODIFIED":
120 if not f
.ismodified():
124 if not os
.path
.isfile(filename
):
127 mode
= os
.lstat(filename
)[stat
.ST_MODE
]
128 if int(value
, 8) != stat
.S_IMODE(mode
):
132 if not os
.path
.isdir(filename
):
134 elif value
== "file":
135 if not os
.path
.isfile(filename
):
137 elif value
== "link":
138 if not os
.path
.islink(filename
):
140 elif case
== "PACNEW":
141 if not os
.path
.isfile("%s.pacnew" % filename
):
143 elif case
== "PACORIG":
144 if not os
.path
.isfile("%s.pacorig" % filename
):
146 elif case
== "PACSAVE":
147 if not os
.path
.isfile("%s.pacsave" % filename
):
150 print "FILE rule '%s' not found" % case
153 filename
= os
.path
.join(test
.root
, key
)
155 if not os
.path
.isdir(filename
):
158 print "DIR rule '%s' not found" % case
161 filename
= os
.path
.join(test
.root
, key
)
163 if not os
.path
.islink(filename
):
166 print "LINK rule '%s' not found" % case
168 elif kind
== "CACHE":
169 cachedir
= os
.path
.join(test
.root
, util
.PM_CACHEDIR
)
171 pkg
= test
.findpkg(key
, value
, allow_local
=True)
172 if not pkg
or not os
.path
.isfile(
173 os
.path
.join(cachedir
, pkg
.filename())):
176 print "Rule kind '%s' not found" % kind
179 if self
.false
and success
!= -1:
180 success
= not success
181 self
.result
= success
184 # vim: set ts=4 sw=4 et: