Updating German Translation
[pacman-ng.git] / pactest / pmrule.py
blob886ac545e501a9586ea4025de3ed42ddcd80bb87
1 #! /usr/bin/python
3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
4 #
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, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 # USA.
21 from util import *
24 class pmrule:
25 """Rule object
26 """
28 def __init__(self, rule):
29 self.rule = rule
30 self.false = 0
31 self.result = 0
33 def __str__(self):
34 return "rule = %s" % self.rule
36 def check(self, root, retcode, localdb, files):
37 """
38 """
40 success = 1
42 [test, args] = self.rule.split("=")
43 if test[0] == "!":
44 self.false = 1
45 test = test.lstrip("!")
46 [kind, case] = test.split("_")
47 if "|" in args:
48 [key, value] = args.split("|", 1)
49 else:
50 [key, value] = [args, None]
52 if kind == "PACMAN":
53 if case == "RETCODE":
54 if retcode != int(key):
55 success = 0
56 elif case == "OUTPUT":
57 if not grep(os.path.join(root, LOGFILE), key):
58 success = 0
59 else:
60 print "PACMAN rule '%s' not found" % case
61 success = -1
62 elif kind == "PKG":
63 newpkg = localdb.db_read(key)
64 if not newpkg:
65 success = 0
66 else:
67 vprint("\tnewpkg.checksum : %s" % newpkg.checksum)
68 vprint("\tnewpkg.mtime : %s" % newpkg.mtime)
69 if case == "EXIST":
70 success = 1
71 elif case == "MODIFIED":
72 if not localdb.ispkgmodified(newpkg):
73 success = 0
74 elif case == "VERSION":
75 if value != newpkg.version:
76 success = 0
77 elif case == "GROUPS":
78 if not value in newpkg.groups:
79 success = 0
80 elif case == "PROVIDES":
81 if not value in newpkg.provides:
82 success = 0
83 elif case == "DEPENDS":
84 if not value in newpkg.depends:
85 success = 0
86 elif case == "REQUIREDBY":
87 if not value in newpkg.requiredby:
88 success = 0
89 elif case == "REASON":
90 if newpkg.reason != int(value):
91 success = 0
92 elif case == "FILES":
93 if not value in newpkg.files:
94 success = 0
95 elif case == "BACKUP":
96 found = 0
97 for f in newpkg.backup:
98 name, md5sum = f.split("\t")
99 if value == name:
100 found = 1
101 if not found:
102 success = 0
103 else:
104 print "PKG rule '%s' not found" % case
105 success = -1
106 elif kind == "FILE":
107 filename = os.path.join(root, key)
108 if case == "EXIST":
109 if not os.path.isfile(filename):
110 success = 0
111 else:
112 if case == "MODIFIED":
113 for f in files:
114 if f.name == key:
115 if not f.ismodified():
116 success = 0
117 elif case == "PACNEW":
118 if not os.path.isfile("%s%s" % (filename, PM_PACNEW)):
119 success = 0
120 elif case == "PACORIG":
121 if not os.path.isfile("%s%s" % (filename, PM_PACORIG)):
122 success = 0
123 elif case == "PACSAVE":
124 if not os.path.isfile("%s%s" % (filename, PM_PACSAVE)):
125 success = 0
126 else:
127 print "FILE rule '%s' not found" % case
128 success = -1
129 else:
130 print "Rule kind '%s' not found" % kind
131 success = -1
133 if self.false and success != -1:
134 success = not success
135 self.result = success
136 return success
139 if __name__ != "__main__":
140 rule = pmrule("PKG_EXIST=dummy")
141 # vim: set ts=4 sw=4 et: