]>
Commit | Line | Data |
---|---|---|
1e80d5d7 | 1 | #!/usr/bin/python |
b792d887 MT |
2 | ############################################################################### |
3 | # # | |
4 | # Pakfire - The IPFire package management system # | |
5 | # Copyright (C) 2011 Pakfire development team # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
1e80d5d7 MT |
21 | |
22 | import logging | |
23 | ||
24 | import packages | |
25 | ||
26 | from constants import * | |
27 | from i18n import _ | |
28 | ||
29 | class Action(object): | |
30 | def __init__(self, pakfire, pkg): | |
31 | self.pakfire = pakfire | |
6ee3d6b9 | 32 | self.pkg_solv = self.pkg = pkg |
1e80d5d7 MT |
33 | |
34 | # Try to get the binary version of the package from the cache if | |
35 | # any. | |
36 | binary_package = self.pkg.get_from_cache() | |
37 | if binary_package: | |
38 | self.pkg = binary_package | |
39 | ||
1e80d5d7 MT |
40 | def __repr__(self): |
41 | return "<%s %s>" % (self.__class__.__name__, self.pkg.friendly_name) | |
42 | ||
43 | @property | |
44 | def needs_download(self): | |
45 | return self.type in ("install", "reinstall", "upgrade", "downgrade",) \ | |
46 | and not isinstance(self.pkg, packages.BinaryPackage) | |
47 | ||
48 | def download(self, text): | |
49 | if not self.needs_download: | |
50 | return | |
51 | ||
52 | self.pkg = self.pkg.download(text) | |
53 | ||
54 | def run(self): | |
55 | raise NotImplementedError | |
56 | ||
57 | @property | |
58 | def local(self): | |
59 | """ | |
60 | Reference to local repository. | |
61 | """ | |
62 | return self.pakfire.repos.local | |
63 | ||
1e80d5d7 MT |
64 | |
65 | class ActionScript(Action): | |
d767668b MT |
66 | type = "script" |
67 | ||
1e80d5d7 | 68 | def run(self): |
d767668b | 69 | #print "Pretending to run script: %s" % self.__class__.__name__ |
1e80d5d7 MT |
70 | pass |
71 | ||
72 | ||
73 | class ActionScriptPreIn(ActionScript): | |
74 | pass | |
75 | ||
76 | ||
77 | class ActionScriptPostIn(ActionScript): | |
78 | pass | |
79 | ||
80 | ||
81 | class ActionScriptPreUn(ActionScript): | |
82 | pass | |
83 | ||
84 | ||
85 | class ActionScriptPostUn(ActionScript): | |
86 | pass | |
87 | ||
88 | ||
d767668b MT |
89 | class ActionScriptPreUp(ActionScript): |
90 | pass | |
91 | ||
92 | ||
93 | class ActionScriptPostUp(ActionScript): | |
94 | pass | |
95 | ||
96 | ||
97 | class ActionScriptPostTrans(ActionScript): | |
98 | pass | |
99 | ||
100 | ||
101 | class ActionScriptPostTransIn(ActionScriptPostTrans): | |
102 | pass | |
103 | ||
104 | ||
105 | class ActionScriptPostTransUn(ActionScriptPostTrans): | |
106 | pass | |
107 | ||
108 | ||
109 | class ActionScriptPostTransUp(ActionScriptPostTrans): | |
110 | pass | |
111 | ||
112 | ||
1e80d5d7 MT |
113 | class ActionInstall(Action): |
114 | type = "install" | |
115 | ||
116 | def run(self): | |
e871a081 MT |
117 | # Add package to the database. |
118 | self.local.add_package(self.pkg) | |
119 | ||
120 | self.pkg.extract(_("Installing"), prefix=self.pakfire.path) | |
1e80d5d7 MT |
121 | |
122 | ||
123 | class ActionUpdate(Action): | |
124 | type = "upgrade" | |
125 | ||
126 | def run(self): | |
e871a081 MT |
127 | # Add new package to the database. |
128 | self.local.add_package(self.pkg) | |
129 | ||
130 | self.pkg.extract(_("Updating"), prefix=self.pakfire.path) | |
1e80d5d7 MT |
131 | |
132 | ||
6ee3d6b9 | 133 | class ActionRemove(Action): |
1e80d5d7 MT |
134 | type = "erase" |
135 | ||
6ee3d6b9 MT |
136 | def __init__(self, *args, **kwargs): |
137 | Action.__init__(self, *args, **kwargs) | |
1e80d5d7 | 138 | |
6ee3d6b9 MT |
139 | # XXX This is ugly, but works for the moment. |
140 | self.pkg = self.local.index.db.get_package_from_solv(self.pkg_solv) | |
141 | assert self.pkg | |
142 | ||
143 | def run(self): | |
144 | self.pkg.remove(_("Removing"), prefix=self.pakfire.path) | |
1e80d5d7 | 145 | |
e871a081 MT |
146 | # Remove package from the database. |
147 | self.local.rem_package(self.pkg) | |
148 | ||
149 | ||
150 | class ActionCleanup(Action): | |
151 | type = "ignore" | |
152 | ||
153 | def __init__(self, *args, **kwargs): | |
154 | Action.__init__(self, *args, **kwargs) | |
155 | ||
156 | # XXX This is ugly, but works for the moment. | |
157 | self.pkg = self.local.index.db.get_package_from_solv(self.pkg_solv) | |
158 | assert self.pkg | |
159 | ||
160 | def run(self): | |
161 | # Cleaning up leftover files and stuff. | |
162 | self.pkg.cleanup(_("Cleanup"), prefix=self.pakfire.path) | |
163 | ||
164 | # Remove package from the database. | |
165 | self.local.rem_package(self.pkg) | |
1e80d5d7 MT |
166 | |
167 | ||
168 | class ActionReinstall(Action): | |
169 | type = "reinstall" | |
170 | ||
171 | def run(self): | |
e871a081 MT |
172 | # Remove package from the database and add it afterwards. |
173 | # Sounds weird, but fixes broken entries in the database. | |
174 | self.local.rem_package(self.pkg) | |
175 | self.local.add_package(self.pkg) | |
176 | ||
177 | self.pkg.extract(_("Installing"), prefix=self.pakfire.path) | |
1e80d5d7 MT |
178 | |
179 | ||
180 | class ActionDowngrade(Action): | |
181 | type = "downgrade" | |
182 | ||
183 | def run(self): | |
e871a081 MT |
184 | # Add new package to database. |
185 | self.local.add_package(self.pkg) | |
186 | ||
187 | self.pkg.extract(_("Downgrading"), prefix=self.pakfire.path) | |
1e80d5d7 MT |
188 | |
189 | ||
190 | class ActionChange(Action): | |
191 | type = "change" | |
192 | ||
e871a081 MT |
193 | # XXX still need to find out what this should be doing |
194 | ||
1e80d5d7 MT |
195 | def run(self): |
196 | print "XXX Change: %s" % self.pkg |