Merge lp:~elachuni/software-center/pep8-test-part20 into lp:software-center
- pep8-test-part20
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2874 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part20 |
Merge into: | lp:software-center |
Prerequisite: | lp:~elachuni/software-center/pep8-test-part19 |
Diff against target: |
1547 lines (+368/-270) 11 files modified
softwarecenter/backend/installbackend_impl/aptd.py (+159/-119) softwarecenter/backend/installbackend_impl/packagekit_enums.py (+4/-2) softwarecenter/backend/installbackend_impl/packagekitd.py (+92/-59) softwarecenter/backend/piston/rnrclient.py (+14/-9) softwarecenter/backend/piston/rnrclient_fake.py (+74/-68) softwarecenter/backend/piston/rnrclient_pristine.py (+8/-3) softwarecenter/backend/piston/scaclient.py (+8/-7) softwarecenter/backend/piston/scaclient_pristine.py (+1/-0) softwarecenter/backend/piston/sreclient_pristine.py (+1/-0) softwarecenter/backend/piston/sso_helper.py (+3/-3) test/test_pep8.py (+4/-0) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part20 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kiwinote | Approve | ||
Review via email: mp+97977@code.launchpad.net |
Commit message
Description of the change
This branch makes all files under softwarecenter/
To post a comment you must log in.
Revision history for this message
Kiwinote (kiwinote) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'softwarecenter/backend/installbackend_impl/aptd.py' | |||
2 | --- softwarecenter/backend/installbackend_impl/aptd.py 2012-03-16 14:36:05 +0000 | |||
3 | +++ softwarecenter/backend/installbackend_impl/aptd.py 2012-03-16 20:20:25 +0000 | |||
4 | @@ -41,7 +41,7 @@ | |||
5 | 41 | 41 | ||
6 | 42 | from softwarecenter.db.application import Application | 42 | from softwarecenter.db.application import Application |
7 | 43 | from softwarecenter.backend.transactionswatcher import ( | 43 | from softwarecenter.backend.transactionswatcher import ( |
9 | 44 | BaseTransactionsWatcher, | 44 | BaseTransactionsWatcher, |
10 | 45 | BaseTransaction, | 45 | BaseTransaction, |
11 | 46 | TransactionFinishedResult, | 46 | TransactionFinishedResult, |
12 | 47 | TransactionProgress) | 47 | TransactionProgress) |
13 | @@ -52,6 +52,8 @@ | |||
14 | 52 | # its important that we only have a single dbus BusConnection | 52 | # its important that we only have a single dbus BusConnection |
15 | 53 | # per address when using the fake dbus aptd | 53 | # per address when using the fake dbus aptd |
16 | 54 | buses = {} | 54 | buses = {} |
17 | 55 | |||
18 | 56 | |||
19 | 55 | def get_dbus_bus(): | 57 | def get_dbus_bus(): |
20 | 56 | if "SOFTWARE_CENTER_APTD_FAKE" in os.environ: | 58 | if "SOFTWARE_CENTER_APTD_FAKE" in os.environ: |
21 | 57 | global buses | 59 | global buses |
22 | @@ -63,6 +65,7 @@ | |||
23 | 63 | bus = dbus.SystemBus() | 65 | bus = dbus.SystemBus() |
24 | 64 | return bus | 66 | return bus |
25 | 65 | 67 | ||
26 | 68 | |||
27 | 66 | class FakePurchaseTransaction(object): | 69 | class FakePurchaseTransaction(object): |
28 | 67 | def __init__(self, app, iconname): | 70 | def __init__(self, app, iconname): |
29 | 68 | self.pkgname = app.pkgname | 71 | self.pkgname = app.pkgname |
30 | @@ -70,6 +73,7 @@ | |||
31 | 70 | self.iconname = iconname | 73 | self.iconname = iconname |
32 | 71 | self.progress = 0 | 74 | self.progress = 0 |
33 | 72 | 75 | ||
34 | 76 | |||
35 | 73 | class AptdaemonTransaction(BaseTransaction): | 77 | class AptdaemonTransaction(BaseTransaction): |
36 | 74 | def __init__(self, trans): | 78 | def __init__(self, trans): |
37 | 75 | self._trans = trans | 79 | self._trans = trans |
38 | @@ -126,9 +130,10 @@ | |||
39 | 126 | trans = AptdaemonTransaction(trans) | 130 | trans = AptdaemonTransaction(trans) |
40 | 127 | return real_handler(trans, *args) | 131 | return real_handler(trans, *args) |
41 | 128 | 132 | ||
42 | 133 | |||
43 | 129 | class AptdaemonTransactionsWatcher(BaseTransactionsWatcher): | 134 | class AptdaemonTransactionsWatcher(BaseTransactionsWatcher): |
46 | 130 | """ | 135 | """ |
47 | 131 | base class for objects that need to watch the aptdaemon | 136 | base class for objects that need to watch the aptdaemon |
48 | 132 | for transaction changes. it registers a handler for the daemon | 137 | for transaction changes. it registers a handler for the daemon |
49 | 133 | going away and reconnects when it appears again | 138 | going away and reconnects when it appears again |
50 | 134 | """ | 139 | """ |
51 | @@ -144,7 +149,7 @@ | |||
52 | 144 | #print "_register_active_transactions_watch", connection | 149 | #print "_register_active_transactions_watch", connection |
53 | 145 | bus = get_dbus_bus() | 150 | bus = get_dbus_bus() |
54 | 146 | apt_daemon = client.get_aptdaemon(bus=bus) | 151 | apt_daemon = client.get_aptdaemon(bus=bus) |
56 | 147 | apt_daemon.connect_to_signal("ActiveTransactionsChanged", | 152 | apt_daemon.connect_to_signal("ActiveTransactionsChanged", |
57 | 148 | self._on_transactions_changed) | 153 | self._on_transactions_changed) |
58 | 149 | current, queued = apt_daemon.GetActiveTransactions() | 154 | current, queued = apt_daemon.GetActiveTransactions() |
59 | 150 | self._on_transactions_changed(current, queued) | 155 | self._on_transactions_changed(current, queued) |
60 | @@ -158,54 +163,54 @@ | |||
61 | 158 | trans = client.get_transaction(tid) | 163 | trans = client.get_transaction(tid) |
62 | 159 | return AptdaemonTransaction(trans) | 164 | return AptdaemonTransaction(trans) |
63 | 160 | except dbus.DBusException: | 165 | except dbus.DBusException: |
65 | 161 | return None | 166 | pass |
66 | 162 | 167 | ||
67 | 163 | 168 | ||
68 | 164 | class AptdaemonBackend(GObject.GObject, InstallBackend): | 169 | class AptdaemonBackend(GObject.GObject, InstallBackend): |
69 | 165 | """ software center specific code that interacts with aptdaemon """ | 170 | """ software center specific code that interacts with aptdaemon """ |
70 | 166 | 171 | ||
72 | 167 | __gsignals__ = {'transaction-started':(GObject.SIGNAL_RUN_FIRST, | 172 | __gsignals__ = {'transaction-started': (GObject.SIGNAL_RUN_FIRST, |
73 | 168 | GObject.TYPE_NONE, | 173 | GObject.TYPE_NONE, |
75 | 169 | (str,str,str,str)), | 174 | (str, str, str, str)), |
76 | 170 | # emits a TransactionFinished object | 175 | # emits a TransactionFinished object |
81 | 171 | 'transaction-finished':(GObject.SIGNAL_RUN_FIRST, | 176 | 'transaction-finished': (GObject.SIGNAL_RUN_FIRST, |
82 | 172 | GObject.TYPE_NONE, | 177 | GObject.TYPE_NONE, |
83 | 173 | (GObject.TYPE_PYOBJECT, )), | 178 | (GObject.TYPE_PYOBJECT, )), |
84 | 174 | 'transaction-stopped':(GObject.SIGNAL_RUN_FIRST, | 179 | 'transaction-stopped': (GObject.SIGNAL_RUN_FIRST, |
85 | 175 | GObject.TYPE_NONE, | 180 | GObject.TYPE_NONE, |
86 | 176 | (GObject.TYPE_PYOBJECT,)), | 181 | (GObject.TYPE_PYOBJECT,)), |
93 | 177 | 'transactions-changed':(GObject.SIGNAL_RUN_FIRST, | 182 | 'transactions-changed': (GObject.SIGNAL_RUN_FIRST, |
94 | 178 | GObject.TYPE_NONE, | 183 | GObject.TYPE_NONE, |
95 | 179 | (GObject.TYPE_PYOBJECT, )), | 184 | (GObject.TYPE_PYOBJECT, )), |
96 | 180 | 'transaction-progress-changed':(GObject.SIGNAL_RUN_FIRST, | 185 | 'transaction-progress-changed': (GObject.SIGNAL_RUN_FIRST, |
97 | 181 | GObject.TYPE_NONE, | 186 | GObject.TYPE_NONE, |
98 | 182 | (str,int,)), | 187 | (str, int,)), |
99 | 183 | # the number/names of the available channels changed | 188 | # the number/names of the available channels changed |
101 | 184 | 'channels-changed':(GObject.SIGNAL_RUN_FIRST, | 189 | 'channels-changed': (GObject.SIGNAL_RUN_FIRST, |
102 | 190 | GObject.TYPE_NONE, | ||
103 | 191 | (bool,)), | ||
104 | 192 | # cache reload emits this specific signal as well | ||
105 | 193 | 'reload-finished': (GObject.SIGNAL_RUN_FIRST, | ||
106 | 185 | GObject.TYPE_NONE, | 194 | GObject.TYPE_NONE, |
112 | 186 | (bool,)), | 195 | (GObject.TYPE_PYOBJECT, bool,)), |
108 | 187 | # cache reload emits this specific signal as well | ||
109 | 188 | 'reload-finished':(GObject.SIGNAL_RUN_FIRST, | ||
110 | 189 | GObject.TYPE_NONE, | ||
111 | 190 | (GObject.TYPE_PYOBJECT, bool,)), | ||
113 | 191 | } | 196 | } |
114 | 192 | 197 | ||
115 | 193 | def __init__(self): | 198 | def __init__(self): |
116 | 194 | GObject.GObject.__init__(self) | 199 | GObject.GObject.__init__(self) |
118 | 195 | 200 | ||
119 | 196 | bus = get_dbus_bus() | 201 | bus = get_dbus_bus() |
120 | 197 | self.aptd_client = client.AptClient(bus=bus) | 202 | self.aptd_client = client.AptClient(bus=bus) |
121 | 198 | self.pending_transactions = {} | 203 | self.pending_transactions = {} |
122 | 199 | self._transactions_watcher = AptdaemonTransactionsWatcher() | 204 | self._transactions_watcher = AptdaemonTransactionsWatcher() |
123 | 200 | self._transactions_watcher.connect("lowlevel-transactions-changed", | 205 | self._transactions_watcher.connect("lowlevel-transactions-changed", |
125 | 201 | self._on_lowlevel_transactions_changed) | 206 | self._on_lowlevel_transactions_changed) |
126 | 202 | # dict of pkgname -> FakePurchaseTransaction | 207 | # dict of pkgname -> FakePurchaseTransaction |
127 | 203 | self.pending_purchases = {} | 208 | self.pending_purchases = {} |
128 | 204 | self._progress_signal = None | 209 | self._progress_signal = None |
129 | 205 | self._logger = logging.getLogger("softwarecenter.backend") | 210 | self._logger = logging.getLogger("softwarecenter.backend") |
130 | 206 | # the AptdaemonBackendUI code | 211 | # the AptdaemonBackendUI code |
131 | 207 | self.ui = None | 212 | self.ui = None |
133 | 208 | 213 | ||
134 | 209 | def _axi_finished(self, res): | 214 | def _axi_finished(self, res): |
135 | 210 | self.emit("channels-changed", res) | 215 | self.emit("channels-changed", res) |
136 | 211 | 216 | ||
137 | @@ -216,7 +221,7 @@ | |||
138 | 216 | # axi is optional, so just do nothing if its not installed | 221 | # axi is optional, so just do nothing if its not installed |
139 | 217 | try: | 222 | try: |
140 | 218 | axi = dbus.Interface( | 223 | axi = dbus.Interface( |
142 | 219 | system_bus.get_object("org.debian.AptXapianIndex","/"), | 224 | system_bus.get_object("org.debian.AptXapianIndex", "/"), |
143 | 220 | "org.debian.AptXapianIndex") | 225 | "org.debian.AptXapianIndex") |
144 | 221 | except dbus.DBusException as e: | 226 | except dbus.DBusException as e: |
145 | 222 | self._logger.warning("axi can not be updated '%s'" % e) | 227 | self._logger.warning("axi can not be updated '%s'" % e) |
146 | @@ -234,22 +239,26 @@ | |||
147 | 234 | def fix_broken_depends(self): | 239 | def fix_broken_depends(self): |
148 | 235 | try: | 240 | try: |
149 | 236 | trans = yield self.aptd_client.fix_broken_depends(defer=True) | 241 | trans = yield self.aptd_client.fix_broken_depends(defer=True) |
151 | 237 | self.emit("transaction-started", "", "", trans.tid, TransactionTypes.REPAIR) | 242 | self.emit("transaction-started", "", "", trans.tid, |
152 | 243 | TransactionTypes.REPAIR) | ||
153 | 238 | yield self._run_transaction(trans, None, None, None) | 244 | yield self._run_transaction(trans, None, None, None) |
154 | 239 | except Exception as error: | 245 | except Exception as error: |
155 | 240 | self._on_trans_error(error) | 246 | self._on_trans_error(error) |
156 | 241 | 247 | ||
157 | 242 | # FIXME: upgrade add-ons here | 248 | # FIXME: upgrade add-ons here |
158 | 243 | @inline_callbacks | 249 | @inline_callbacks |
160 | 244 | def upgrade(self, app, iconname, addons_install=[], addons_remove=[], metadata=None): | 250 | def upgrade(self, app, iconname, addons_install=[], addons_remove=[], |
161 | 251 | metadata=None): | ||
162 | 245 | """ upgrade a single package """ | 252 | """ upgrade a single package """ |
163 | 246 | pkgname = app.pkgname | 253 | pkgname = app.pkgname |
164 | 247 | appname = app.appname | 254 | appname = app.appname |
165 | 248 | try: | 255 | try: |
166 | 249 | trans = yield self.aptd_client.upgrade_packages([pkgname], | 256 | trans = yield self.aptd_client.upgrade_packages([pkgname], |
167 | 250 | defer=True) | 257 | defer=True) |
170 | 251 | self.emit("transaction-started", pkgname, appname, trans.tid, TransactionTypes.UPGRADE) | 258 | self.emit("transaction-started", pkgname, appname, trans.tid, |
171 | 252 | yield self._run_transaction(trans, pkgname, appname, iconname, metadata) | 259 | TransactionTypes.UPGRADE) |
172 | 260 | yield self._run_transaction(trans, pkgname, appname, iconname, | ||
173 | 261 | metadata) | ||
174 | 253 | except Exception as error: | 262 | except Exception as error: |
175 | 254 | self._on_trans_error(error, pkgname) | 263 | self._on_trans_error(error, pkgname) |
176 | 255 | 264 | ||
177 | @@ -257,9 +266,10 @@ | |||
178 | 257 | # @inline_callbacks | 266 | # @inline_callbacks |
179 | 258 | # def _simulate_remove_multiple(self, pkgnames): | 267 | # def _simulate_remove_multiple(self, pkgnames): |
180 | 259 | # try: | 268 | # try: |
182 | 260 | # trans = yield self.aptd_client.remove_packages(pkgnames, | 269 | # trans = yield self.aptd_client.remove_packages(pkgnames, |
183 | 261 | # defer=True) | 270 | # defer=True) |
185 | 262 | # trans.connect("dependencies-changed", self._on_dependencies_changed) | 271 | # trans.connect("dependencies-changed", |
186 | 272 | # self._on_dependencies_changed) | ||
187 | 263 | # except Exception: | 273 | # except Exception: |
188 | 264 | # logging.exception("simulate_remove") | 274 | # logging.exception("simulate_remove") |
189 | 265 | # return_value(trans) | 275 | # return_value(trans) |
190 | @@ -278,22 +288,25 @@ | |||
191 | 278 | # gtk.main_iteration() | 288 | # gtk.main_iteration() |
192 | 279 | # time.sleep(0.01) | 289 | # time.sleep(0.01) |
193 | 280 | 290 | ||
194 | 281 | |||
195 | 282 | @inline_callbacks | 291 | @inline_callbacks |
197 | 283 | def remove(self, app, iconname, addons_install=[], addons_remove=[], metadata=None): | 292 | def remove(self, app, iconname, addons_install=[], addons_remove=[], |
198 | 293 | metadata=None): | ||
199 | 284 | """ remove a single package """ | 294 | """ remove a single package """ |
200 | 285 | pkgname = app.pkgname | 295 | pkgname = app.pkgname |
201 | 286 | appname = app.appname | 296 | appname = app.appname |
202 | 287 | try: | 297 | try: |
203 | 288 | trans = yield self.aptd_client.remove_packages([pkgname], | 298 | trans = yield self.aptd_client.remove_packages([pkgname], |
204 | 289 | defer=True) | 299 | defer=True) |
207 | 290 | self.emit("transaction-started", pkgname, appname, trans.tid, TransactionTypes.REMOVE) | 300 | self.emit("transaction-started", pkgname, appname, trans.tid, |
208 | 291 | yield self._run_transaction(trans, pkgname, appname, iconname, metadata) | 301 | TransactionTypes.REMOVE) |
209 | 302 | yield self._run_transaction(trans, pkgname, appname, iconname, | ||
210 | 303 | metadata) | ||
211 | 292 | except Exception as error: | 304 | except Exception as error: |
212 | 293 | self._on_trans_error(error, pkgname) | 305 | self._on_trans_error(error, pkgname) |
213 | 294 | 306 | ||
214 | 295 | @inline_callbacks | 307 | @inline_callbacks |
216 | 296 | def remove_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None): | 308 | def remove_multiple(self, apps, iconnames, addons_install=[], |
217 | 309 | addons_remove=[], metadatas=None): | ||
218 | 297 | """ queue a list of packages for removal """ | 310 | """ queue a list of packages for removal """ |
219 | 298 | if metadatas == None: | 311 | if metadatas == None: |
220 | 299 | metadatas = [] | 312 | metadatas = [] |
221 | @@ -303,7 +316,8 @@ | |||
222 | 303 | yield self.remove(app, iconname, metadata) | 316 | yield self.remove(app, iconname, metadata) |
223 | 304 | 317 | ||
224 | 305 | @inline_callbacks | 318 | @inline_callbacks |
226 | 306 | def install(self, app, iconname, filename=None, addons_install=[], addons_remove=[], metadata=None, force=False): | 319 | def install(self, app, iconname, filename=None, addons_install=[], |
227 | 320 | addons_remove=[], metadata=None, force=False): | ||
228 | 307 | """Install a single package from the archive | 321 | """Install a single package from the archive |
229 | 308 | If filename is given a local deb package is installed instead. | 322 | If filename is given a local deb package is installed instead. |
230 | 309 | """ | 323 | """ |
231 | @@ -317,23 +331,26 @@ | |||
232 | 317 | # force means on lintian failure | 331 | # force means on lintian failure |
233 | 318 | trans = yield self.aptd_client.install_file( | 332 | trans = yield self.aptd_client.install_file( |
234 | 319 | filename, force=force, defer=True) | 333 | filename, force=force, defer=True) |
236 | 320 | self.emit("transaction-started", pkgname, appname, trans.tid, TransactionTypes.INSTALL) | 334 | self.emit("transaction-started", pkgname, appname, trans.tid, |
237 | 335 | TransactionTypes.INSTALL) | ||
238 | 321 | yield trans.set_meta_data(sc_filename=filename, defer=True) | 336 | yield trans.set_meta_data(sc_filename=filename, defer=True) |
239 | 322 | else: | 337 | else: |
240 | 323 | install = [pkgname] + addons_install | 338 | install = [pkgname] + addons_install |
241 | 324 | remove = addons_remove | 339 | remove = addons_remove |
243 | 325 | reinstall = remove = purge = upgrade =downgrade = [] | 340 | reinstall = remove = purge = upgrade = downgrade = [] |
244 | 326 | trans = yield self.aptd_client.commit_packages( | 341 | trans = yield self.aptd_client.commit_packages( |
246 | 327 | install, reinstall, remove, purge, upgrade, downgrade, | 342 | install, reinstall, remove, purge, upgrade, downgrade, |
247 | 328 | defer=True) | 343 | defer=True) |
249 | 329 | self.emit("transaction-started", pkgname, appname, trans.tid, TransactionTypes.INSTALL) | 344 | self.emit("transaction-started", pkgname, appname, trans.tid, |
250 | 345 | TransactionTypes.INSTALL) | ||
251 | 330 | yield self._run_transaction( | 346 | yield self._run_transaction( |
252 | 331 | trans, pkgname, appname, iconname, metadata) | 347 | trans, pkgname, appname, iconname, metadata) |
253 | 332 | except Exception as error: | 348 | except Exception as error: |
254 | 333 | self._on_trans_error(error, pkgname) | 349 | self._on_trans_error(error, pkgname) |
255 | 334 | 350 | ||
256 | 335 | @inline_callbacks | 351 | @inline_callbacks |
258 | 336 | def install_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None): | 352 | def install_multiple(self, apps, iconnames, addons_install=[], |
259 | 353 | addons_remove=[], metadatas=None): | ||
260 | 337 | """ queue a list of packages for install """ | 354 | """ queue a list of packages for install """ |
261 | 338 | if metadatas == None: | 355 | if metadatas == None: |
262 | 339 | metadatas = [] | 356 | metadatas = [] |
263 | @@ -341,20 +358,22 @@ | |||
264 | 341 | metadatas.append(None) | 358 | metadatas.append(None) |
265 | 342 | for app, iconname, metadata in zip(apps, iconnames, metadatas): | 359 | for app, iconname, metadata in zip(apps, iconnames, metadatas): |
266 | 343 | yield self.install(app, iconname, metadata=metadata) | 360 | yield self.install(app, iconname, metadata=metadata) |
268 | 344 | 361 | ||
269 | 345 | @inline_callbacks | 362 | @inline_callbacks |
271 | 346 | def apply_changes(self, app, iconname, addons_install=[], addons_remove=[], metadata=None): | 363 | def apply_changes(self, app, iconname, addons_install=[], |
272 | 364 | addons_remove=[], metadata=None): | ||
273 | 347 | """ install and remove add-ons """ | 365 | """ install and remove add-ons """ |
274 | 348 | pkgname = app.pkgname | 366 | pkgname = app.pkgname |
275 | 349 | appname = app.appname | 367 | appname = app.appname |
276 | 350 | try: | 368 | try: |
277 | 351 | install = addons_install | 369 | install = addons_install |
278 | 352 | remove = addons_remove | 370 | remove = addons_remove |
280 | 353 | reinstall = remove = purge = upgrade =downgrade = [] | 371 | reinstall = remove = purge = upgrade = downgrade = [] |
281 | 354 | trans = yield self.aptd_client.commit_packages( | 372 | trans = yield self.aptd_client.commit_packages( |
283 | 355 | install, reinstall, remove, purge, upgrade, downgrade, | 373 | install, reinstall, remove, purge, upgrade, downgrade, |
284 | 356 | defer=True) | 374 | defer=True) |
286 | 357 | self.emit("transaction-started", pkgname, appname, trans.tid, TransactionTypes.APPLY) | 375 | self.emit("transaction-started", pkgname, appname, trans.tid, |
287 | 376 | TransactionTypes.APPLY) | ||
288 | 358 | yield self._run_transaction(trans, pkgname, appname, iconname) | 377 | yield self._run_transaction(trans, pkgname, appname, iconname) |
289 | 359 | except Exception as error: | 378 | except Exception as error: |
290 | 360 | self._on_trans_error(error) | 379 | self._on_trans_error(error) |
291 | @@ -365,12 +384,12 @@ | |||
292 | 365 | # check if the sourcespart is there, if not, do a full reload | 384 | # check if the sourcespart is there, if not, do a full reload |
293 | 366 | # this can happen when the "partner" repository is added, it | 385 | # this can happen when the "partner" repository is added, it |
294 | 367 | # will be in the main sources.list already and this means that | 386 | # will be in the main sources.list already and this means that |
296 | 368 | # aptsources will just enable it instead of adding a extra | 387 | # aptsources will just enable it instead of adding a extra |
297 | 369 | # sources.list.d file (LP: #666956) | 388 | # sources.list.d file (LP: #666956) |
298 | 370 | d = apt_pkg.config.find_dir("Dir::Etc::sourceparts") | 389 | d = apt_pkg.config.find_dir("Dir::Etc::sourceparts") |
299 | 371 | if (not sources_list or | 390 | if (not sources_list or |
300 | 372 | not os.path.exists(os.path.join(d, sources_list))): | 391 | not os.path.exists(os.path.join(d, sources_list))): |
302 | 373 | sources_list="" | 392 | sources_list = "" |
303 | 374 | try: | 393 | try: |
304 | 375 | trans = yield self.aptd_client.update_cache( | 394 | trans = yield self.aptd_client.update_cache( |
305 | 376 | sources_list=sources_list, defer=True) | 395 | sources_list=sources_list, defer=True) |
306 | @@ -404,18 +423,18 @@ | |||
307 | 404 | continue | 423 | continue |
308 | 405 | sourcepart = os.path.basename(channelfile) | 424 | sourcepart = os.path.basename(channelfile) |
309 | 406 | yield self.add_sources_list_entry(entry, sourcepart) | 425 | yield self.add_sources_list_entry(entry, sourcepart) |
311 | 407 | keyfile = channelfile.replace(".list",".key") | 426 | keyfile = channelfile.replace(".list", ".key") |
312 | 408 | if os.path.exists(keyfile): | 427 | if os.path.exists(keyfile): |
314 | 409 | trans = yield self.aptd_client.add_vendor_key_from_file(keyfile, wait=True) | 428 | trans = yield self.aptd_client.add_vendor_key_from_file( |
315 | 429 | keyfile, wait=True) | ||
316 | 410 | # don't use self._run_transaction() here, to avoid sending | 430 | # don't use self._run_transaction() here, to avoid sending |
317 | 411 | # uneeded signals | 431 | # uneeded signals |
318 | 412 | yield trans.run(defer=True) | 432 | yield trans.run(defer=True) |
319 | 413 | yield self.reload(sourcepart) | 433 | yield self.reload(sourcepart) |
320 | 414 | 434 | ||
321 | 415 | @inline_callbacks | 435 | @inline_callbacks |
325 | 416 | def add_vendor_key_from_keyserver(self, keyid, | 436 | def add_vendor_key_from_keyserver(self, keyid, |
326 | 417 | keyserver="hkp://keyserver.ubuntu.com:80/", | 437 | keyserver="hkp://keyserver.ubuntu.com:80/", metadata=None): |
324 | 418 | metadata=None): | ||
327 | 419 | # strip the keysize | 438 | # strip the keysize |
328 | 420 | if "/" in keyid: | 439 | if "/" in keyid: |
329 | 421 | keyid = keyid.split("/")[1] | 440 | keyid = keyid.split("/")[1] |
330 | @@ -452,8 +471,8 @@ | |||
331 | 452 | 471 | ||
332 | 453 | @inline_callbacks | 472 | @inline_callbacks |
333 | 454 | def authenticate_for_purchase(self): | 473 | def authenticate_for_purchase(self): |
336 | 455 | """ | 474 | """ |
337 | 456 | helper that authenticates with aptdaemon for a purchase operation | 475 | helper that authenticates with aptdaemon for a purchase operation |
338 | 457 | """ | 476 | """ |
339 | 458 | bus = get_dbus_bus() | 477 | bus = get_dbus_bus() |
340 | 459 | name = bus.get_unique_name() | 478 | name = bus.get_unique_name() |
341 | @@ -462,12 +481,13 @@ | |||
342 | 462 | yield policykit1.check_authorization_by_name(name, action, flags=flags) | 481 | yield policykit1.check_authorization_by_name(name, action, flags=flags) |
343 | 463 | 482 | ||
344 | 464 | @inline_callbacks | 483 | @inline_callbacks |
346 | 465 | def add_license_key(self, license_key, license_key_path, license_key_oauth, pkgname): | 484 | def add_license_key(self, license_key, license_key_path, |
347 | 485 | license_key_oauth, pkgname): | ||
348 | 466 | """ add a license key for a purchase. """ | 486 | """ add a license key for a purchase. """ |
349 | 467 | self._logger.debug( | 487 | self._logger.debug( |
350 | 468 | "adding license_key for pkg '%s' of len: %i" % ( | 488 | "adding license_key for pkg '%s' of len: %i" % ( |
351 | 469 | pkgname, len(license_key))) | 489 | pkgname, len(license_key))) |
353 | 470 | 490 | ||
354 | 471 | # HOME based license keys | 491 | # HOME based license keys |
355 | 472 | if license_key_path and license_key_path.startswith("~"): | 492 | if license_key_path and license_key_path.startswith("~"): |
356 | 473 | # check if its inside HOME and if so, just create it | 493 | # check if its inside HOME and if so, just create it |
357 | @@ -503,19 +523,19 @@ | |||
358 | 503 | license_key_path, | 523 | license_key_path, |
359 | 504 | json_oauth_token=None, | 524 | json_oauth_token=None, |
360 | 505 | purchase=True): | 525 | purchase=True): |
362 | 506 | """ | 526 | """ |
363 | 507 | a convenience method that combines all of the steps needed | 527 | a convenience method that combines all of the steps needed |
364 | 508 | to install a for-pay application, including adding the | 528 | to install a for-pay application, including adding the |
365 | 509 | source entry and the vendor key, reloading the package list, | 529 | source entry and the vendor key, reloading the package list, |
366 | 510 | and finally installing the specified application once the | 530 | and finally installing the specified application once the |
367 | 511 | package list reload has completed. | 531 | package list reload has completed. |
368 | 512 | """ | 532 | """ |
375 | 513 | self.emit("transaction-started", app.pkgname, app.appname, "FIXME-NEED-ID-HERE", TransactionTypes.INSTALL) | 533 | self.emit("transaction-started", app.pkgname, app.appname, |
376 | 514 | self._logger.info("add_repo_add_key_and_install_app() '%s' '%s' '%s'"% ( | 534 | "FIXME-NEED-ID-HERE", TransactionTypes.INSTALL) |
377 | 515 | # re.sub() out the password from the log | 535 | self._logger.info("add_repo_add_key_and_install_app() '%s' '%s' '%s'" % |
378 | 516 | re.sub("deb https://.*@", "", deb_line), | 536 | (re.sub("deb https://.*@", "", deb_line), # strip out password |
379 | 517 | signing_key_id, | 537 | signing_key_id, |
380 | 518 | app)) | 538 | app)) |
381 | 519 | 539 | ||
382 | 520 | if purchase: | 540 | if purchase: |
383 | 521 | # pre-authenticate | 541 | # pre-authenticate |
384 | @@ -537,15 +557,17 @@ | |||
385 | 537 | 557 | ||
386 | 538 | # add the metadata early, add_sources_list_entry is a transaction | 558 | # add the metadata early, add_sources_list_entry is a transaction |
387 | 539 | # too | 559 | # too |
397 | 540 | trans_metadata = {'sc_add_repo_and_install_appname' : app.appname, | 560 | trans_metadata = { |
398 | 541 | 'sc_add_repo_and_install_pkgname' : app.pkgname, | 561 | 'sc_add_repo_and_install_appname': app.appname, |
399 | 542 | 'sc_add_repo_and_install_deb_line' : deb_line, | 562 | 'sc_add_repo_and_install_pkgname': app.pkgname, |
400 | 543 | 'sc_iconname' : iconname, | 563 | 'sc_add_repo_and_install_deb_line': deb_line, |
401 | 544 | 'sc_add_repo_and_install_try' : "1", | 564 | 'sc_iconname': iconname, |
402 | 545 | 'sc_add_repo_and_install_license_key' : license_key or "", | 565 | 'sc_add_repo_and_install_try': "1", |
403 | 546 | 'sc_add_repo_and_install_license_key_path' : license_key_path or "", | 566 | 'sc_add_repo_and_install_license_key': license_key or "", |
404 | 547 | 'sc_add_repo_and_install_license_key_token' : json_oauth_token or "", | 567 | 'sc_add_repo_and_install_license_key_path': license_key_path or "", |
405 | 548 | } | 568 | 'sc_add_repo_and_install_license_key_token': \ |
406 | 569 | json_oauth_token or "", | ||
407 | 570 | } | ||
408 | 549 | 571 | ||
409 | 550 | self._logger.info("add_sources_list_entry()") | 572 | self._logger.info("add_sources_list_entry()") |
410 | 551 | sourcepart = yield self.add_sources_list_entry(deb_line) | 573 | sourcepart = yield self.add_sources_list_entry(deb_line) |
411 | @@ -560,8 +582,9 @@ | |||
412 | 560 | yield self._reload_for_commercial_repo(app, trans_metadata, sourcepart) | 582 | yield self._reload_for_commercial_repo(app, trans_metadata, sourcepart) |
413 | 561 | 583 | ||
414 | 562 | @inline_callbacks | 584 | @inline_callbacks |
417 | 563 | def _reload_for_commercial_repo_defer(self, app, trans_metadata, sources_list): | 585 | def _reload_for_commercial_repo_defer(self, app, trans_metadata, |
418 | 564 | """ | 586 | sources_list): |
419 | 587 | """ | ||
420 | 565 | helper that reloads and registers a callback for when the reload is | 588 | helper that reloads and registers a callback for when the reload is |
421 | 566 | finished | 589 | finished |
422 | 567 | """ | 590 | """ |
423 | @@ -570,7 +593,7 @@ | |||
424 | 570 | # otherwise the daemon will fail because he does not know | 593 | # otherwise the daemon will fail because he does not know |
425 | 571 | # the new package name yet | 594 | # the new package name yet |
426 | 572 | self.connect("reload-finished", | 595 | self.connect("reload-finished", |
428 | 573 | self._on_reload_for_add_repo_and_install_app_finished, | 596 | self._on_reload_for_add_repo_and_install_app_finished, |
429 | 574 | trans_metadata, app) | 597 | trans_metadata, app) |
430 | 575 | # reload to ensure we have the new package data | 598 | # reload to ensure we have the new package data |
431 | 576 | yield self.reload(sources_list=sources_list, metadata=trans_metadata) | 599 | yield self.reload(sources_list=sources_list, metadata=trans_metadata) |
432 | @@ -588,29 +611,34 @@ | |||
433 | 588 | return False | 611 | return False |
434 | 589 | 612 | ||
435 | 590 | @inline_callbacks | 613 | @inline_callbacks |
439 | 591 | def _on_reload_for_add_repo_and_install_app_finished(self, backend, trans, | 614 | def _on_reload_for_add_repo_and_install_app_finished(self, backend, trans, |
440 | 592 | result, metadata, app): | 615 | result, metadata, app): |
441 | 593 | """ | 616 | """ |
442 | 594 | callback that is called once after reload was queued | 617 | callback that is called once after reload was queued |
443 | 595 | and will trigger the install of the for-pay package itself | 618 | and will trigger the install of the for-pay package itself |
444 | 596 | (after that it will automatically de-register) | 619 | (after that it will automatically de-register) |
445 | 597 | """ | 620 | """ |
448 | 598 | #print "_on_reload_for_add_repo_and_install_app_finished", trans, result, backend, self._reload_signal_id | 621 | #print "_on_reload_for_add_repo_and_install_app_finished", trans, \ |
449 | 599 | self._logger.info("_on_reload_for_add_repo_and_install_app_finished() %s %s %s" % (trans, result, app)) | 622 | # result, backend, self._reload_signal_id |
450 | 623 | self._logger.info("_on_reload_for_add_repo_and_install_app_finished() " | ||
451 | 624 | "%s %s %s" % (trans, result, app)) | ||
452 | 600 | 625 | ||
453 | 601 | # check if this is the transaction we waiting for | 626 | # check if this is the transaction we waiting for |
454 | 602 | key = "sc_add_repo_and_install_pkgname" | 627 | key = "sc_add_repo_and_install_pkgname" |
456 | 603 | if not (key in trans.meta_data and trans.meta_data[key] == app.pkgname): | 628 | if not (key in trans.meta_data and |
457 | 629 | trans.meta_data[key] == app.pkgname): | ||
458 | 604 | return_value(None) | 630 | return_value(None) |
459 | 605 | 631 | ||
460 | 606 | # get the debline and check if we have a release.gpg file | 632 | # get the debline and check if we have a release.gpg file |
461 | 607 | deb_line = trans.meta_data["sc_add_repo_and_install_deb_line"] | 633 | deb_line = trans.meta_data["sc_add_repo_and_install_deb_line"] |
462 | 608 | license_key = trans.meta_data["sc_add_repo_and_install_license_key"] | 634 | license_key = trans.meta_data["sc_add_repo_and_install_license_key"] |
465 | 609 | license_key_path = trans.meta_data["sc_add_repo_and_install_license_key_path"] | 635 | license_key_path = trans.meta_data[ |
466 | 610 | license_key_oauth = trans.meta_data["sc_add_repo_and_install_license_key_token"] | 636 | "sc_add_repo_and_install_license_key_path"] |
467 | 637 | license_key_oauth = trans.meta_data[ | ||
468 | 638 | "sc_add_repo_and_install_license_key_token"] | ||
469 | 611 | release_filename = release_filename_in_lists_from_deb_line(deb_line) | 639 | release_filename = release_filename_in_lists_from_deb_line(deb_line) |
470 | 612 | lists_dir = apt_pkg.config.find_dir("Dir::State::lists") | 640 | lists_dir = apt_pkg.config.find_dir("Dir::State::lists") |
472 | 613 | release_signature = os.path.join(lists_dir, release_filename)+".gpg" | 641 | release_signature = os.path.join(lists_dir, release_filename) + ".gpg" |
473 | 614 | self._logger.info("looking for '%s'" % release_signature) | 642 | self._logger.info("looking for '%s'" % release_signature) |
474 | 615 | # no Release.gpg in the newly added repository, try again, | 643 | # no Release.gpg in the newly added repository, try again, |
475 | 616 | # this can happen e.g. on odd network proxies | 644 | # this can happen e.g. on odd network proxies |
476 | @@ -625,15 +653,15 @@ | |||
477 | 625 | # FIXME: this logic will *fail* if the sources.list of the user | 653 | # FIXME: this logic will *fail* if the sources.list of the user |
478 | 626 | # was broken before | 654 | # was broken before |
479 | 627 | 655 | ||
481 | 628 | # run install action if the repo was added successfully | 656 | # run install action if the repo was added successfully |
482 | 629 | if result: | 657 | if result: |
483 | 630 | self.emit("channels-changed", True) | 658 | self.emit("channels-changed", True) |
484 | 631 | 659 | ||
485 | 632 | # we use aptd_client.install_packages() here instead | 660 | # we use aptd_client.install_packages() here instead |
487 | 633 | # of just | 661 | # of just |
488 | 634 | # self.install(app, "", metadata=metadata) | 662 | # self.install(app, "", metadata=metadata) |
491 | 635 | # go get less authentication prompts (because of the 03_auth_me_less | 663 | # go get less authentication prompts (because of the |
492 | 636 | # patch in aptdaemon) | 664 | # 03_auth_me_less patch in aptdaemon) |
493 | 637 | try: | 665 | try: |
494 | 638 | self._logger.info("install_package()") | 666 | self._logger.info("install_package()") |
495 | 639 | trans = yield self.aptd_client.install_packages( | 667 | trans = yield self.aptd_client.install_packages( |
496 | @@ -648,7 +676,7 @@ | |||
497 | 648 | # but I wonder if we should ease that restriction | 676 | # but I wonder if we should ease that restriction |
498 | 649 | if license_key and not os.path.exists(license_key_path): | 677 | if license_key and not os.path.exists(license_key_path): |
499 | 650 | yield self.add_license_key( | 678 | yield self.add_license_key( |
501 | 651 | license_key, license_key_path, license_key_oauth, | 679 | license_key, license_key_path, license_key_oauth, |
502 | 652 | app.pkgname) | 680 | app.pkgname) |
503 | 653 | 681 | ||
504 | 654 | else: | 682 | else: |
505 | @@ -668,14 +696,16 @@ | |||
506 | 668 | # whole re-try machinery will not survive anyway if the local | 696 | # whole re-try machinery will not survive anyway if the local |
507 | 669 | # s-c instance is closed | 697 | # s-c instance is closed |
508 | 670 | self._logger.info("queuing reload in 30s") | 698 | self._logger.info("queuing reload in 30s") |
511 | 671 | trans.meta_data["sc_add_repo_and_install_try"]= str(retry+1) | 699 | trans.meta_data["sc_add_repo_and_install_try"] = str(retry + 1) |
512 | 672 | sourcepart = trans.meta_data["sc_add_repo_and_install_sources_list"] | 700 | sourcepart = trans.meta_data[ |
513 | 701 | "sc_add_repo_and_install_sources_list"] | ||
514 | 673 | GObject.timeout_add_seconds(30, self._reload_for_commercial_repo, | 702 | GObject.timeout_add_seconds(30, self._reload_for_commercial_repo, |
515 | 674 | app, trans.meta_data, sourcepart) | 703 | app, trans.meta_data, sourcepart) |
516 | 675 | 704 | ||
517 | 676 | # internal helpers | 705 | # internal helpers |
518 | 677 | def _on_lowlevel_transactions_changed(self, watcher, current, pending): | 706 | def _on_lowlevel_transactions_changed(self, watcher, current, pending): |
520 | 678 | # cleanup progress signal (to be sure to not leave dbus matchers around) | 707 | # cleanup progress signal (to be sure to not leave dbus |
521 | 708 | # matchers around) | ||
522 | 679 | if self._progress_signal: | 709 | if self._progress_signal: |
523 | 680 | GObject.source_remove(self._progress_signal) | 710 | GObject.source_remove(self._progress_signal) |
524 | 681 | self._progress_signal = None | 711 | self._progress_signal = None |
525 | @@ -683,7 +713,8 @@ | |||
526 | 683 | if current: | 713 | if current: |
527 | 684 | try: | 714 | try: |
528 | 685 | trans = client.get_transaction(current) | 715 | trans = client.get_transaction(current) |
530 | 686 | self._progress_signal = trans.connect("progress-changed", self._on_progress_changed) | 716 | self._progress_signal = trans.connect("progress-changed", |
531 | 717 | self._on_progress_changed) | ||
532 | 687 | except dbus.DBusException: | 718 | except dbus.DBusException: |
533 | 688 | pass | 719 | pass |
534 | 689 | 720 | ||
535 | @@ -693,12 +724,14 @@ | |||
536 | 693 | if not tid: | 724 | if not tid: |
537 | 694 | continue | 725 | continue |
538 | 695 | try: | 726 | try: |
540 | 696 | trans = client.get_transaction(tid, error_handler=lambda x: True) | 727 | trans = client.get_transaction(tid, |
541 | 728 | error_handler=lambda x: True) | ||
542 | 697 | except dbus.DBusException: | 729 | except dbus.DBusException: |
543 | 698 | continue | 730 | continue |
544 | 699 | trans_progress = TransactionProgress(trans) | 731 | trans_progress = TransactionProgress(trans) |
545 | 700 | try: | 732 | try: |
547 | 701 | self.pending_transactions[trans_progress.pkgname] = trans_progress | 733 | self.pending_transactions[trans_progress.pkgname] = \ |
548 | 734 | trans_progress | ||
549 | 702 | except KeyError: | 735 | except KeyError: |
550 | 703 | # if its not a transaction from us (sc_pkgname) still | 736 | # if its not a transaction from us (sc_pkgname) still |
551 | 704 | # add it with the tid as key to get accurate results | 737 | # add it with the tid as key to get accurate results |
552 | @@ -709,19 +742,20 @@ | |||
553 | 709 | self.inject_fake_transactions_and_emit_changed_signal() | 742 | self.inject_fake_transactions_and_emit_changed_signal() |
554 | 710 | 743 | ||
555 | 711 | def inject_fake_transactions_and_emit_changed_signal(self): | 744 | def inject_fake_transactions_and_emit_changed_signal(self): |
557 | 712 | """ | 745 | """ |
558 | 713 | ensures that the fake transactions are considered and emits | 746 | ensures that the fake transactions are considered and emits |
559 | 714 | transactions-changed signal with the right pending transactions | 747 | transactions-changed signal with the right pending transactions |
560 | 715 | """ | 748 | """ |
561 | 716 | # inject a bunch FakePurchaseTransaction into the transations dict | 749 | # inject a bunch FakePurchaseTransaction into the transations dict |
562 | 717 | for pkgname in self.pending_purchases: | 750 | for pkgname in self.pending_purchases: |
564 | 718 | self.pending_transactions[pkgname] = self.pending_purchases[pkgname] | 751 | self.pending_transactions[pkgname] = \ |
565 | 752 | self.pending_purchases[pkgname] | ||
566 | 719 | # and emit the signal | 753 | # and emit the signal |
567 | 720 | self.emit("transactions-changed", self.pending_transactions) | 754 | self.emit("transactions-changed", self.pending_transactions) |
568 | 721 | 755 | ||
569 | 722 | def _on_progress_changed(self, trans, progress): | 756 | def _on_progress_changed(self, trans, progress): |
572 | 723 | """ | 757 | """ |
573 | 724 | internal helper that gets called on our package transaction progress | 758 | internal helper that gets called on our package transaction progress |
574 | 725 | (only showing pkg progress currently) | 759 | (only showing pkg progress currently) |
575 | 726 | """ | 760 | """ |
576 | 727 | try: | 761 | try: |
577 | @@ -741,7 +775,8 @@ | |||
578 | 741 | return | 775 | return |
579 | 742 | # hide any private ppa details in the error message since it may | 776 | # hide any private ppa details in the error message since it may |
580 | 743 | # appear in the logs for LP bugs and potentially in screenshots as well | 777 | # appear in the logs for LP bugs and potentially in screenshots as well |
582 | 744 | cleaned_error_details = obfuscate_private_ppa_details(trans.error_details) | 778 | cleaned_error_details = obfuscate_private_ppa_details( |
583 | 779 | trans.error_details) | ||
584 | 745 | msg = utf8("%s: %s\n%s\n\n%s") % ( | 780 | msg = utf8("%s: %s\n%s\n\n%s") % ( |
585 | 746 | utf8(_("Error")), | 781 | utf8(_("Error")), |
586 | 747 | utf8(enums.get_error_string_from_enum(trans.error_code)), | 782 | utf8(enums.get_error_string_from_enum(trans.error_code)), |
587 | @@ -750,20 +785,23 @@ | |||
588 | 750 | self._logger.error("error in _on_trans_finished '%s'" % msg) | 785 | self._logger.error("error in _on_trans_finished '%s'" % msg) |
589 | 751 | # show dialog to the user and exit (no need to reopen the cache) | 786 | # show dialog to the user and exit (no need to reopen the cache) |
590 | 752 | if not trans.error_code: | 787 | if not trans.error_code: |
597 | 753 | # sometimes aptdaemon doesn't return a value for error_code when the network | 788 | # sometimes aptdaemon doesn't return a value for error_code |
598 | 754 | # connection has become unavailable; in that case, we will assume it's a | 789 | # when the network connection has become unavailable; in |
599 | 755 | # failure during a package download because that is the only case where we | 790 | # that case, we will assume it's a failure during a package |
600 | 756 | # see this happening - this avoids display of an empty error dialog and | 791 | # download because that is the only case where we see this |
601 | 757 | # correctly prompts the user to check their network connection (see LP: #747172) | 792 | # happening - this avoids display of an empty error dialog |
602 | 758 | # FIXME: fix aptdaemon to return a valid error_code under all conditions | 793 | # and correctly prompts the user to check their network |
603 | 794 | # connection (see LP: #747172) | ||
604 | 795 | # FIXME: fix aptdaemon to return a valid error_code under | ||
605 | 796 | # all conditions | ||
606 | 759 | trans.error_code = enums.ERROR_PACKAGE_DOWNLOAD_FAILED | 797 | trans.error_code = enums.ERROR_PACKAGE_DOWNLOAD_FAILED |
607 | 760 | # show dialog to the user and exit (no need to reopen | 798 | # show dialog to the user and exit (no need to reopen |
608 | 761 | # the cache) | 799 | # the cache) |
609 | 762 | res = self.ui.error(None, | 800 | res = self.ui.error(None, |
614 | 763 | utf8(enums.get_error_string_from_enum(trans.error_code)), | 801 | utf8(enums.get_error_string_from_enum(trans.error_code)), |
615 | 764 | utf8(enums.get_error_description_from_enum(trans.error_code)), | 802 | utf8(enums.get_error_description_from_enum(trans.error_code)), |
616 | 765 | utf8(cleaned_error_details), | 803 | utf8(cleaned_error_details), |
617 | 766 | utf8(alternative_action)) | 804 | utf8(alternative_action)) |
618 | 767 | return res | 805 | return res |
619 | 768 | 806 | ||
620 | 769 | def _get_app_and_icon_and_deb_from_trans(self, trans): | 807 | def _get_app_and_icon_and_deb_from_trans(self, trans): |
621 | @@ -794,7 +832,7 @@ | |||
622 | 794 | self.install(app, iconname, filename, [], [], | 832 | self.install(app, iconname, filename, [], [], |
623 | 795 | metadata=meta_copy, force=True) | 833 | metadata=meta_copy, force=True) |
624 | 796 | return | 834 | return |
626 | 797 | # on unauthenticated errors, try a "repair" using the | 835 | # on unauthenticated errors, try a "repair" using the |
627 | 798 | # reload functionatlity | 836 | # reload functionatlity |
628 | 799 | elif trans.error.code == enums.ERROR_PACKAGE_UNAUTHENTICATED: | 837 | elif trans.error.code == enums.ERROR_PACKAGE_UNAUTHENTICATED: |
629 | 800 | action = _("Repair") | 838 | action = _("Repair") |
630 | @@ -808,7 +846,8 @@ | |||
631 | 808 | metadata=meta_copy) | 846 | metadata=meta_copy) |
632 | 809 | return | 847 | return |
633 | 810 | 848 | ||
635 | 811 | elif not "sc_add_repo_and_install_ignore_errors" in trans.meta_data: | 849 | elif (not "sc_add_repo_and_install_ignore_errors" in |
636 | 850 | trans.meta_data): | ||
637 | 812 | self._show_transaction_failed_dialog(trans, enum) | 851 | self._show_transaction_failed_dialog(trans, enum) |
638 | 813 | 852 | ||
639 | 814 | # send finished signal, use "" here instead of None, because | 853 | # send finished signal, use "" here instead of None, because |
640 | @@ -827,7 +866,8 @@ | |||
641 | 827 | self.emit("reload-finished", trans, enum != enums.EXIT_FAILED) | 866 | self.emit("reload-finished", trans, enum != enums.EXIT_FAILED) |
642 | 828 | # send appropriate signals | 867 | # send appropriate signals |
643 | 829 | self.inject_fake_transactions_and_emit_changed_signal() | 868 | self.inject_fake_transactions_and_emit_changed_signal() |
645 | 830 | self.emit("transaction-finished", TransactionFinishedResult(trans, enum != enums.EXIT_FAILED)) | 869 | self.emit("transaction-finished", TransactionFinishedResult(trans, |
646 | 870 | enum != enums.EXIT_FAILED)) | ||
647 | 831 | 871 | ||
648 | 832 | @inline_callbacks | 872 | @inline_callbacks |
649 | 833 | def _config_file_conflict(self, transaction, old, new): | 873 | def _config_file_conflict(self, transaction, old, new): |
650 | @@ -871,7 +911,8 @@ | |||
651 | 871 | # setup debconf only if we have a pkg | 911 | # setup debconf only if we have a pkg |
652 | 872 | yield trans.set_debconf_frontend("gnome", defer=True) | 912 | yield trans.set_debconf_frontend("gnome", defer=True) |
653 | 873 | trans.set_remove_obsoleted_depends(True, defer=True) | 913 | trans.set_remove_obsoleted_depends(True, defer=True) |
655 | 874 | self._progress_signal = trans.connect("progress-changed", self._on_progress_changed) | 914 | self._progress_signal = trans.connect("progress-changed", |
656 | 915 | self._on_progress_changed) | ||
657 | 875 | self.pending_transactions[pkgname] = TransactionProgress(trans) | 916 | self.pending_transactions[pkgname] = TransactionProgress(trans) |
658 | 876 | # generic metadata | 917 | # generic metadata |
659 | 877 | if metadata: | 918 | if metadata: |
660 | @@ -919,4 +960,3 @@ | |||
661 | 919 | backend.enable_component("multiverse") | 960 | backend.enable_component("multiverse") |
662 | 920 | from gi.repository import Gtk | 961 | from gi.repository import Gtk |
663 | 921 | Gtk.main() | 962 | Gtk.main() |
664 | 922 | |||
665 | 923 | 963 | ||
666 | === modified file 'softwarecenter/backend/installbackend_impl/packagekit_enums.py' | |||
667 | --- softwarecenter/backend/installbackend_impl/packagekit_enums.py 2011-12-16 12:50:18 +0000 | |||
668 | +++ softwarecenter/backend/installbackend_impl/packagekit_enums.py 2012-03-16 20:20:25 +0000 | |||
669 | @@ -18,9 +18,11 @@ | |||
670 | 18 | 18 | ||
671 | 19 | from gi.repository import PackageKitGlib as packagekit | 19 | from gi.repository import PackageKitGlib as packagekit |
672 | 20 | 20 | ||
673 | 21 | |||
674 | 21 | # this requires packagekit 0.7.2 or better | 22 | # this requires packagekit 0.7.2 or better |
676 | 22 | def status_enum_to_localised_text (status): | 23 | def status_enum_to_localised_text(status): |
677 | 23 | return packagekit.info_enum_to_localised_present(status) | 24 | return packagekit.info_enum_to_localised_present(status) |
678 | 24 | 25 | ||
680 | 25 | def role_enum_to_localised_present (role): | 26 | |
681 | 27 | def role_enum_to_localised_present(role): | ||
682 | 26 | return packagekit.role_enum_to_localised_present(role) | 28 | return packagekit.role_enum_to_localised_present(role) |
683 | 27 | 29 | ||
684 | === modified file 'softwarecenter/backend/installbackend_impl/packagekitd.py' | |||
685 | --- softwarecenter/backend/installbackend_impl/packagekitd.py 2012-02-07 16:56:40 +0000 | |||
686 | +++ softwarecenter/backend/installbackend_impl/packagekitd.py 2012-03-16 20:20:25 +0000 | |||
687 | @@ -24,10 +24,12 @@ | |||
688 | 24 | from gi.repository import PackageKitGlib as packagekit | 24 | from gi.repository import PackageKitGlib as packagekit |
689 | 25 | 25 | ||
690 | 26 | from softwarecenter.enums import TransactionTypes | 26 | from softwarecenter.enums import TransactionTypes |
695 | 27 | from softwarecenter.backend.transactionswatcher import (BaseTransactionsWatcher, | 27 | from softwarecenter.backend.transactionswatcher import ( |
696 | 28 | BaseTransaction, | 28 | BaseTransactionsWatcher, |
697 | 29 | TransactionFinishedResult, | 29 | BaseTransaction, |
698 | 30 | TransactionProgress) | 30 | TransactionFinishedResult, |
699 | 31 | TransactionProgress | ||
700 | 32 | ) | ||
701 | 31 | from softwarecenter.backend.installbackend import InstallBackend | 33 | from softwarecenter.backend.installbackend import InstallBackend |
702 | 32 | from softwarecenter.backend.installbackend_impl import packagekit_enums | 34 | from softwarecenter.backend.installbackend_impl import packagekit_enums |
703 | 33 | 35 | ||
704 | @@ -36,9 +38,10 @@ | |||
705 | 36 | 38 | ||
706 | 37 | LOG = logging.getLogger("softwarecenter.backend.packagekit") | 39 | LOG = logging.getLogger("softwarecenter.backend.packagekit") |
707 | 38 | 40 | ||
708 | 41 | |||
709 | 39 | class PackagekitTransaction(BaseTransaction): | 42 | class PackagekitTransaction(BaseTransaction): |
710 | 40 | _meta_data = {} | 43 | _meta_data = {} |
712 | 41 | 44 | ||
713 | 42 | def __init__(self, trans): | 45 | def __init__(self, trans): |
714 | 43 | """ trans -- a PkProgress object """ | 46 | """ trans -- a PkProgress object """ |
715 | 44 | GObject.GObject.__init__(self) | 47 | GObject.GObject.__init__(self) |
716 | @@ -50,18 +53,26 @@ | |||
717 | 50 | because PK DBus exposes only a generic Changed, without | 53 | because PK DBus exposes only a generic Changed, without |
718 | 51 | specifying the property changed | 54 | specifying the property changed |
719 | 52 | """ | 55 | """ |
726 | 53 | self._trans.connect('notify::role', self._emit, 'role-changed', 'role') | 56 | self._trans.connect('notify::role', self._emit, |
727 | 54 | self._trans.connect('notify::status', self._emit, 'status-changed', 'status') | 57 | 'role-changed', 'role') |
728 | 55 | self._trans.connect('notify::percentage', self._emit, 'progress-changed', 'percentage') | 58 | self._trans.connect('notify::status', self._emit, |
729 | 56 | #self._trans.connect('notify::subpercentage', self._emit, 'progress-changed', 'subpercentage') # SC UI does not support subprogress | 59 | 'status-changed', 'status') |
730 | 57 | self._trans.connect('notify::percentage', self._emit, 'progress-changed', 'percentage') | 60 | self._trans.connect('notify::percentage', self._emit, |
731 | 58 | self._trans.connect('notify::allow-cancel', self._emit, 'cancellable-changed', 'allow-cancel') | 61 | 'progress-changed', 'percentage') |
732 | 62 | # SC UI does not support subprogress: | ||
733 | 63 | #self._trans.connect('notify::subpercentage', self._emit, | ||
734 | 64 | # 'progress-changed', 'subpercentage') | ||
735 | 65 | self._trans.connect('notify::percentage', self._emit, | ||
736 | 66 | 'progress-changed', 'percentage') | ||
737 | 67 | self._trans.connect('notify::allow-cancel', self._emit, | ||
738 | 68 | 'cancellable-changed', 'allow-cancel') | ||
739 | 59 | 69 | ||
740 | 60 | # connect the delete: | 70 | # connect the delete: |
742 | 61 | proxy = dbus.SystemBus().get_object('org.freedesktop.PackageKit', self.tid) | 71 | proxy = dbus.SystemBus().get_object('org.freedesktop.PackageKit', |
743 | 72 | self.tid) | ||
744 | 62 | trans = dbus.Interface(proxy, 'org.freedesktop.PackageKit.Transaction') | 73 | trans = dbus.Interface(proxy, 'org.freedesktop.PackageKit.Transaction') |
745 | 63 | trans.connect_to_signal("Destroy", self._remove) | 74 | trans.connect_to_signal("Destroy", self._remove) |
747 | 64 | 75 | ||
748 | 65 | def _emit(self, *args): | 76 | def _emit(self, *args): |
749 | 66 | prop, what = args[-1], args[-2] | 77 | prop, what = args[-1], args[-2] |
750 | 67 | self.emit(what, self._trans.get_property(prop)) | 78 | self.emit(what, self._trans.get_property(prop)) |
751 | @@ -69,25 +80,31 @@ | |||
752 | 69 | @property | 80 | @property |
753 | 70 | def tid(self): | 81 | def tid(self): |
754 | 71 | return self._trans.get_property('transaction-id') | 82 | return self._trans.get_property('transaction-id') |
755 | 83 | |||
756 | 72 | @property | 84 | @property |
757 | 73 | def status_details(self): | 85 | def status_details(self): |
759 | 74 | return self.get_status_description() # FIXME | 86 | return self.get_status_description() # FIXME |
760 | 87 | |||
761 | 75 | @property | 88 | @property |
762 | 76 | def meta_data(self): | 89 | def meta_data(self): |
763 | 77 | return self._meta_data | 90 | return self._meta_data |
764 | 91 | |||
765 | 78 | @property | 92 | @property |
766 | 79 | def cancellable(self): | 93 | def cancellable(self): |
767 | 80 | return self._trans.get_property('allow-cancel') | 94 | return self._trans.get_property('allow-cancel') |
768 | 95 | |||
769 | 81 | @property | 96 | @property |
770 | 82 | def progress(self): | 97 | def progress(self): |
771 | 83 | return self._trans.get_property('percentage') | 98 | return self._trans.get_property('percentage') |
772 | 84 | 99 | ||
773 | 85 | def get_role_description(self, role=None): | 100 | def get_role_description(self, role=None): |
774 | 86 | role = role if role is not None else self._trans.get_property('role') | 101 | role = role if role is not None else self._trans.get_property('role') |
776 | 87 | return self.meta_data.get('sc_appname', packagekit_enums.role_enum_to_localised_present(role)) | 102 | return self.meta_data.get('sc_appname', |
777 | 103 | packagekit_enums.role_enum_to_localised_present(role)) | ||
778 | 88 | 104 | ||
779 | 89 | def get_status_description(self, status=None): | 105 | def get_status_description(self, status=None): |
781 | 90 | status = status if status is not None else self._trans.get_property('status') | 106 | if status is None: |
782 | 107 | status = self._trans.get_property('status') | ||
783 | 91 | 108 | ||
784 | 92 | return packagekit_enums.status_enum_to_localised_text(status) | 109 | return packagekit_enums.status_enum_to_localised_text(status) |
785 | 93 | 110 | ||
786 | @@ -107,7 +124,8 @@ | |||
787 | 107 | status <= packagekit.StatusEnum.DOWNLOAD_UPDATEINFO) | 124 | status <= packagekit.StatusEnum.DOWNLOAD_UPDATEINFO) |
788 | 108 | 125 | ||
789 | 109 | def cancel(self): | 126 | def cancel(self): |
791 | 110 | proxy = dbus.SystemBus().get_object('org.freedesktop.PackageKit', self.tid) | 127 | proxy = dbus.SystemBus().get_object('org.freedesktop.PackageKit', |
792 | 128 | self.tid) | ||
793 | 111 | trans = dbus.Interface(proxy, 'org.freedesktop.PackageKit.Transaction') | 129 | trans = dbus.Interface(proxy, 'org.freedesktop.PackageKit.Transaction') |
794 | 112 | trans.Cancel() | 130 | trans.Cancel() |
795 | 113 | 131 | ||
796 | @@ -120,6 +138,7 @@ | |||
797 | 120 | del PackagekitTransactionsWatcher._tlist[self.tid] | 138 | del PackagekitTransactionsWatcher._tlist[self.tid] |
798 | 121 | LOG.debug("Delete transaction %s" % self.tid) | 139 | LOG.debug("Delete transaction %s" % self.tid) |
799 | 122 | 140 | ||
800 | 141 | |||
801 | 123 | class PackagekitTransactionsWatcher(BaseTransactionsWatcher): | 142 | class PackagekitTransactionsWatcher(BaseTransactionsWatcher): |
802 | 124 | _tlist = {} | 143 | _tlist = {} |
803 | 125 | 144 | ||
804 | @@ -128,9 +147,10 @@ | |||
805 | 128 | self.client = packagekit.Client() | 147 | self.client = packagekit.Client() |
806 | 129 | 148 | ||
807 | 130 | bus = dbus.SystemBus() | 149 | bus = dbus.SystemBus() |
809 | 131 | proxy = bus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit') | 150 | proxy = bus.get_object('org.freedesktop.PackageKit', |
810 | 151 | '/org/freedesktop/PackageKit') | ||
811 | 132 | daemon = dbus.Interface(proxy, 'org.freedesktop.PackageKit') | 152 | daemon = dbus.Interface(proxy, 'org.freedesktop.PackageKit') |
813 | 133 | daemon.connect_to_signal("TransactionListChanged", | 153 | daemon.connect_to_signal("TransactionListChanged", |
814 | 134 | self._on_transactions_changed) | 154 | self._on_transactions_changed) |
815 | 135 | queued = daemon.GetTransactionList() | 155 | queued = daemon.GetTransactionList() |
816 | 136 | self._on_transactions_changed(queued) | 156 | self._on_transactions_changed(queued) |
817 | @@ -161,29 +181,30 @@ | |||
818 | 161 | return trans | 181 | return trans |
819 | 162 | return PackagekitTransactionsWatcher._tlist[tid] | 182 | return PackagekitTransactionsWatcher._tlist[tid] |
820 | 163 | 183 | ||
821 | 184 | |||
822 | 164 | class PackagekitBackend(GObject.GObject, InstallBackend): | 185 | class PackagekitBackend(GObject.GObject, InstallBackend): |
825 | 165 | 186 | ||
826 | 166 | __gsignals__ = {'transaction-started':(GObject.SIGNAL_RUN_FIRST, | 187 | __gsignals__ = {'transaction-started': (GObject.SIGNAL_RUN_FIRST, |
827 | 167 | GObject.TYPE_NONE, | 188 | GObject.TYPE_NONE, |
829 | 168 | (str,str,str,str)), | 189 | (str, str, str, str)), |
830 | 169 | # emits a TransactionFinished object | 190 | # emits a TransactionFinished object |
835 | 170 | 'transaction-finished':(GObject.SIGNAL_RUN_FIRST, | 191 | 'transaction-finished': (GObject.SIGNAL_RUN_FIRST, |
836 | 171 | GObject.TYPE_NONE, | 192 | GObject.TYPE_NONE, |
837 | 172 | (GObject.TYPE_PYOBJECT, )), | 193 | (GObject.TYPE_PYOBJECT, )), |
838 | 173 | 'transaction-stopped':(GObject.SIGNAL_RUN_FIRST, | 194 | 'transaction-stopped': (GObject.SIGNAL_RUN_FIRST, |
839 | 174 | GObject.TYPE_NONE, | 195 | GObject.TYPE_NONE, |
840 | 175 | (GObject.TYPE_PYOBJECT,)), | 196 | (GObject.TYPE_PYOBJECT,)), |
847 | 176 | 'transactions-changed':(GObject.SIGNAL_RUN_FIRST, | 197 | 'transactions-changed': (GObject.SIGNAL_RUN_FIRST, |
848 | 177 | GObject.TYPE_NONE, | 198 | GObject.TYPE_NONE, |
849 | 178 | (GObject.TYPE_PYOBJECT, )), | 199 | (GObject.TYPE_PYOBJECT, )), |
850 | 179 | 'transaction-progress-changed':(GObject.SIGNAL_RUN_FIRST, | 200 | 'transaction-progress-changed': (GObject.SIGNAL_RUN_FIRST, |
851 | 180 | GObject.TYPE_NONE, | 201 | GObject.TYPE_NONE, |
852 | 181 | (str,int,)), | 202 | (str, int,)), |
853 | 182 | # the number/names of the available channels changed | 203 | # the number/names of the available channels changed |
854 | 183 | # FIXME: not emitted. | 204 | # FIXME: not emitted. |
858 | 184 | 'channels-changed':(GObject.SIGNAL_RUN_FIRST, | 205 | 'channels-changed': (GObject.SIGNAL_RUN_FIRST, |
859 | 185 | GObject.TYPE_NONE, | 206 | GObject.TYPE_NONE, |
860 | 186 | (bool,)), | 207 | (bool,)), |
861 | 187 | } | 208 | } |
862 | 188 | 209 | ||
863 | 189 | def __init__(self): | 210 | def __init__(self): |
864 | @@ -192,7 +213,7 @@ | |||
865 | 192 | 213 | ||
866 | 193 | # transaction details for setting as meta | 214 | # transaction details for setting as meta |
867 | 194 | self.new_pkgname, self.new_appname, self.new_iconname = '', '', '' | 215 | self.new_pkgname, self.new_appname, self.new_iconname = '', '', '' |
869 | 195 | 216 | ||
870 | 196 | # this is public exposed | 217 | # this is public exposed |
871 | 197 | self.pending_transactions = {} | 218 | self.pending_transactions = {} |
872 | 198 | 219 | ||
873 | @@ -202,11 +223,12 @@ | |||
874 | 202 | 223 | ||
875 | 203 | self._transactions_watcher = PackagekitTransactionsWatcher() | 224 | self._transactions_watcher = PackagekitTransactionsWatcher() |
876 | 204 | self._transactions_watcher.connect('lowlevel-transactions-changed', | 225 | self._transactions_watcher.connect('lowlevel-transactions-changed', |
878 | 205 | self._on_lowlevel_transactions_changed) | 226 | self._on_lowlevel_transactions_changed) |
879 | 206 | 227 | ||
880 | 207 | def upgrade(self, pkgname, appname, iconname, addons_install=[], | 228 | def upgrade(self, pkgname, appname, iconname, addons_install=[], |
881 | 208 | addons_remove=[], metadata=None): | 229 | addons_remove=[], metadata=None): |
883 | 209 | pass # FIXME implement it | 230 | pass # FIXME implement it |
884 | 231 | |||
885 | 210 | def remove(self, app, iconname, addons_install=[], | 232 | def remove(self, app, iconname, addons_install=[], |
886 | 211 | addons_remove=[], metadata=None): | 233 | addons_remove=[], metadata=None): |
887 | 212 | self.remove_multiple((app,), (iconname,), | 234 | self.remove_multiple((app,), (iconname,), |
888 | @@ -220,26 +242,29 @@ | |||
889 | 220 | appnames = [app.appname for app in apps] | 242 | appnames = [app.appname for app in apps] |
890 | 221 | 243 | ||
891 | 222 | # keep track of pkg, app and icon for setting them as meta | 244 | # keep track of pkg, app and icon for setting them as meta |
893 | 223 | self.new_pkgname, self.new_appname, self.new_iconname = pkgnames[0], appnames[0], iconnames[0] | 245 | self.new_pkgname = pkgnames[0] |
894 | 246 | self.new_appname = appnames[0] | ||
895 | 247 | self.new_iconname = iconnames[0] | ||
896 | 224 | 248 | ||
897 | 225 | # temporary hack | 249 | # temporary hack |
898 | 226 | pkgnames = self._fix_pkgnames(pkgnames) | 250 | pkgnames = self._fix_pkgnames(pkgnames) |
899 | 227 | 251 | ||
900 | 228 | self.client.remove_packages_async(pkgnames, | 252 | self.client.remove_packages_async(pkgnames, |
904 | 229 | False, # allow deps | 253 | False, # allow deps |
905 | 230 | False, # autoremove | 254 | False, # autoremove |
906 | 231 | None, # cancellable | 255 | None, # cancellable |
907 | 232 | self._on_progress_changed, | 256 | self._on_progress_changed, |
911 | 233 | None, # progress data | 257 | None, # progress data |
912 | 234 | self._on_remove_ready, # callback ready | 258 | self._on_remove_ready, # callback ready |
913 | 235 | None # callback data | 259 | None # callback data |
914 | 236 | ) | 260 | ) |
916 | 237 | self.emit("transaction-started", pkgnames[0], appnames[0], 0, TransactionTypes.REMOVE) | 261 | self.emit("transaction-started", pkgnames[0], appnames[0], 0, |
917 | 262 | TransactionTypes.REMOVE) | ||
918 | 238 | 263 | ||
919 | 239 | def install(self, app, iconname, filename=None, | 264 | def install(self, app, iconname, filename=None, |
920 | 240 | addons_install=[], addons_remove=[], metadata=None): | 265 | addons_install=[], addons_remove=[], metadata=None): |
921 | 241 | if filename is not None: | 266 | if filename is not None: |
923 | 242 | LOG.error("Filename not implemented") # FIXME | 267 | LOG.error("Filename not implemented") # FIXME |
924 | 243 | else: | 268 | else: |
925 | 244 | self.install_multiple((app,), (iconname,), | 269 | self.install_multiple((app,), (iconname,), |
926 | 245 | addons_install, addons_remove, metadata | 270 | addons_install, addons_remove, metadata |
927 | @@ -252,7 +277,9 @@ | |||
928 | 252 | appnames = [app.appname for app in apps] | 277 | appnames = [app.appname for app in apps] |
929 | 253 | 278 | ||
930 | 254 | # keep track of pkg, app and icon for setting them as meta | 279 | # keep track of pkg, app and icon for setting them as meta |
932 | 255 | self.new_pkgname, self.new_appname, self.new_iconname = pkgnames[0], appnames[0], iconnames[0] | 280 | self.new_pkgname = pkgnames[0] |
933 | 281 | self.new_appname = appnames[0] | ||
934 | 282 | self.new_iconname = iconnames[0] | ||
935 | 256 | 283 | ||
936 | 257 | # temporary hack | 284 | # temporary hack |
937 | 258 | pkgnames = self._fix_pkgnames(pkgnames) | 285 | pkgnames = self._fix_pkgnames(pkgnames) |
938 | @@ -263,19 +290,21 @@ | |||
939 | 263 | # PackageKit from installing untrusted packages | 290 | # PackageKit from installing untrusted packages |
940 | 264 | # (in general, all enabled repos should have GPG signatures, | 291 | # (in general, all enabled repos should have GPG signatures, |
941 | 265 | # which is enough for being marked "trusted", but still) | 292 | # which is enough for being marked "trusted", but still) |
943 | 266 | self.client.install_packages_async(True, # only trusted | 293 | self.client.install_packages_async(True, # only trusted |
944 | 267 | pkgnames, | 294 | pkgnames, |
946 | 268 | None, # cancellable | 295 | None, # cancellable |
947 | 269 | self._on_progress_changed, | 296 | self._on_progress_changed, |
950 | 270 | None, # progress data | 297 | None, # progress data |
951 | 271 | self._on_install_ready, # GAsyncReadyCallback | 298 | self._on_install_ready, # GAsyncReadyCallback |
952 | 272 | None # ready data | 299 | None # ready data |
953 | 273 | ) | 300 | ) |
955 | 274 | self.emit("transaction-started", pkgnames[0], appnames[0], 0, TransactionTypes.INSTALL) | 301 | self.emit("transaction-started", pkgnames[0], appnames[0], 0, |
956 | 302 | TransactionTypes.INSTALL) | ||
957 | 275 | 303 | ||
958 | 276 | def apply_changes(self, pkgname, appname, iconname, | 304 | def apply_changes(self, pkgname, appname, iconname, |
959 | 277 | addons_install=[], addons_remove=[], metadata=None): | 305 | addons_install=[], addons_remove=[], metadata=None): |
960 | 278 | pass | 306 | pass |
961 | 307 | |||
962 | 279 | def reload(self, sources_list=None, metadata=None): | 308 | def reload(self, sources_list=None, metadata=None): |
963 | 280 | """ reload package list """ | 309 | """ reload package list """ |
964 | 281 | pass | 310 | pass |
965 | @@ -313,15 +342,19 @@ | |||
966 | 313 | if self.new_pkgname not in self.pending_transactions: | 342 | if self.new_pkgname not in self.pending_transactions: |
967 | 314 | self.pending_transactions[self.new_pkgname] = trans | 343 | self.pending_transactions[self.new_pkgname] = trans |
968 | 315 | 344 | ||
970 | 316 | #LOG.debug("Progress update %s %s %s %s" % (status, ptype, progress.get_property('transaction-id'),progress.get_property('status'))) | 345 | # LOG.debug("Progress update %s %s %s %s" % |
971 | 346 | # (status, ptype, progress.get_property('transaction-id'), | ||
972 | 347 | # progress.get_property('status'))) | ||
973 | 317 | 348 | ||
974 | 318 | if status == packagekit.StatusEnum.FINISHED: | 349 | if status == packagekit.StatusEnum.FINISHED: |
975 | 319 | LOG.debug("Transaction finished %s" % tid) | 350 | LOG.debug("Transaction finished %s" % tid) |
977 | 320 | self.emit("transaction-finished", TransactionFinishedResult(trans, True)) | 351 | self.emit("transaction-finished", |
978 | 352 | TransactionFinishedResult(trans, True)) | ||
979 | 321 | 353 | ||
980 | 322 | if status == packagekit.StatusEnum.CANCEL: | 354 | if status == packagekit.StatusEnum.CANCEL: |
981 | 323 | LOG.debug("Transaction canceled %s" % tid) | 355 | LOG.debug("Transaction canceled %s" % tid) |
983 | 324 | self.emit("transaction-stopped", TransactionFinishedResult(trans, True)) | 356 | self.emit("transaction-stopped", |
984 | 357 | TransactionFinishedResult(trans, True)) | ||
985 | 325 | 358 | ||
986 | 326 | if ptype == packagekit.ProgressType.PACKAGE: | 359 | if ptype == packagekit.ProgressType.PACKAGE: |
987 | 327 | # this should be done better | 360 | # this should be done better |
988 | @@ -348,7 +381,8 @@ | |||
989 | 348 | trans = self._transactions_watcher.get_transaction(tid) | 381 | trans = self._transactions_watcher.get_transaction(tid) |
990 | 349 | trans_progress = TransactionProgress(trans) | 382 | trans_progress = TransactionProgress(trans) |
991 | 350 | try: | 383 | try: |
993 | 351 | self.pending_transactions[trans_progress.pkgname] = trans_progress | 384 | self.pending_transactions[ |
994 | 385 | trans_progress.pkgname] = trans_progress | ||
995 | 352 | except: | 386 | except: |
996 | 353 | self.pending_transactions[trans.tid] = trans_progress | 387 | self.pending_transactions[trans.tid] = trans_progress |
997 | 354 | 388 | ||
998 | @@ -375,7 +409,7 @@ | |||
999 | 375 | 409 | ||
1000 | 376 | loop = dbus.mainloop.glib.DBusGMainLoop() | 410 | loop = dbus.mainloop.glib.DBusGMainLoop() |
1001 | 377 | dbus.set_default_main_loop(loop) | 411 | dbus.set_default_main_loop(loop) |
1003 | 378 | 412 | ||
1004 | 379 | backend = PackagekitBackend() | 413 | backend = PackagekitBackend() |
1005 | 380 | pkginfo = get_pkg_info() | 414 | pkginfo = get_pkg_info() |
1006 | 381 | if pkginfo[package].is_installed: | 415 | if pkginfo[package].is_installed: |
1007 | @@ -387,4 +421,3 @@ | |||
1008 | 387 | from gi.repository import Gtk | 421 | from gi.repository import Gtk |
1009 | 388 | Gtk.main() | 422 | Gtk.main() |
1010 | 389 | #print backend._fix_pkgnames(('cheese',)) | 423 | #print backend._fix_pkgnames(('cheese',)) |
1011 | 390 | |||
1012 | 391 | 424 | ||
1013 | === modified file 'softwarecenter/backend/piston/rnrclient.py' | |||
1014 | --- softwarecenter/backend/piston/rnrclient.py 2011-10-26 10:25:49 +0000 | |||
1015 | +++ softwarecenter/backend/piston/rnrclient.py 2012-03-16 20:20:25 +0000 | |||
1016 | @@ -31,15 +31,18 @@ | |||
1017 | 31 | # get the server to use | 31 | # get the server to use |
1018 | 32 | from softwarecenter.distro import get_distro | 32 | from softwarecenter.distro import get_distro |
1019 | 33 | distro = get_distro() | 33 | distro = get_distro() |
1021 | 34 | SERVER_ROOT=distro.REVIEWS_SERVER | 34 | SERVER_ROOT = distro.REVIEWS_SERVER |
1022 | 35 | 35 | ||
1023 | 36 | try: | 36 | try: |
1024 | 37 | if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ: | 37 | if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ: |
1026 | 38 | from softwarecenter.backend.piston.rnrclient_fake import RatingsAndReviewsAPI | 38 | from softwarecenter.backend.piston.rnrclient_fake import ( |
1027 | 39 | RatingsAndReviewsAPI | ||
1028 | 40 | ) | ||
1029 | 39 | RatingsAndReviewsAPI.default_service_root = SERVER_ROOT | 41 | RatingsAndReviewsAPI.default_service_root = SERVER_ROOT |
1030 | 40 | import rnrclient_fake | 42 | import rnrclient_fake |
1031 | 41 | rnrclient_fake | 43 | rnrclient_fake |
1033 | 42 | LOG.warn("using FAKE review api, data returned will be dummy data only") | 44 | LOG.warn("using FAKE review api, data returned will be dummy " |
1034 | 45 | "data only") | ||
1035 | 43 | else: | 46 | else: |
1036 | 44 | # patch default_service_root | 47 | # patch default_service_root |
1037 | 45 | from rnrclient_pristine import RatingsAndReviewsAPI | 48 | from rnrclient_pristine import RatingsAndReviewsAPI |
1038 | @@ -68,22 +71,24 @@ | |||
1039 | 68 | # dump all reviews | 71 | # dump all reviews |
1040 | 69 | for stat in rnr.review_stats(): | 72 | for stat in rnr.review_stats(): |
1041 | 70 | print("stats for (pkg='%s', app: '%s'): avg=%s total=%s" % ( | 73 | print("stats for (pkg='%s', app: '%s'): avg=%s total=%s" % ( |
1043 | 71 | stat.package_name, stat.app_name, stat.ratings_average, stat.ratings_total)) | 74 | stat.package_name, stat.app_name, stat.ratings_average, |
1044 | 75 | stat.ratings_total)) | ||
1045 | 72 | reviews = rnr.get_reviews( | 76 | reviews = rnr.get_reviews( |
1046 | 73 | language="any", origin="ubuntu", distroseries="natty", | 77 | language="any", origin="ubuntu", distroseries="natty", |
1047 | 74 | packagename=stat.package_name, | 78 | packagename=stat.package_name, |
1048 | 75 | appname=urllib.quote_plus(stat.app_name.encode("utf-8"))) | 79 | appname=urllib.quote_plus(stat.app_name.encode("utf-8"))) |
1049 | 76 | for review in reviews: | 80 | for review in reviews: |
1051 | 77 | print("rating: %s user=%s" % (review.rating, review.reviewer_username)) | 81 | print("rating: %s user=%s" % (review.rating, |
1052 | 82 | review.reviewer_username)) | ||
1053 | 78 | print(review.summary) | 83 | print(review.summary) |
1054 | 79 | print(review.review_text) | 84 | print(review.review_text) |
1055 | 80 | print("\n") | 85 | print("\n") |
1057 | 81 | 86 | ||
1058 | 82 | # get individual ones | 87 | # get individual ones |
1061 | 83 | reviews = rnr.get_reviews(language="en",origin="ubuntu",distroseries="maverick", | 88 | reviews = rnr.get_reviews(language="en", origin="ubuntu", |
1062 | 84 | packagename="unace", appname="ACE") | 89 | distroseries="maverick", packagename="unace", appname="ACE") |
1063 | 85 | print(reviews) | 90 | print(reviews) |
1065 | 86 | print(rnr.get_reviews(language="en",origin="ubuntu",distroseries="natty", | 91 | print(rnr.get_reviews(language="en", origin="ubuntu", distroseries="natty", |
1066 | 87 | packagename="aclock.app")) | 92 | packagename="aclock.app")) |
1067 | 88 | print(rnr.get_reviews(language="en", origin="ubuntu", distroseries="natty", | 93 | print(rnr.get_reviews(language="en", origin="ubuntu", distroseries="natty", |
1068 | 89 | packagename="unace", appname="ACE")) | 94 | packagename="unace", appname="ACE")) |
1069 | 90 | 95 | ||
1070 | === modified file 'softwarecenter/backend/piston/rnrclient_fake.py' | |||
1071 | --- softwarecenter/backend/piston/rnrclient_fake.py 2011-08-15 11:55:13 +0000 | |||
1072 | +++ softwarecenter/backend/piston/rnrclient_fake.py 2012-03-16 20:20:25 +0000 | |||
1073 | @@ -17,36 +17,40 @@ | |||
1074 | 17 | AUTHENTICATED_API_SCHEME = 'https' | 17 | AUTHENTICATED_API_SCHEME = 'https' |
1075 | 18 | 18 | ||
1076 | 19 | from rnrclient_pristine import ReviewRequest, ReviewsStats, ReviewDetails | 19 | from rnrclient_pristine import ReviewRequest, ReviewsStats, ReviewDetails |
1078 | 20 | from softwarecenter.backend.fake_review_settings import FakeReviewSettings, network_delay | 20 | from softwarecenter.backend.fake_review_settings import ( |
1079 | 21 | FakeReviewSettings, | ||
1080 | 22 | network_delay, | ||
1081 | 23 | ) | ||
1082 | 21 | import json | 24 | import json |
1083 | 22 | import random | 25 | import random |
1084 | 23 | import time | 26 | import time |
1085 | 24 | 27 | ||
1086 | 25 | 28 | ||
1087 | 26 | class RatingsAndReviewsAPI(PistonAPI): | 29 | class RatingsAndReviewsAPI(PistonAPI): |
1094 | 27 | """A fake client pretending to be RAtingsAndReviewsAPI from rnrclient_pristine. | 30 | """A fake client pretending to be RAtingsAndReviewsAPI from |
1095 | 28 | Uses settings from test.fake_review_settings.FakeReviewSettings | 31 | rnrclient_pristine. Uses settings from |
1096 | 29 | to provide predictable responses to methods that try to use the | 32 | test.fake_review_settings.FakeReviewSettings |
1097 | 30 | RatingsAndReviewsAPI for testing purposes (i.e. without network activity). | 33 | to provide predictable responses to methods that try to use the |
1098 | 31 | To use this, instead of importing from rnrclient_pristine, you can import | 34 | RatingsAndReviewsAPI for testing purposes (i.e. without network |
1099 | 32 | from rnrclient_fake instead. | 35 | activity). |
1100 | 36 | To use this, instead of importing from rnrclient_pristine, you can | ||
1101 | 37 | import from rnrclient_fake instead. | ||
1102 | 33 | """ | 38 | """ |
1104 | 34 | 39 | ||
1105 | 35 | default_service_root = 'http://localhost:8000/reviews/api/1.0' | 40 | default_service_root = 'http://localhost:8000/reviews/api/1.0' |
1106 | 36 | default_content_type = 'application/x-www-form-urlencoded' | 41 | default_content_type = 'application/x-www-form-urlencoded' |
1107 | 37 | _exception_msg = 'Fake RatingsAndReviewsAPI raising fake exception' | 42 | _exception_msg = 'Fake RatingsAndReviewsAPI raising fake exception' |
1113 | 38 | _PACKAGE_NAMES = ['armagetronad', 'compizconfig-settings-manager', 'file-roller', | 43 | _PACKAGE_NAMES = ['armagetronad', 'compizconfig-settings-manager', |
1114 | 39 | 'aisleriot', 'p7zip-full', 'compiz-core', 'banshee', | 44 | 'file-roller', 'aisleriot', 'p7zip-full', 'compiz-core', |
1115 | 40 | 'gconf-editor', 'nanny', '3depict', 'apturl', 'jockey-gtk', | 45 | 'banshee', 'gconf-editor', 'nanny', '3depict', 'apturl', |
1116 | 41 | 'alex4', 'bzr-explorer', 'aqualung'] | 46 | 'jockey-gtk', 'alex4', 'bzr-explorer', 'aqualung'] |
1117 | 42 | _USERS = ["Joe Doll", "John Foo", "Cat Lala", "Foo Grumpf", | 47 | _USERS = ["Joe Doll", "John Foo", "Cat Lala", "Foo Grumpf", |
1118 | 43 | "Bar Tender", "Baz Lightyear"] | 48 | "Bar Tender", "Baz Lightyear"] |
1119 | 44 | _SUMMARIES = ["Cool", "Medium", "Bad", "Too difficult"] | 49 | _SUMMARIES = ["Cool", "Medium", "Bad", "Too difficult"] |
1121 | 45 | _TEXT = ["Review text number 1", "Review text number 2", | 50 | _TEXT = ["Review text number 1", "Review text number 2", |
1122 | 46 | "Review text number 3", "Review text number 4"] | 51 | "Review text number 3", "Review text number 4"] |
1123 | 47 | _fake_settings = FakeReviewSettings() | 52 | _fake_settings = FakeReviewSettings() |
1124 | 48 | 53 | ||
1125 | 49 | |||
1126 | 50 | @returns_json | 54 | @returns_json |
1127 | 51 | @network_delay | 55 | @network_delay |
1128 | 52 | def server_status(self): | 56 | def server_status(self): |
1129 | @@ -54,32 +58,31 @@ | |||
1130 | 54 | raise APIError(self._exception_msg) | 58 | raise APIError(self._exception_msg) |
1131 | 55 | return json.dumps('ok') | 59 | return json.dumps('ok') |
1132 | 56 | 60 | ||
1133 | 57 | |||
1134 | 58 | @validate_pattern('origin', r'[0-9a-z+-.:/]+', required=False) | 61 | @validate_pattern('origin', r'[0-9a-z+-.:/]+', required=False) |
1135 | 59 | @validate_pattern('distroseries', r'\w+', required=False) | 62 | @validate_pattern('distroseries', r'\w+', required=False) |
1136 | 60 | @validate('days', int, required=False) | 63 | @validate('days', int, required=False) |
1137 | 61 | @returns_list_of(ReviewsStats) | 64 | @returns_list_of(ReviewsStats) |
1138 | 62 | @network_delay | 65 | @network_delay |
1139 | 63 | def review_stats(self, origin='any', distroseries='any', days=None, | 66 | def review_stats(self, origin='any', distroseries='any', days=None, |
1141 | 64 | valid_days=(1,3,7)): | 67 | valid_days=(1, 3, 7)): |
1142 | 65 | if self._fake_settings.get_setting('review_stats_error'): | 68 | if self._fake_settings.get_setting('review_stats_error'): |
1143 | 66 | raise APIError(self._exception_msg) | 69 | raise APIError(self._exception_msg) |
1145 | 67 | 70 | ||
1146 | 68 | if self._fake_settings.get_setting('packages_returned') > 15: | 71 | if self._fake_settings.get_setting('packages_returned') > 15: |
1147 | 69 | quantity = 15 | 72 | quantity = 15 |
1148 | 70 | else: | 73 | else: |
1149 | 71 | quantity = self._fake_settings.get_setting('packages_returned') | 74 | quantity = self._fake_settings.get_setting('packages_returned') |
1151 | 72 | 75 | ||
1152 | 73 | stats = [] | 76 | stats = [] |
1159 | 74 | 77 | ||
1160 | 75 | for i in range (0, quantity): | 78 | for i in range(0, quantity): |
1161 | 76 | s = {'app_name':'', | 79 | s = {'app_name': '', |
1162 | 77 | 'package_name':self._PACKAGE_NAMES[i], | 80 | 'package_name': self._PACKAGE_NAMES[i], |
1163 | 78 | 'ratings_total': str(random.randrange(1,200)), | 81 | 'ratings_total': str(random.randrange(1, 200)), |
1164 | 79 | 'ratings_average': str(random.randrange(0,5)) | 82 | 'ratings_average': str(random.randrange(0, 5)) |
1165 | 80 | } | 83 | } |
1166 | 81 | stats.append(s) | 84 | stats.append(s) |
1168 | 82 | 85 | ||
1169 | 83 | return json.dumps(stats) | 86 | return json.dumps(stats) |
1170 | 84 | 87 | ||
1171 | 85 | @validate_pattern('language', r'\w+', required=False) | 88 | @validate_pattern('language', r'\w+', required=False) |
1172 | @@ -94,7 +97,7 @@ | |||
1173 | 94 | @network_delay | 97 | @network_delay |
1174 | 95 | def get_reviews(self, packagename, language='any', origin='any', | 98 | def get_reviews(self, packagename, language='any', origin='any', |
1175 | 96 | distroseries='any', version='any', appname='', page=1, sort='helpful'): | 99 | distroseries='any', version='any', appname='', page=1, sort='helpful'): |
1177 | 97 | 100 | ||
1178 | 98 | # work out how many reviews to return for pagination | 101 | # work out how many reviews to return for pagination |
1179 | 99 | if page <= self._fake_settings.get_setting('review_pages'): | 102 | if page <= self._fake_settings.get_setting('review_pages'): |
1180 | 100 | num_reviews = 10 | 103 | num_reviews = 10 |
1181 | @@ -102,10 +105,10 @@ | |||
1182 | 102 | num_reviews = self._fake_settings.get_setting('reviews_returned') | 105 | num_reviews = self._fake_settings.get_setting('reviews_returned') |
1183 | 103 | else: | 106 | else: |
1184 | 104 | num_reviews = 0 | 107 | num_reviews = 0 |
1186 | 105 | 108 | ||
1187 | 106 | if self._fake_settings.get_setting('get_reviews_error'): | 109 | if self._fake_settings.get_setting('get_reviews_error'): |
1188 | 107 | raise APIError(self._exception_msg) | 110 | raise APIError(self._exception_msg) |
1190 | 108 | 111 | ||
1191 | 109 | reviews = self._make_fake_reviews(packagename, num_reviews) | 112 | reviews = self._make_fake_reviews(packagename, num_reviews) |
1192 | 110 | return json.dumps(reviews) | 113 | return json.dumps(reviews) |
1193 | 111 | 114 | ||
1194 | @@ -124,9 +127,11 @@ | |||
1195 | 124 | def submit_review(self, review): | 127 | def submit_review(self, review): |
1196 | 125 | if self._fake_settings.get_setting('submit_review_error'): | 128 | if self._fake_settings.get_setting('submit_review_error'): |
1197 | 126 | raise APIError(self._exception_msg) | 129 | raise APIError(self._exception_msg) |
1201 | 127 | 130 | ||
1202 | 128 | user = self._fake_settings.get_setting('reviewer_username') or random.choice(self._USERS) | 131 | user = self._fake_settings.get_setting( |
1203 | 129 | review_id = self._fake_settings.get_setting('submit_review_id') or random.randint(1,10000) | 132 | 'reviewer_username') or random.choice(self._USERS) |
1204 | 133 | review_id = self._fake_settings.get_setting( | ||
1205 | 134 | 'submit_review_id') or random.randint(1, 10000) | ||
1206 | 130 | r = { | 135 | r = { |
1207 | 131 | "origin": review.origin, | 136 | "origin": review.origin, |
1208 | 132 | "rating": review.rating, | 137 | "rating": review.rating, |
1209 | @@ -156,13 +161,15 @@ | |||
1210 | 156 | def flag_review(self, review_id, reason, text): | 161 | def flag_review(self, review_id, reason, text): |
1211 | 157 | if self._fake_settings.get_setting('flag_review_error'): | 162 | if self._fake_settings.get_setting('flag_review_error'): |
1212 | 158 | raise APIError(self._exception_msg) | 163 | raise APIError(self._exception_msg) |
1217 | 159 | 164 | ||
1218 | 160 | mod_id = random.randint(1,500) | 165 | mod_id = random.randint(1, 500) |
1219 | 161 | pkg = self._fake_settings.get_setting('flag_package_name') or random.choice(self._PACKAGE_NAMES) | 166 | pkg = self._fake_settings.get_setting( |
1220 | 162 | username = self._fake_settings.get_setting('flagger_username') or random.choice(self._USERS) | 167 | 'flag_package_name') or random.choice(self._PACKAGE_NAMES) |
1221 | 168 | username = self._fake_settings.get_setting( | ||
1222 | 169 | 'flagger_username') or random.choice(self._USERS) | ||
1223 | 163 | 170 | ||
1224 | 164 | f = { | 171 | f = { |
1226 | 165 | "user_id": random.randint(1,500), | 172 | "user_id": random.randint(1, 500), |
1227 | 166 | "description": text, | 173 | "description": text, |
1228 | 167 | "review_moderation_id": mod_id, | 174 | "review_moderation_id": mod_id, |
1229 | 168 | "_user_cache": self._make_user_cache(username), | 175 | "_user_cache": self._make_user_cache(username), |
1230 | @@ -170,7 +177,7 @@ | |||
1231 | 170 | "_review_moderation_cache": { | 177 | "_review_moderation_cache": { |
1232 | 171 | "status": 0, | 178 | "status": 0, |
1233 | 172 | "review_id": review_id, | 179 | "review_id": review_id, |
1235 | 173 | "_review_cache": self._make_fake_reviews(packagename=pkg, | 180 | "_review_cache": self._make_fake_reviews(packagename=pkg, |
1236 | 174 | single_id=review_id), | 181 | single_id=review_id), |
1237 | 175 | "moderation_text": text, | 182 | "moderation_text": text, |
1238 | 176 | "date_moderated": None, | 183 | "date_moderated": None, |
1239 | @@ -191,7 +198,8 @@ | |||
1240 | 191 | def submit_usefulness(self, review_id, useful): | 198 | def submit_usefulness(self, review_id, useful): |
1241 | 192 | if self._fake_settings.get_setting('submit_usefulness_error'): | 199 | if self._fake_settings.get_setting('submit_usefulness_error'): |
1242 | 193 | raise APIError(self._exception_msg) | 200 | raise APIError(self._exception_msg) |
1244 | 194 | return json.dumps(self._fake_settings.get_setting('usefulness_response_string')) | 201 | return json.dumps(self._fake_settings.get_setting( |
1245 | 202 | 'usefulness_response_string')) | ||
1246 | 195 | 203 | ||
1247 | 196 | @validate('review_id', int, required=False) | 204 | @validate('review_id', int, required=False) |
1248 | 197 | @validate_pattern('username', r'[^\n]+', required=False) | 205 | @validate_pattern('username', r'[^\n]+', required=False) |
1249 | @@ -200,24 +208,24 @@ | |||
1250 | 200 | def get_usefulness(self, review_id=None, username=None): | 208 | def get_usefulness(self, review_id=None, username=None): |
1251 | 201 | if not username and not review_id: | 209 | if not username and not review_id: |
1252 | 202 | return None | 210 | return None |
1254 | 203 | 211 | ||
1255 | 204 | if self._fake_settings.get_setting('get_usefulness_error'): | 212 | if self._fake_settings.get_setting('get_usefulness_error'): |
1256 | 205 | raise APIError(self._exception_msg) | 213 | raise APIError(self._exception_msg) |
1258 | 206 | 214 | ||
1259 | 207 | #just return a single fake item if the review_id was supplied | 215 | #just return a single fake item if the review_id was supplied |
1260 | 208 | if review_id: | 216 | if review_id: |
1261 | 209 | if username: | 217 | if username: |
1262 | 210 | response_user = username | 218 | response_user = username |
1263 | 211 | else: | 219 | else: |
1264 | 212 | response_user = random.choice(self._USERS) | 220 | response_user = random.choice(self._USERS) |
1266 | 213 | 221 | ||
1267 | 214 | response = { | 222 | response = { |
1271 | 215 | 'username':response_user, | 223 | 'username': response_user, |
1272 | 216 | 'useful':random.choice(['True','False']), | 224 | 'useful': random.choice(['True', 'False']), |
1273 | 217 | 'review_id':review_id | 225 | 'review_id': review_id |
1274 | 218 | } | 226 | } |
1275 | 219 | return json.dumps([response]) | 227 | return json.dumps([response]) |
1277 | 220 | 228 | ||
1278 | 221 | #set up review ids to honour requested and also add randoms | 229 | #set up review ids to honour requested and also add randoms |
1279 | 222 | quantity = self._fake_settings.get_setting('votes_returned') | 230 | quantity = self._fake_settings.get_setting('votes_returned') |
1280 | 223 | id_list = self._fake_settings.get_setting('required_review_ids') | 231 | id_list = self._fake_settings.get_setting('required_review_ids') |
1281 | @@ -228,23 +236,23 @@ | |||
1282 | 228 | rand_id_start = 0 | 236 | rand_id_start = 0 |
1283 | 229 | else: | 237 | else: |
1284 | 230 | rand_id_start = max(id_list) | 238 | rand_id_start = max(id_list) |
1286 | 231 | 239 | ||
1287 | 232 | votes = [] | 240 | votes = [] |
1289 | 233 | 241 | ||
1290 | 234 | for i in range(0, quantity): | 242 | for i in range(0, quantity): |
1291 | 235 | #assign review ids requested if any still exist | 243 | #assign review ids requested if any still exist |
1292 | 236 | try: | 244 | try: |
1293 | 237 | id = id_list[i] | 245 | id = id_list[i] |
1294 | 238 | except IndexError: | 246 | except IndexError: |
1297 | 239 | id = random.randint(rand_id_start,10000) | 247 | id = random.randint(rand_id_start, 10000) |
1298 | 240 | 248 | ||
1299 | 241 | u = { | 249 | u = { |
1303 | 242 | 'username': username, | 250 | 'username': username, |
1304 | 243 | 'useful': random.choice(['True','False']), | 251 | 'useful': random.choice(['True', 'False']), |
1305 | 244 | 'review_id' : id | 252 | 'review_id': id |
1306 | 245 | } | 253 | } |
1307 | 246 | votes.append(u) | 254 | votes.append(u) |
1309 | 247 | 255 | ||
1310 | 248 | return json.dumps(votes) | 256 | return json.dumps(votes) |
1311 | 249 | 257 | ||
1312 | 250 | @validate('review_id', int) | 258 | @validate('review_id', int) |
1313 | @@ -261,29 +269,28 @@ | |||
1314 | 261 | def modify_review(self, review_id, rating, summary, review_text): | 269 | def modify_review(self, review_id, rating, summary, review_text): |
1315 | 262 | """Modify an existing review""" | 270 | """Modify an existing review""" |
1316 | 263 | return json.dumps(self._make_fake_reviews()[0]) | 271 | return json.dumps(self._make_fake_reviews()[0]) |
1320 | 264 | 272 | ||
1321 | 265 | 273 | def _make_fake_reviews(self, packagename='compiz-core', | |
1319 | 266 | def _make_fake_reviews(self, packagename='compiz-core', | ||
1322 | 267 | quantity=1, single_id=None): | 274 | quantity=1, single_id=None): |
1323 | 268 | """Make and return a requested quantity of fake reviews""" | 275 | """Make and return a requested quantity of fake reviews""" |
1325 | 269 | 276 | ||
1326 | 270 | reviews = [] | 277 | reviews = [] |
1328 | 271 | 278 | ||
1329 | 272 | for i in range(0, quantity): | 279 | for i in range(0, quantity): |
1330 | 273 | if quantity == 1 and single_id: | 280 | if quantity == 1 and single_id: |
1331 | 274 | id = single_id | 281 | id = single_id |
1332 | 275 | else: | 282 | else: |
1335 | 276 | id = i*3 | 283 | id = i * 3 |
1336 | 277 | 284 | ||
1337 | 278 | r = { | 285 | r = { |
1338 | 279 | "origin": "ubuntu", | 286 | "origin": "ubuntu", |
1340 | 280 | "rating": random.randint(1,5), | 287 | "rating": random.randint(1, 5), |
1341 | 281 | "hide": False, | 288 | "hide": False, |
1342 | 282 | "app_name": "", | 289 | "app_name": "", |
1343 | 283 | "language": "en", | 290 | "language": "en", |
1344 | 284 | "reviewer_username": random.choice(self._USERS), | 291 | "reviewer_username": random.choice(self._USERS), |
1347 | 285 | "usefulness_total": random.randint(3,6), | 292 | "usefulness_total": random.randint(3, 6), |
1348 | 286 | "usefulness_favorable": random.randint(1,3), | 293 | "usefulness_favorable": random.randint(1, 3), |
1349 | 287 | "review_text": random.choice(self._TEXT), | 294 | "review_text": random.choice(self._TEXT), |
1350 | 288 | "date_deleted": None, | 295 | "date_deleted": None, |
1351 | 289 | "summary": random.choice(self._SUMMARIES), | 296 | "summary": random.choice(self._SUMMARIES), |
1352 | @@ -295,13 +302,13 @@ | |||
1353 | 295 | "distroseries": "natty" | 302 | "distroseries": "natty" |
1354 | 296 | } | 303 | } |
1355 | 297 | reviews.append(r) | 304 | reviews.append(r) |
1357 | 298 | 305 | ||
1358 | 299 | #get_review wants a dict but get_reviews wants a list of dicts | 306 | #get_review wants a dict but get_reviews wants a list of dicts |
1359 | 300 | if single_id: | 307 | if single_id: |
1360 | 301 | return r | 308 | return r |
1361 | 302 | else: | 309 | else: |
1362 | 303 | return reviews | 310 | return reviews |
1364 | 304 | 311 | ||
1365 | 305 | def _make_user_cache(self, username): | 312 | def _make_user_cache(self, username): |
1366 | 306 | return { | 313 | return { |
1367 | 307 | "username": username, | 314 | "username": username, |
1368 | @@ -313,7 +320,6 @@ | |||
1369 | 313 | "is_staff": False, | 320 | "is_staff": False, |
1370 | 314 | "last_login": time.strftime("%Y-%m-%d %H:%M:%S"), | 321 | "last_login": time.strftime("%Y-%m-%d %H:%M:%S"), |
1371 | 315 | "password": "!", | 322 | "password": "!", |
1373 | 316 | "id": random.randint(1,500), | 323 | "id": random.randint(1, 500), |
1374 | 317 | "date_joined": time.strftime("%Y-%m-%d %H:%M:%S") | 324 | "date_joined": time.strftime("%Y-%m-%d %H:%M:%S") |
1375 | 318 | } | 325 | } |
1376 | 319 | |||
1377 | 320 | 326 | ||
1378 | === modified file 'softwarecenter/backend/piston/rnrclient_pristine.py' | |||
1379 | --- softwarecenter/backend/piston/rnrclient_pristine.py 2011-08-15 11:55:13 +0000 | |||
1380 | +++ softwarecenter/backend/piston/rnrclient_pristine.py 2012-03-16 20:20:25 +0000 | |||
1381 | @@ -29,6 +29,7 @@ | |||
1382 | 29 | 'rating', 'language', 'origin', 'distroseries', 'arch_tag') | 29 | 'rating', 'language', 'origin', 'distroseries', 'arch_tag') |
1383 | 30 | app_name = '' | 30 | app_name = '' |
1384 | 31 | 31 | ||
1385 | 32 | |||
1386 | 32 | class ReviewsStats(PistonResponseObject): | 33 | class ReviewsStats(PistonResponseObject): |
1387 | 33 | """A ratings summary for a package/app. | 34 | """A ratings summary for a package/app. |
1388 | 34 | 35 | ||
1389 | @@ -82,7 +83,7 @@ | |||
1390 | 82 | @validate('days', int, required=False) | 83 | @validate('days', int, required=False) |
1391 | 83 | @returns_list_of(ReviewsStats) | 84 | @returns_list_of(ReviewsStats) |
1392 | 84 | def review_stats(self, origin='any', distroseries='any', days=None, | 85 | def review_stats(self, origin='any', distroseries='any', days=None, |
1394 | 85 | valid_days=(1,3,7)): | 86 | valid_days=(1, 3, 7)): |
1395 | 86 | """Fetch ratings for a particular distroseries""" | 87 | """Fetch ratings for a particular distroseries""" |
1396 | 87 | url = 'review-stats/{0}/{1}/'.format(origin, distroseries) | 88 | url = 'review-stats/{0}/{1}/'.format(origin, distroseries) |
1397 | 88 | if days is not None: | 89 | if days is not None: |
1398 | @@ -115,7 +116,7 @@ | |||
1399 | 115 | appname = quote_plus(';' + appname) | 116 | appname = quote_plus(';' + appname) |
1400 | 116 | return self._get('reviews/filter/%s/%s/%s/%s/%s%s/page/%s/%s/' % ( | 117 | return self._get('reviews/filter/%s/%s/%s/%s/%s%s/page/%s/%s/' % ( |
1401 | 117 | language, origin, distroseries, version, packagename, | 118 | language, origin, distroseries, version, packagename, |
1403 | 118 | appname, page, sort), | 119 | appname, page, sort), |
1404 | 119 | scheme=PUBLIC_API_SCHEME) | 120 | scheme=PUBLIC_API_SCHEME) |
1405 | 120 | 121 | ||
1406 | 121 | @validate('review_id', int) | 122 | @validate('review_id', int) |
1407 | @@ -183,6 +184,10 @@ | |||
1408 | 183 | @returns(ReviewDetails) | 184 | @returns(ReviewDetails) |
1409 | 184 | def modify_review(self, review_id, rating, summary, review_text): | 185 | def modify_review(self, review_id, rating, summary, review_text): |
1410 | 185 | """Modify an existing review""" | 186 | """Modify an existing review""" |
1412 | 186 | data = {'rating':rating, 'summary':summary, 'review_text':review_text} | 187 | data = { |
1413 | 188 | 'rating': rating, | ||
1414 | 189 | 'summary': summary, | ||
1415 | 190 | 'review_text': review_text | ||
1416 | 191 | } | ||
1417 | 187 | return self._put('/reviews/modify/%s/' % review_id, data=data, | 192 | return self._put('/reviews/modify/%s/' % review_id, data=data, |
1418 | 188 | scheme=AUTHENTICATED_API_SCHEME) | 193 | scheme=AUTHENTICATED_API_SCHEME) |
1419 | 189 | 194 | ||
1420 | === modified file 'softwarecenter/backend/piston/scaclient.py' | |||
1421 | --- softwarecenter/backend/piston/scaclient.py 2012-01-03 16:48:01 +0000 | |||
1422 | +++ softwarecenter/backend/piston/scaclient.py 2012-03-16 20:20:25 +0000 | |||
1423 | @@ -14,7 +14,7 @@ | |||
1424 | 14 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 14 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1425 | 15 | # | 15 | # |
1426 | 16 | # | 16 | # |
1428 | 17 | # taken from lp:~canonical-ca-hackers/software-center/scaclient | 17 | # taken from lp:~canonical-ca-hackers/software-center/scaclient |
1429 | 18 | # and put into scaclient_pristine.py | 18 | # and put into scaclient_pristine.py |
1430 | 19 | 19 | ||
1431 | 20 | import logging | 20 | import logging |
1432 | @@ -31,26 +31,27 @@ | |||
1433 | 31 | from softwarecenter.enums import BUY_SOMETHING_HOST | 31 | from softwarecenter.enums import BUY_SOMETHING_HOST |
1434 | 32 | try: | 32 | try: |
1435 | 33 | from scaclient_pristine import SoftwareCenterAgentAPI | 33 | from scaclient_pristine import SoftwareCenterAgentAPI |
1437 | 34 | SoftwareCenterAgentAPI.default_service_root = BUY_SOMETHING_HOST+"/api/2.0" | 34 | SoftwareCenterAgentAPI.default_service_root = \ |
1438 | 35 | BUY_SOMETHING_HOST + "/api/2.0" | ||
1439 | 35 | except: | 36 | except: |
1440 | 36 | logging.exception("need python-piston-mini client") | 37 | logging.exception("need python-piston-mini client") |
1441 | 37 | sys.exit(1) | 38 | sys.exit(1) |
1442 | 38 | 39 | ||
1443 | 39 | 40 | ||
1444 | 40 | |||
1445 | 41 | if __name__ == "__main__": | 41 | if __name__ == "__main__": |
1446 | 42 | 42 | ||
1447 | 43 | sca = SoftwareCenterAgentAPI() | 43 | sca = SoftwareCenterAgentAPI() |
1449 | 44 | 44 | ||
1450 | 45 | lang = "en" | 45 | lang = "en" |
1451 | 46 | series = "natty" | 46 | series = "natty" |
1452 | 47 | arch = "i386" | 47 | arch = "i386" |
1453 | 48 | 48 | ||
1454 | 49 | available = sca.available_apps(lang=lang, series=series, arch=arch) | 49 | available = sca.available_apps(lang=lang, series=series, arch=arch) |
1455 | 50 | print(available) | 50 | print(available) |
1458 | 51 | 51 | ||
1459 | 52 | available_for_qa = sca.available_apps_qa(lang=lang, series=series, arch=arch) | 52 | available_for_qa = sca.available_apps_qa(lang=lang, series=series, |
1460 | 53 | arch=arch) | ||
1461 | 53 | print(available_for_qa) | 54 | print(available_for_qa) |
1463 | 54 | 55 | ||
1464 | 55 | for_me = sca.subscriptions_for_me() | 56 | for_me = sca.subscriptions_for_me() |
1465 | 56 | print(for_me) | 57 | print(for_me) |
1466 | 57 | 58 | ||
1467 | === modified file 'softwarecenter/backend/piston/scaclient_pristine.py' | |||
1468 | --- softwarecenter/backend/piston/scaclient_pristine.py 2012-01-03 16:03:59 +0000 | |||
1469 | +++ softwarecenter/backend/piston/scaclient_pristine.py 2012-03-16 20:20:25 +0000 | |||
1470 | @@ -8,6 +8,7 @@ | |||
1471 | 8 | PUBLIC_API_SCHEME = 'http' | 8 | PUBLIC_API_SCHEME = 'http' |
1472 | 9 | AUTHENTICATED_API_SCHEME = 'https' | 9 | AUTHENTICATED_API_SCHEME = 'https' |
1473 | 10 | 10 | ||
1474 | 11 | |||
1475 | 11 | class SoftwareCenterAgentAPI(PistonAPI): | 12 | class SoftwareCenterAgentAPI(PistonAPI): |
1476 | 12 | default_service_root = 'http://localhost:8000/api/2.0' | 13 | default_service_root = 'http://localhost:8000/api/2.0' |
1477 | 13 | 14 | ||
1478 | 14 | 15 | ||
1479 | === modified file 'softwarecenter/backend/piston/sreclient_pristine.py' | |||
1480 | --- softwarecenter/backend/piston/sreclient_pristine.py 2012-02-29 20:56:24 +0000 | |||
1481 | +++ softwarecenter/backend/piston/sreclient_pristine.py 2012-03-16 20:20:25 +0000 | |||
1482 | @@ -11,6 +11,7 @@ | |||
1483 | 11 | PUBLIC_API_SCHEME = 'http' | 11 | PUBLIC_API_SCHEME = 'http' |
1484 | 12 | AUTHENTICATED_API_SCHEME = 'https' | 12 | AUTHENTICATED_API_SCHEME = 'https' |
1485 | 13 | 13 | ||
1486 | 14 | |||
1487 | 14 | class SoftwareCenterRecommenderAPI(PistonAPI): | 15 | class SoftwareCenterRecommenderAPI(PistonAPI): |
1488 | 15 | default_service_root = 'http://localhost:8000/api/1.0' | 16 | default_service_root = 'http://localhost:8000/api/1.0' |
1489 | 16 | 17 | ||
1490 | 17 | 18 | ||
1491 | === modified file 'softwarecenter/backend/piston/sso_helper.py' | |||
1492 | --- softwarecenter/backend/piston/sso_helper.py 2012-01-13 16:40:48 +0000 | |||
1493 | +++ softwarecenter/backend/piston/sso_helper.py 2012-03-16 20:20:25 +0000 | |||
1494 | @@ -28,13 +28,12 @@ | |||
1495 | 28 | from softwarecenter.utils import clear_token_from_ubuntu_sso | 28 | from softwarecenter.utils import clear_token_from_ubuntu_sso |
1496 | 29 | 29 | ||
1497 | 30 | 30 | ||
1498 | 31 | |||
1499 | 32 | class SSOLoginHelper(object): | 31 | class SSOLoginHelper(object): |
1500 | 33 | def __init__(self, xid=0): | 32 | def __init__(self, xid=0): |
1501 | 34 | self.oauth = None | 33 | self.oauth = None |
1502 | 35 | self.xid = xid | 34 | self.xid = xid |
1503 | 36 | self.loop = GObject.MainLoop(GObject.main_context_default()) | 35 | self.loop = GObject.MainLoop(GObject.main_context_default()) |
1505 | 37 | 36 | ||
1506 | 38 | def _login_successful(self, sso_backend, oauth_result): | 37 | def _login_successful(self, sso_backend, oauth_result): |
1507 | 39 | self.oauth = oauth_result | 38 | self.oauth = oauth_result |
1508 | 40 | # FIXME: actually verify the token against ubuntu SSO | 39 | # FIXME: actually verify the token against ubuntu SSO |
1509 | @@ -44,6 +43,7 @@ | |||
1510 | 44 | def _whoami_done(sso, me): | 43 | def _whoami_done(sso, me): |
1511 | 45 | self._whoami = me | 44 | self._whoami = me |
1512 | 46 | self.loop.quit() | 45 | self.loop.quit() |
1513 | 46 | |||
1514 | 47 | def _whoami_error(sso, err): | 47 | def _whoami_error(sso, err): |
1515 | 48 | #print "ERRR", err | 48 | #print "ERRR", err |
1516 | 49 | self.loop.quit() | 49 | self.loop.quit() |
1517 | @@ -74,7 +74,7 @@ | |||
1518 | 74 | def get_oauth_token_sync(self): | 74 | def get_oauth_token_sync(self): |
1519 | 75 | self.oauth = None | 75 | self.oauth = None |
1520 | 76 | sso = get_sso_backend( | 76 | sso = get_sso_backend( |
1522 | 77 | self.xid, | 77 | self.xid, |
1523 | 78 | SOFTWARE_CENTER_NAME_KEYRING, | 78 | SOFTWARE_CENTER_NAME_KEYRING, |
1524 | 79 | _(SOFTWARE_CENTER_SSO_DESCRIPTION)) | 79 | _(SOFTWARE_CENTER_SSO_DESCRIPTION)) |
1525 | 80 | sso.connect("login-successful", self._login_successful) | 80 | sso.connect("login-successful", self._login_successful) |
1526 | 81 | 81 | ||
1527 | === modified file 'test/test_pep8.py' | |||
1528 | --- test/test_pep8.py 2012-03-16 19:16:21 +0000 | |||
1529 | +++ test/test_pep8.py 2012-03-16 20:20:25 +0000 | |||
1530 | @@ -9,6 +9,8 @@ | |||
1531 | 9 | # Only test these two packages for now: | 9 | # Only test these two packages for now: |
1532 | 10 | import softwarecenter.backend.reviews | 10 | import softwarecenter.backend.reviews |
1533 | 11 | import softwarecenter.backend.oneconfhandler | 11 | import softwarecenter.backend.oneconfhandler |
1534 | 12 | import softwarecenter.backend.piston | ||
1535 | 13 | import softwarecenter.backend.installbackend_impl | ||
1536 | 12 | import softwarecenter.db | 14 | import softwarecenter.db |
1537 | 13 | import softwarecenter.ui | 15 | import softwarecenter.ui |
1538 | 14 | import softwarecenter.distro | 16 | import softwarecenter.distro |
1539 | @@ -16,6 +18,8 @@ | |||
1540 | 16 | class PackagePep8TestCase(unittest.TestCase): | 18 | class PackagePep8TestCase(unittest.TestCase): |
1541 | 17 | maxDiff = None | 19 | maxDiff = None |
1542 | 18 | packages = [softwarecenter.ui, | 20 | packages = [softwarecenter.ui, |
1543 | 21 | softwarecenter.backend.piston, | ||
1544 | 22 | softwarecenter.backend.installbackend_impl, | ||
1545 | 19 | softwarecenter.backend.reviews, | 23 | softwarecenter.backend.reviews, |
1546 | 20 | softwarecenter.backend.oneconfhandler, | 24 | softwarecenter.backend.oneconfhandler, |
1547 | 21 | softwarecenter.db, | 25 | softwarecenter.db, |