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/>.
26 def __init__(self
, rule
):
32 return "rule = %s" % self
.rule
34 def check(self
, root
, retcode
, localdb
, files
):
40 [test
, args
] = self
.rule
.split("=")
43 test
= test
.lstrip("!")
44 [kind
, case
] = test
.split("_")
46 [key
, value
] = args
.split("|", 1)
48 [key
, value
] = [args
, None]
52 if retcode
!= int(key
):
54 elif case
== "OUTPUT":
55 logfile
= os
.path
.join(root
, LOGFILE
)
56 if not os
.access(logfile
, os
.F_OK
):
57 print "LOGFILE not found, cannot validate 'OUTPUT' rule"
59 elif not grep(os
.path
.join(root
, LOGFILE
), key
):
62 print "PACMAN rule '%s' not found" % case
65 newpkg
= localdb
.db_read(key
)
69 vprint("\tnewpkg.checksum : %s" % newpkg
.checksum
)
70 vprint("\tnewpkg.mtime : %s" % newpkg
.mtime
)
73 elif case
== "MODIFIED":
74 if not localdb
.ispkgmodified(newpkg
):
76 elif case
== "VERSION":
77 if value
!= newpkg
.version
:
79 elif case
== "GROUPS":
80 if not value
in newpkg
.groups
:
82 elif case
== "PROVIDES":
83 if not value
in newpkg
.provides
:
85 elif case
== "DEPENDS":
86 if not value
in newpkg
.depends
:
88 elif case
== "OPTDEPENDS":
89 if not value
in newpkg
.optdepends
:
91 elif case
== "REASON":
92 if newpkg
.reason
!= int(value
):
95 if not value
in newpkg
.files
:
97 elif case
== "BACKUP":
99 for f
in newpkg
.backup
:
100 name
, md5sum
= f
.split("\t")
106 print "PKG rule '%s' not found" % case
109 filename
= os
.path
.join(root
, key
)
111 if not os
.path
.isfile(filename
):
113 elif case
== "MODIFIED":
116 if not f
.ismodified():
119 if not os
.path
.isfile(filename
):
122 mode
= os
.lstat(filename
)[ST_MODE
]
123 if int(value
,8) != S_IMODE(mode
):
127 if not os
.path
.isdir(filename
):
129 elif value
== "file":
130 if not os
.path
.isfile(filename
):
132 elif value
== "link":
133 if not os
.path
.islink(filename
):
135 elif case
== "PACNEW":
136 if not os
.path
.isfile("%s%s" % (filename
, PM_PACNEW
)):
138 elif case
== "PACORIG":
139 if not os
.path
.isfile("%s%s" % (filename
, PM_PACORIG
)):
141 elif case
== "PACSAVE":
142 if not os
.path
.isfile("%s%s" % (filename
, PM_PACSAVE
)):
145 print "FILE rule '%s' not found" % case
148 print "Rule kind '%s' not found" % kind
151 if self
.false
and success
!= -1:
152 success
= not success
153 self
.result
= success
157 if __name__
!= "__main__":
158 rule
= pmrule("PKG_EXIST=dummy")
159 # vim: set ts=4 sw=4 et: