From 78f154a6b4d35cd05b1fdec5da563a087fb46966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Tue, 8 Nov 2005 17:39:55 +0000 Subject: [PATCH] * add status and notify methods to UI interface * implement these methods in CLI * get the atomic operations to use these new interfaces, there are several other places where these could be useful. * let's not get lazy and do it The Right Way (TM) :) --- pisi/atomicoperations.py | 21 +++++++++++++++++---- pisi/cli/__init__.py | 14 ++++++++++++++ pisi/comariface.py | 1 + pisi/ui.py | 11 +++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index 6dba87fb..91447a97 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -38,6 +38,7 @@ from pisi.package import Package from pisi.metadata import MetaData from pisi.files import Files from pisi.uri import URI +import pisi.ui #import conflicts class Error(pisi.Error): @@ -73,7 +74,7 @@ class Install(AtomicOperation): def install(self, ask_reinstall = True): "entry point" - ctx.ui.info(_('Installing %s, version %s, release %s, build %s') % + ctx.ui.status(_('Installing %s, version %s, release %s, build %s') % (self.pkginfo.name, self.pkginfo.version, self.pkginfo.release, self.pkginfo.build)) self.ask_reinstall = ask_reinstall @@ -89,7 +90,13 @@ class Install(AtomicOperation): comariface.run_postinstall(self.pkginfo.name) self.update_databases() self.update_environment() - + ctx.ui.status() + if self.upgrade: + event = pisi.ui.upgraded + else: + event = pisi.ui.installed + ctx.ui.notify(event, package = self.pkginfo, files = self.files) + def check_requirements(self): """check system requirements""" #TODO: IS THERE ENOUGH SPACE? @@ -121,6 +128,7 @@ class Install(AtomicOperation): pkg = self.pkginfo self.reinstall = False + self.upgrade = False if ctx.installdb.is_installed(pkg.name): # is this a reinstallation? (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name) @@ -153,6 +161,7 @@ class Install(AtomicOperation): and pkg.build > ibuild): ctx.ui.info(_('Upgrading to new distribution build')) upgrade = True + self.upgrade = upgrade # is this a downgrade? confirm this action. if self.ask_reinstall and (not upgrade): @@ -165,6 +174,7 @@ class Install(AtomicOperation): if not ctx.ui.confirm(x): raise Error(_('Package downgrade declined')) + # schedule for reinstall self.old_files = ctx.installdb.files(pkg.name) self.reinstall = True @@ -297,8 +307,9 @@ class Remove(AtomicOperation): """Remove a single package""" inst_packagedb = packagedb.inst_packagedb self.package = packagedb.get_package(self.package_name) + self.files = ctx.installdb.files(self.package_name) - ctx.ui.info(_('Removing package %s') % self.package_name) + ctx.ui.status(_('Removing package %s') % self.package_name) if not ctx.installdb.is_installed(self.package_name): raise Exception(_('Trying to remove nonexistent package ') + self.package_name) @@ -307,11 +318,13 @@ class Remove(AtomicOperation): self.run_preremove() - for fileinfo in ctx.installdb.files(self.package_name).list: + for fileinfo in self.files.list: self.remove_file(fileinfo) self.remove_db() self.remove_pisi_files() + ctx.ui.status() + ctx.ui.notify(pisi.ui.removed, package = self.pkginfo, files = self.files) def check_dependencies(self): #we only have to check the dependencies to ensure the diff --git a/pisi/cli/__init__.py b/pisi/cli/__init__.py index e3659338..61cee454 100644 --- a/pisi/cli/__init__.py +++ b/pisi/cli/__init__.py @@ -25,6 +25,7 @@ _ = __trans.ugettext import pisi import pisi.context as ctx from pisi.ui import UI +import pisi.ui as ui from pisi.cli.colors import colorize @@ -121,3 +122,16 @@ class CLI(UI): out = '\r%-30.30s %3d%% %12.2f %s' % \ (pd['filename'], pd['percent'], pd['rate'], pd['symbol']) self.output(out) + + def status(self, msg = None): + if msg: + self.output(colorize(msg + '\n', 'purple')) + + def notify(self, event, **keywords): + if event == ui.installed: + msg = _('Installed %s') % keywords['package'].name + elif event == ui.removed: + msg = _('Removed %s') % keywords['package'].name + elif event == ui.upgraded: + msg = _('Upgraded %s') % keywords['package'].name + self.output(colorize(msg + '\n', 'cyan')) diff --git a/pisi/comariface.py b/pisi/comariface.py index 3eb2e338..e1aed9b9 100644 --- a/pisi/comariface.py +++ b/pisi/comariface.py @@ -26,6 +26,7 @@ class Error(pisi.Error): def make_com(): # FIXME: just try for others (that don't use comar) + # what does this mean? -- exa try: import comar comard = comar.Link() diff --git a/pisi/ui.py b/pisi/ui.py index 8d6f661e..f0f64ab1 100644 --- a/pisi/ui.py +++ b/pisi/ui.py @@ -19,6 +19,8 @@ import sys import pisi import pisi.context as ctx +installed, upgraded, removed = range(3) + class UI(object): "Abstract class for UI operations, derive from this." @@ -70,6 +72,7 @@ class UI(object): "inform a (possibly fatal) error" pass + #FIXME: merge this with info, this just means "important message" def action(self,msg): "uh?" pass @@ -85,3 +88,11 @@ class UI(object): def display_progress(self, pd): "display progress" pass + + def status(self, msg = None): + "set status, if not given clear it" + pass + + def notify(self, event, **keywords): + "notify UI of a significant event" + pass