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":
90 if not value
in newpkg
.optdepends
:
92 elif case
== "REASON":
93 if newpkg
.reason
!= int(value
):
96 if not value
in newpkg
.files
:
98 elif case
== "BACKUP":
100 for f
in newpkg
.backup
:
101 name
, md5sum
= f
.split("\t")
107 print "PKG rule '%s' not found" % case
110 filename
= os
.path
.join(test
.root
, key
)
112 if not os
.path
.isfile(filename
):
114 elif case
== "MODIFIED":
117 if not f
.ismodified():
121 if not os
.path
.isfile(filename
):
124 mode
= os
.lstat(filename
)[stat
.ST_MODE
]
125 if int(value
, 8) != stat
.S_IMODE(mode
):
129 if not os
.path
.isdir(filename
):
131 elif value
== "file":
132 if not os
.path
.isfile(filename
):
134 elif value
== "link":
135 if not os
.path
.islink(filename
):
137 elif case
== "PACNEW":
138 if not os
.path
.isfile("%s.pacnew" % filename
):
140 elif case
== "PACORIG":
141 if not os
.path
.isfile("%s.pacorig" % filename
):
143 elif case
== "PACSAVE":
144 if not os
.path
.isfile("%s.pacsave" % filename
):
147 print "FILE rule '%s' not found" % case
150 filename
= os
.path
.join(test
.root
, key
)
152 if not os
.path
.isdir(filename
):
155 print "DIR rule '%s' not found" % case
158 filename
= os
.path
.join(test
.root
, key
)
160 if not os
.path
.islink(filename
):
163 print "LINK rule '%s' not found" % case
165 elif kind
== "CACHE":
166 cachedir
= os
.path
.join(test
.root
, util
.PM_CACHEDIR
)
168 pkg
= test
.findpkg(key
, value
, allow_local
=True)
169 if not pkg
or not os
.path
.isfile(
170 os
.path
.join(cachedir
, pkg
.filename())):
173 print "Rule kind '%s' not found" % kind
176 if self
.false
and success
!= -1:
177 success
= not success
178 self
.result
= success
181 # vim: set ts=4 sw=4 et: