From a7a4fe57cf69fde8e9da3e18cda4a84348e559e6 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Mon, 16 Jun 2008 07:48:34 +0000 Subject: [PATCH] Show progress while taking snapshot --- pisi/api.py | 13 +++++++++++-- pisi/ui.py | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 690dbec6..b2564209 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -353,11 +353,15 @@ def snapshot(): installed. The record is kept by pisi history mechanism as it works automatically on install, remove and upgrade operations. """ - - installdb = pisi.db.installdb.InstallDB() + + installdb = pisi.db.installdb.InstallDB() historydb = pisi.db.historydb.HistoryDB() historydb.create_history("snapshot") + li = installdb.list_installed() + progress = ctx.ui.Progress(len(li)) + + processed = 0 for name in installdb.list_installed(): package = installdb.get_package(name) historydb.add_package(pkgBefore=package, operation="snapshot") @@ -366,6 +370,11 @@ def snapshot(): if f.type == "config" and pisi.util.config_changed(f): historydb.save_config(name, "/%s" % f.path) + processed += 1 + ctx.ui.display_progress(operation = "snapshot", + percent = progress.update(processed), + info = _("Taking snapshot of the system")) + historydb.update_history() # ****** Danger Zone Below! Tressspassers' eyes will explode! ********** # diff --git a/pisi/ui.py b/pisi/ui.py index 9a3daa23..d8a28550 100644 --- a/pisi/ui.py +++ b/pisi/ui.py @@ -26,6 +26,15 @@ class UI(object): except ArithmeticError: self.percent = 0 + def update(self, size): + if not self.totalsize: + return 100 + try: + self.percent = (size * 100) / self.totalsize + except ArithmeticError: + self.percent = 0 + return self.percent + def __init__(self, debuggy = False, verbose = False): self.show_debug = debuggy self.show_verbose = verbose