Merge lp:~larryprice/libertine-scope/libertine-store-status-updates into lp:~larryprice/libertine-scope/libertine-store-search
- libertine-store-status-updates
- Merge into libertine-store-search
Proposed by
Larry Price
Status: | Merged |
---|---|
Approved by: | Larry Price |
Approved revision: | 130 |
Merged at revision: | 105 |
Proposed branch: | lp:~larryprice/libertine-scope/libertine-store-status-updates |
Merge into: | lp:~larryprice/libertine-scope/libertine-store-search |
Prerequisite: | lp:~larryprice/libertine-scope/libertine-store-packages |
Diff against target: |
626 lines (+197/-52) 14 files modified
scope/store/package.cpp (+1/-0) scope/store/package.h (+1/-0) scope/store/preview.cpp (+45/-17) scope/store/preview.h (+12/-1) scope/store/scope.cpp (+0/-2) scope/store/scope.h (+0/-3) scope/store/service_manager.cpp (+8/-1) scope/store/service_manager.h (+1/-0) service/libertine_service/apt.py (+1/-0) service/libertine_service/container.py (+4/-4) service/libertine_service/dbus.py (+73/-3) service/libertine_service/tasks.py (+34/-9) tests/scope/store/mock_service_manager.h (+1/-0) tests/scope/store/test_preview.cpp (+16/-12) |
To merge this branch: | bzr merge lp:~larryprice/libertine-scope/libertine-store-status-updates |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Christopher Townsend (community) | Approve | ||
Review via email: mp+303981@code.launchpad.net |
Commit message
Update state of application once install/remove is complete.
Description of the change
Update state of application once install/remove is complete.
To post a comment you must log in.
- 119. By Larry Price
-
Updating dbus name
- 120. By Larry Price
-
Constantly emit progress signal so it's picked up by scope
- 121. By Larry Price
-
merge
- 122. By Larry Price
-
fixing test
- 123. By Larry Price
-
merge
- 124. By Larry Price
-
Merge with parent
- 125. By Larry Price
-
merge
- 126. By Larry Price
-
Remove stupid Timer from Progress object and instead rely on the C++ Preview to ask us to emit the current progress as necessary
- 127. By Larry Price
-
Use package name to get progress update
- 128. By Larry Price
-
Test that update_progress was called on service
- 129. By Larry Price
-
Merge with parent
Revision history for this message
Christopher Townsend (townsend) wrote : | # |
Just a couple of quick formatting comments inline.
- 130. By Larry Price
-
Fixing indentation of tuple def
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'scope/store/package.cpp' |
2 | --- scope/store/package.cpp 2016-08-25 20:41:33 +0000 |
3 | +++ scope/store/package.cpp 2016-09-21 14:34:34 +0000 |
4 | @@ -30,6 +30,7 @@ |
5 | pkg.id = pkgMap["id"].toString().toStdString(); |
6 | pkg.package = pkgMap["package"].toString().toStdString(); |
7 | pkg.status = pkgMap["status"].toString().toStdString(); |
8 | + pkg.progress = pkgMap["progress_id"].toString().toStdString(); |
9 | |
10 | for (auto const& screenshot: pkgMap["screenshots"].toStringList()) |
11 | { |
12 | |
13 | === modified file 'scope/store/package.h' |
14 | --- scope/store/package.h 2016-08-25 20:41:33 +0000 |
15 | +++ scope/store/package.h 2016-09-21 14:34:34 +0000 |
16 | @@ -48,6 +48,7 @@ |
17 | std::string publisher; |
18 | std::string website; |
19 | std::string license; |
20 | + std::string progress; |
21 | |
22 | std::vector<std::string> screenshots; |
23 | }; |
24 | |
25 | === modified file 'scope/store/preview.cpp' |
26 | --- scope/store/preview.cpp 2016-08-25 20:41:33 +0000 |
27 | +++ scope/store/preview.cpp 2016-09-21 14:34:34 +0000 |
28 | @@ -18,6 +18,8 @@ |
29 | |
30 | #include "scope/store/i18n.h" |
31 | #include "scope/store/service_manager.h" |
32 | +#include <future> |
33 | +#include <QDebug> |
34 | #include <unity/UnityExceptions.h> |
35 | #include <unity/scopes/ColumnLayout.h> |
36 | #include <unity/scopes/PreviewReply.h> |
37 | @@ -25,7 +27,6 @@ |
38 | #include <unity/scopes/VariantBuilder.h> |
39 | #include <unity/scopes/ActionMetadata.h> |
40 | #include <unity/scopes/Result.h> |
41 | -#include <QDebug> |
42 | |
43 | |
44 | namespace usc = unity::scopes; |
45 | @@ -92,18 +93,19 @@ |
46 | static usc::PreviewWidget |
47 | buttonWidgets(Libertine::Store::Package const& package) |
48 | { |
49 | - usc::PreviewWidget buttons(ACTIONS_ID, "actions"); |
50 | + if (package.status == "installing" || package.status == "removing") |
51 | + { |
52 | + usc::PreviewWidget progress(ACTIONS_ID, "progress"); |
53 | + usc::VariantMap tuple; |
54 | + tuple["dbus-name"] = "com.canonical.libertine.ContainerManager"; |
55 | + tuple["dbus-object"] = std::string("/Progress/") + package.progress; |
56 | + progress.add_attribute_value("source", usc::Variant(tuple)); |
57 | + |
58 | + return progress; |
59 | + } |
60 | + |
61 | usc::VariantBuilder builder; |
62 | - |
63 | - if (package.status.empty()) |
64 | - { |
65 | - builder.add_tuple( |
66 | - { |
67 | - {"id", usc::Variant("install")}, |
68 | - {"label", usc::Variant(ACTION_INSTALL)}, |
69 | - }); |
70 | - } |
71 | - else if (package.status == "installed") |
72 | + if (package.status == "installed") |
73 | { |
74 | builder.add_tuple( |
75 | { |
76 | @@ -120,10 +122,12 @@ |
77 | { |
78 | builder.add_tuple( |
79 | { |
80 | - {"id", usc::Variant("noop")}, |
81 | - {"label", usc::Variant(package.status == "removing" ? ACTION_NOOP_REMOVING : ACTION_NOOP_INSTALLING)}, |
82 | + {"id", usc::Variant("install")}, |
83 | + {"label", usc::Variant(ACTION_INSTALL)}, |
84 | }); |
85 | } |
86 | + |
87 | + usc::PreviewWidget buttons(ACTIONS_ID, "actions"); |
88 | buttons.add_attribute_value("actions", builder.end()); |
89 | return buttons; |
90 | } |
91 | @@ -170,13 +174,28 @@ |
92 | } |
93 | |
94 | |
95 | +std::chrono::milliseconds Libertine::Store::Preview:: |
96 | +update_progress_after = std::chrono::milliseconds(500); |
97 | + |
98 | + |
99 | Libertine::Store::Preview:: |
100 | -Preview(usc::Result const& result, |
101 | - usc::ActionMetadata const& metadata, |
102 | +Preview(usc::Result const& result, |
103 | + usc::ActionMetadata const& metadata, |
104 | std::shared_ptr<ServiceManager> const& service) |
105 | : PreviewQueryBase(result, metadata) |
106 | , service_(service) |
107 | -{ |
108 | + , thread_() |
109 | +{ |
110 | +} |
111 | + |
112 | + |
113 | +Libertine::Store::Preview:: |
114 | +~Preview() |
115 | +{ |
116 | + if (thread_ != nullptr) |
117 | + { |
118 | + thread_->join(); |
119 | + } |
120 | } |
121 | |
122 | |
123 | @@ -225,6 +244,15 @@ |
124 | |
125 | registerLayouts(reply); |
126 | reply->push(widgets); |
127 | + |
128 | + // update the progress bar asynchronously |
129 | + // if an operation is in progress |
130 | + if (app.status == "installing" || app.status == "removing") { |
131 | + thread_.reset(new std::thread([=](){ |
132 | + std::this_thread::sleep_for(update_progress_after); |
133 | + service_->update_progress(QString::fromStdString(app.package)); |
134 | + })); |
135 | + } |
136 | } |
137 | |
138 | |
139 | |
140 | === modified file 'scope/store/preview.h' |
141 | --- scope/store/preview.h 2016-07-25 20:12:20 +0000 |
142 | +++ scope/store/preview.h 2016-09-21 14:34:34 +0000 |
143 | @@ -16,9 +16,16 @@ |
144 | #ifndef LIBERTINE_STORE_PREVIEW_H |
145 | #define LIBERTINE_STORE_PREVIEW_H |
146 | |
147 | +#include <chrono> |
148 | #include <unity/scopes/PreviewQueryBase.h> |
149 | |
150 | |
151 | +namespace std |
152 | +{ |
153 | +class thread; |
154 | +} |
155 | + |
156 | + |
157 | namespace Libertine |
158 | { |
159 | namespace Store |
160 | @@ -37,7 +44,7 @@ |
161 | unity::scopes::ActionMetadata const& metadata, |
162 | std::shared_ptr<ServiceManager> const& service); |
163 | |
164 | - virtual ~Preview() = default; |
165 | + virtual ~Preview(); |
166 | |
167 | virtual void |
168 | cancelled() override; |
169 | @@ -45,6 +52,9 @@ |
170 | virtual void |
171 | run(unity::scopes::PreviewReplyProxy const& reply) override; |
172 | |
173 | + static |
174 | + std::chrono::milliseconds update_progress_after; |
175 | + |
176 | private: |
177 | void |
178 | registerLayouts(unity::scopes::PreviewReplyProxy const& reply); |
179 | @@ -65,6 +75,7 @@ |
180 | } twoColumns; |
181 | |
182 | std::shared_ptr<ServiceManager> service_; |
183 | + std::unique_ptr<std::thread> thread_; |
184 | }; |
185 | |
186 | |
187 | |
188 | === modified file 'scope/store/scope.cpp' |
189 | --- scope/store/scope.cpp 2016-08-25 20:41:33 +0000 |
190 | +++ scope/store/scope.cpp 2016-09-21 14:34:34 +0000 |
191 | @@ -60,7 +60,6 @@ |
192 | } |
193 | |
194 | |
195 | - |
196 | usc::ActivationQueryBase::UPtr Libertine::Store::Scope:: |
197 | perform_action(usc::Result const& result, |
198 | usc::ActionMetadata const& metadata, |
199 | @@ -72,4 +71,3 @@ |
200 | action_id, |
201 | service_)); |
202 | } |
203 | - |
204 | |
205 | === modified file 'scope/store/scope.h' |
206 | --- scope/store/scope.h 2016-08-15 20:49:25 +0000 |
207 | +++ scope/store/scope.h 2016-09-21 14:34:34 +0000 |
208 | @@ -75,6 +75,3 @@ |
209 | } // namespace Libertine |
210 | |
211 | #endif /* LIBERTINE_STORE_SCOPE_H_ */ |
212 | - |
213 | - |
214 | - |
215 | |
216 | === modified file 'scope/store/service_manager.cpp' |
217 | --- scope/store/service_manager.cpp 2016-08-31 19:59:05 +0000 |
218 | +++ scope/store/service_manager.cpp 2016-09-21 14:34:34 +0000 |
219 | @@ -25,6 +25,7 @@ |
220 | constexpr auto APP_INFO_METHOD = "app_info"; |
221 | constexpr auto INSTALL_METHOD = "install"; |
222 | constexpr auto REMOVE_METHOD = "remove"; |
223 | +constexpr auto UPDATE_PROGRESS_METHOD = "update_progress"; |
224 | constexpr auto LIBERTINE_SERVICE_DESTINATION = "com.canonical.libertine.ContainerManager"; |
225 | constexpr auto LIBERTINE_SERVICE_INTERFACE = "com.canonical.libertine.ContainerManager"; |
226 | constexpr auto LIBERTINE_SERVICE_OBJECT = "/Manager"; |
227 | @@ -59,6 +60,13 @@ |
228 | } |
229 | |
230 | |
231 | +void Libertine::Store::ServiceManager:: |
232 | +update_progress(QString const& package_name) const |
233 | +{ |
234 | + call<bool>(UPDATE_PROGRESS_METHOD, QVariant(package_name)); |
235 | +} |
236 | + |
237 | + |
238 | QList<Libertine::Store::Package> Libertine::Store::ServiceManager:: |
239 | search_cache(const QString &query) const |
240 | { |
241 | @@ -93,4 +101,3 @@ |
242 | { |
243 | return QDBusConnection::sessionBus().isConnected(); |
244 | } |
245 | - |
246 | |
247 | === modified file 'scope/store/service_manager.h' |
248 | --- scope/store/service_manager.h 2016-08-16 18:32:43 +0000 |
249 | +++ scope/store/service_manager.h 2016-09-21 14:34:34 +0000 |
250 | @@ -38,6 +38,7 @@ |
251 | virtual Package app_info(QString const& app_id) const; |
252 | virtual void install(QString const& package_name) const; |
253 | virtual void remove(QString const& package_name) const; |
254 | + virtual void update_progress(QString const& package_name) const; |
255 | |
256 | private: |
257 | bool valid() const; |
258 | |
259 | === modified file 'service/libertine_service/apt.py' |
260 | --- service/libertine_service/apt.py 2016-09-16 18:39:05 +0000 |
261 | +++ service/libertine_service/apt.py 2016-09-21 14:34:34 +0000 |
262 | @@ -101,5 +101,6 @@ |
263 | app_data["summary"] = app.versions[0].summary |
264 | app_data["website"] = app.versions[0].homepage |
265 | app_data["description"] = app.versions[0].description |
266 | + app_data["package"] = app.name |
267 | |
268 | return app_data |
269 | |
270 | === modified file 'service/libertine_service/container.py' |
271 | --- service/libertine_service/container.py 2016-08-18 19:04:10 +0000 |
272 | +++ service/libertine_service/container.py 2016-09-21 14:34:34 +0000 |
273 | @@ -36,24 +36,24 @@ |
274 | self.libertine_config = SafeContainersConfig() |
275 | self.lock = Lock() |
276 | |
277 | - def install(self, package_name, container_id): |
278 | + def install(self, package_name, container_id, progress): |
279 | self.libertine_config.refresh_database() |
280 | if not self._container_exists(container_id): |
281 | self.log.debug("Container does not exist, queuing create operation") |
282 | create = tasks.CreateTask(container_id, self.libertine_config, self.lock, self.log) |
283 | create.start() |
284 | |
285 | - task = tasks.InstallTask(package_name, container_id, self.libertine_config, self.lock, self.log) |
286 | + task = tasks.InstallTask(package_name, container_id, self.libertine_config, progress, self.lock, self.log) |
287 | return task.start() |
288 | |
289 | - def remove(self, package_name, container_id): |
290 | + def remove(self, package_name, container_id, progress): |
291 | self.libertine_config.refresh_database() |
292 | if not self._container_exists(container_id): |
293 | self.log.debug("Container does not exist, queuing create operation") |
294 | create = tasks.CreateTask(container_id, self.libertine_config, self.lock, self.log) |
295 | create.start() |
296 | |
297 | - task = tasks.RemoveTask(package_name, container_id, self.libertine_config, self.lock, self.log) |
298 | + task = tasks.RemoveTask(package_name, container_id, self.libertine_config, progress, self.lock, self.log) |
299 | return task.start() |
300 | |
301 | def status(self, package_name, container_id): |
302 | |
303 | === modified file 'service/libertine_service/dbus.py' |
304 | --- service/libertine_service/dbus.py 2016-08-31 19:59:05 +0000 |
305 | +++ service/libertine_service/dbus.py 2016-09-21 14:34:34 +0000 |
306 | @@ -19,20 +19,53 @@ |
307 | from libertine_service import appstream |
308 | from libertine_service import container |
309 | from dbus.mainloop.glib import DBusGMainLoop |
310 | +from time import time |
311 | |
312 | |
313 | LIBERTINE_SERVICE_NAME = "com.canonical.libertine.ContainerManager" |
314 | LIBERTINE_STORE_INTERFACE = LIBERTINE_SERVICE_NAME |
315 | +DOWNLOAD_INTERFACE = "com.canonical.applications.Download" |
316 | LIBERTINE_STORE_PATH = "/Manager" |
317 | CONTAINER_ID = "palatine" |
318 | |
319 | log = logging.getLogger("Libertine") |
320 | |
321 | |
322 | +class Progress(dbus.service.Object): |
323 | + def __init__(self, connection, package): |
324 | + log.debug("creating a Progress object") |
325 | + self.package = package |
326 | + self._id = hex(int(time()*10000000))[2:] |
327 | + self._finished = False |
328 | + self.current_progress = (dbus.UInt64(0), dbus.UInt64(0)) |
329 | + dbus.service.Object.__init__(self, conn=connection, object_path=("/Progress/%s" % self._id)) |
330 | + |
331 | + def emit_progress(self): |
332 | + self.progress(self.current_progress[0], self.current_progress[1]) |
333 | + |
334 | + @property |
335 | + def id(self): |
336 | + return self._id |
337 | + |
338 | + @property |
339 | + def done(self): |
340 | + return self._finished |
341 | + |
342 | + @dbus.service.signal(DOWNLOAD_INTERFACE) |
343 | + def finished(self, path): |
344 | + log.debug("emit finished('%s')" % path) |
345 | + self._finished = True |
346 | + |
347 | + @dbus.service.signal(DOWNLOAD_INTERFACE) |
348 | + def progress(self, received, total): |
349 | + log.debug("emit progress(%d, %d)" % (received, total)) |
350 | + self.current_progress = (received, total) |
351 | + |
352 | + |
353 | class Service(dbus.service.Object): |
354 | |
355 | def __init__(self, config): |
356 | - log.info("creating service") |
357 | + log.debug("creating service") |
358 | DBusGMainLoop(set_as_default=True) |
359 | try: |
360 | bus_name = dbus.service.BusName(LIBERTINE_SERVICE_NAME, |
361 | @@ -49,6 +82,7 @@ |
362 | self.cache = apt.AptCache(config) |
363 | |
364 | self.container = container.Container(log) |
365 | + self.progress = {} |
366 | |
367 | super().__init__(bus_name, LIBERTINE_STORE_PATH) |
368 | |
369 | @@ -85,6 +119,9 @@ |
370 | app = self.cache.app_info(app_id) |
371 | if 'package' in app: |
372 | app['status'] = self.container.status(app['package'], CONTAINER_ID) |
373 | + if app['package'] in self.progress: |
374 | + app['progress_id'] = self.progress[app['package']].id |
375 | + |
376 | return app |
377 | |
378 | @dbus.service.signal(LIBERTINE_STORE_INTERFACE, |
379 | @@ -92,16 +129,49 @@ |
380 | def updating(self, target, percent): |
381 | log.debug("emit updating('{}', {})".format(target, percent)) |
382 | |
383 | + # Packaging |
384 | + |
385 | @dbus.service.method(LIBERTINE_STORE_INTERFACE, |
386 | in_signature='s', |
387 | out_signature='x') |
388 | def install(self, package_name): |
389 | log.debug("install('%s')" % package_name) |
390 | - return self.container.install(package_name, CONTAINER_ID) |
391 | + return self.container.install(package_name, CONTAINER_ID, self.find_or_create_package_progress(package_name)) |
392 | |
393 | @dbus.service.method(LIBERTINE_STORE_INTERFACE, |
394 | in_signature='s', |
395 | out_signature='x') |
396 | def remove(self, package_name): |
397 | log.debug("remove('%s')" % package_name) |
398 | - return self.container.remove(package_name, CONTAINER_ID) |
399 | + return self.container.remove(package_name, CONTAINER_ID, self.find_or_create_package_progress(package_name)) |
400 | + |
401 | + @dbus.service.method(LIBERTINE_STORE_INTERFACE, |
402 | + in_signature='s', |
403 | + out_signature='b') |
404 | + def update_progress(self, package_name): |
405 | + log.debug("update_progress('%s')" % package_name) |
406 | + self.cleanup_progress() |
407 | + if package_name in self.progress: |
408 | + self.progress[package_name].emit_progress() |
409 | + return True |
410 | + return False |
411 | + |
412 | + def find_or_create_package_progress(self, package_name): |
413 | + self.cleanup_progress() |
414 | + |
415 | + if package_name in self.progress: |
416 | + progress = self.progress[package_name] |
417 | + else: |
418 | + progress = Progress(self.connection, package_name) |
419 | + self.progress[package_name] = progress |
420 | + |
421 | + return progress |
422 | + |
423 | + def cleanup_progress(self): |
424 | + updated_progress_list = {} |
425 | + for key in self.progress.keys(): |
426 | + if self.progress[key].done: |
427 | + self.progress[key].remove_from_connection() |
428 | + else: |
429 | + updated_progress_list[key] = self.progress[key] |
430 | + self.progress = updated_progress_list |
431 | |
432 | === modified file 'service/libertine_service/tasks.py' |
433 | --- service/libertine_service/tasks.py 2016-09-16 16:38:43 +0000 |
434 | +++ service/libertine_service/tasks.py 2016-09-21 14:34:34 +0000 |
435 | @@ -16,6 +16,7 @@ |
436 | from threading import Thread |
437 | from abc import ABCMeta, abstractmethod |
438 | from libertine import LibertineContainer, HostInfo, utils |
439 | +from dbus import UInt64 |
440 | |
441 | |
442 | class LibertineTask(metaclass=ABCMeta): |
443 | @@ -34,6 +35,8 @@ |
444 | thread = Thread(target=self.run) |
445 | thread.start() |
446 | return thread.ident |
447 | + else: |
448 | + return 0 |
449 | |
450 | def run(self): |
451 | with self.lock: |
452 | @@ -47,53 +50,75 @@ |
453 | return True |
454 | |
455 | |
456 | -class InstallTask(LibertineTask): |
457 | - def __init__(self, package_name, container_id, config, lock, log): |
458 | +class ProgressTask(LibertineTask): |
459 | + def __init__(self, package_name, container_id, config, progress, lock, log): |
460 | super().__init__(lock, log) |
461 | self.package = package_name |
462 | self.container = container_id |
463 | self.config = config |
464 | + self.progress = progress |
465 | + self.current_progress = 0 |
466 | + |
467 | + def _progress(self): |
468 | + self.current_progress += 1 |
469 | + self.progress.progress(UInt64(self.current_progress), UInt64(self.current_progress+1)) |
470 | + |
471 | + |
472 | +class InstallTask(ProgressTask): |
473 | + def __init__(self, package_name, container_id, config, progress, lock, log): |
474 | + super().__init__(package_name, container_id, config, progress, lock, log) |
475 | |
476 | def _run(self): |
477 | self.log.debug("Installing package '%s'" % self.package) |
478 | + self._progress() |
479 | container = LibertineContainer(self.container, self.config) |
480 | if container.install_package(self.package): |
481 | + self._progress() |
482 | self.config.update_package_install_status(self.container, self.package, "installed") |
483 | utils.refresh_libertine_scope() |
484 | else: |
485 | + self.log.warning("Package installation failed for '%s'" % self.package) |
486 | self.config.delete_package(self.container, self.package) |
487 | + self.progress.finished(self.package) |
488 | |
489 | def _before(self): |
490 | self.log.debug("InstallTask::_before") |
491 | + self._progress() |
492 | self.config.add_new_package(self.container, self.package) |
493 | self.config.update_package_install_status(self.container, self.package, "installing") |
494 | + self._progress() |
495 | return True |
496 | |
497 | |
498 | -class RemoveTask(LibertineTask): |
499 | - def __init__(self, package_name, container_id, config, lock, log): |
500 | - super().__init__(lock, log) |
501 | - self.package = package_name |
502 | - self.container = container_id |
503 | - self.config = config |
504 | +class RemoveTask(ProgressTask): |
505 | + def __init__(self, package_name, container_id, config, progress, lock, log): |
506 | + super().__init__(package_name, container_id, config, progress, lock, log) |
507 | self.fallback = "installed" |
508 | |
509 | def _run(self): |
510 | self.log.debug("Removing package '%s'" % self.package) |
511 | + self._progress() |
512 | container = LibertineContainer(self.container, self.config) |
513 | if container.remove_package(self.package): |
514 | + self._progress() |
515 | self.config.delete_package(self.container, self.package) |
516 | utils.refresh_libertine_scope() |
517 | else: |
518 | + self.log.warning("Package removal failed for '%s'" % self.package) |
519 | self.config.update_package_install_status(self.container, self.package, self.fallback) |
520 | + self.progress.finished(self.package) |
521 | |
522 | def _before(self): |
523 | self.log.debug("RemoveTask::_before") |
524 | + self._progress() |
525 | if self.config.package_exists(self.container, self.package): |
526 | self.fallback = self.config.get_package_install_status(self.container, self.package) |
527 | self.config.update_package_install_status(self.container, self.package, "removing") |
528 | + self._progress() |
529 | return True |
530 | - return False |
531 | + else: |
532 | + self.log.debug("Package '%s' already exists, skipping install" % self.package) |
533 | + return False |
534 | |
535 | |
536 | class CreateTask(LibertineTask): |
537 | |
538 | === modified file 'tests/scope/store/mock_service_manager.h' |
539 | --- tests/scope/store/mock_service_manager.h 2016-08-18 18:17:36 +0000 |
540 | +++ tests/scope/store/mock_service_manager.h 2016-09-21 14:34:34 +0000 |
541 | @@ -37,6 +37,7 @@ |
542 | |
543 | MOCK_CONST_METHOD1(search_cache, QList<Package>(QString const&)); |
544 | MOCK_CONST_METHOD1(app_info, Package(QString const&)); |
545 | + MOCK_CONST_METHOD1(update_progress, void(QString const&)); |
546 | MOCK_CONST_METHOD1(install, void(QString const&)); |
547 | MOCK_CONST_METHOD1(remove, void(QString const&)); |
548 | }; |
549 | |
550 | === modified file 'tests/scope/store/test_preview.cpp' |
551 | --- tests/scope/store/test_preview.cpp 2016-08-25 20:41:33 +0000 |
552 | +++ tests/scope/store/test_preview.cpp 2016-09-21 14:34:34 +0000 |
553 | @@ -52,14 +52,13 @@ |
554 | } |
555 | |
556 | static void |
557 | -verifyInProgressButtons(unity::scopes::PreviewWidget const& buttons, std::string const& text) |
558 | +verifyInProgressButtons(unity::scopes::PreviewWidget const& buttons, std::string const& progress_id) |
559 | { |
560 | EXPECT_EQ("buttons", buttons.id()); |
561 | - EXPECT_EQ("actions", buttons.widget_type()); |
562 | - auto buttons_actions = buttons.attribute_values()["actions"].get_array(); |
563 | - ASSERT_EQ(1, buttons_actions.size()); |
564 | - EXPECT_EQ("noop", buttons_actions[0].get_dict()["id"].get_string()); |
565 | - EXPECT_EQ(text, buttons_actions[0].get_dict()["label"].get_string()); |
566 | + EXPECT_EQ("progress", buttons.widget_type()); |
567 | + auto source = buttons.attribute_values()["source"].get_dict(); |
568 | + EXPECT_EQ("com.canonical.libertine.ContainerManager", source["dbus-name"].get_string()); |
569 | + EXPECT_EQ(std::string("/Progress/") + progress_id, source["dbus-object"].get_string()); |
570 | } |
571 | |
572 | |
573 | @@ -160,6 +159,7 @@ |
574 | SetUp() |
575 | { |
576 | EXPECT_CALL(reply, push(testing::_)).WillOnce(testing::SaveArg<0>(list.get())); |
577 | + Preview::update_progress_after = std::chrono::milliseconds(0); |
578 | } |
579 | |
580 | void usePackage(Package const& package) |
581 | @@ -248,17 +248,19 @@ |
582 | { |
583 | auto package = basePackage(); |
584 | package.status = "removing"; |
585 | + package.progress = "something"; |
586 | usePackage(package); |
587 | + EXPECT_CALL(*service, update_progress(QString::fromStdString(package.package))); |
588 | |
589 | - Preview preview(result, metadata, service); |
590 | - preview.run(proxy); |
591 | + std::unique_ptr<Preview> preview(new Preview(result, metadata, service)); |
592 | + preview->run(proxy); |
593 | |
594 | ASSERT_NE(nullptr, list); |
595 | ASSERT_EQ(4, list->size()); |
596 | |
597 | verifyHeader(package, list->front()); |
598 | list->pop_front(); |
599 | - verifyInProgressButtons(list->front(), "Removing..."); |
600 | + verifyInProgressButtons(list->front(), package.progress); |
601 | list->pop_front(); |
602 | verifyMetadata(package, list->front()); |
603 | list->pop_front(); |
604 | @@ -270,17 +272,19 @@ |
605 | { |
606 | auto package = basePackage(); |
607 | package.status = "installing"; |
608 | + package.progress = "foobar"; |
609 | usePackage(package); |
610 | + EXPECT_CALL(*service, update_progress(QString::fromStdString(package.package))); |
611 | |
612 | - Preview preview(result, metadata, service); |
613 | - preview.run(proxy); |
614 | + std::unique_ptr<Preview> preview(new Preview(result, metadata, service)); |
615 | + preview->run(proxy); |
616 | |
617 | ASSERT_NE(nullptr, list); |
618 | ASSERT_EQ(4, list->size()); |
619 | |
620 | verifyHeader(package, list->front()); |
621 | list->pop_front(); |
622 | - verifyInProgressButtons(list->front(), "Installing..."); |
623 | + verifyInProgressButtons(list->front(), package.progress); |
624 | list->pop_front(); |
625 | verifyMetadata(package, list->front()); |
626 | list->pop_front(); |
Per the conversation on IRC, I'm not a fan of how the progress meter increments, the main problem being that it jumps to 75% quite quickly and then can sit there for some time while packages are downloaded and installed.
This will need to be addressed, but as agreed, this can be done later.
Approving this so we can get it merged.