* 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) :)
This commit is contained in:
Eray Özkural
2005-11-08 17:39:55 +00:00
parent 1d02911909
commit 78f154a6b4
4 changed files with 43 additions and 4 deletions
+17 -4
View File
@@ -38,6 +38,7 @@ from pisi.package import Package
from pisi.metadata import MetaData from pisi.metadata import MetaData
from pisi.files import Files from pisi.files import Files
from pisi.uri import URI from pisi.uri import URI
import pisi.ui
#import conflicts #import conflicts
class Error(pisi.Error): class Error(pisi.Error):
@@ -73,7 +74,7 @@ class Install(AtomicOperation):
def install(self, ask_reinstall = True): def install(self, ask_reinstall = True):
"entry point" "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.name, self.pkginfo.version,
self.pkginfo.release, self.pkginfo.build)) self.pkginfo.release, self.pkginfo.build))
self.ask_reinstall = ask_reinstall self.ask_reinstall = ask_reinstall
@@ -89,7 +90,13 @@ class Install(AtomicOperation):
comariface.run_postinstall(self.pkginfo.name) comariface.run_postinstall(self.pkginfo.name)
self.update_databases() self.update_databases()
self.update_environment() 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): def check_requirements(self):
"""check system requirements""" """check system requirements"""
#TODO: IS THERE ENOUGH SPACE? #TODO: IS THERE ENOUGH SPACE?
@@ -121,6 +128,7 @@ class Install(AtomicOperation):
pkg = self.pkginfo pkg = self.pkginfo
self.reinstall = False self.reinstall = False
self.upgrade = False
if ctx.installdb.is_installed(pkg.name): # is this a reinstallation? if ctx.installdb.is_installed(pkg.name): # is this a reinstallation?
(iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name) (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name)
@@ -153,6 +161,7 @@ class Install(AtomicOperation):
and pkg.build > ibuild): and pkg.build > ibuild):
ctx.ui.info(_('Upgrading to new distribution build')) ctx.ui.info(_('Upgrading to new distribution build'))
upgrade = True upgrade = True
self.upgrade = upgrade
# is this a downgrade? confirm this action. # is this a downgrade? confirm this action.
if self.ask_reinstall and (not upgrade): if self.ask_reinstall and (not upgrade):
@@ -165,6 +174,7 @@ class Install(AtomicOperation):
if not ctx.ui.confirm(x): if not ctx.ui.confirm(x):
raise Error(_('Package downgrade declined')) raise Error(_('Package downgrade declined'))
# schedule for reinstall # schedule for reinstall
self.old_files = ctx.installdb.files(pkg.name) self.old_files = ctx.installdb.files(pkg.name)
self.reinstall = True self.reinstall = True
@@ -297,8 +307,9 @@ class Remove(AtomicOperation):
"""Remove a single package""" """Remove a single package"""
inst_packagedb = packagedb.inst_packagedb inst_packagedb = packagedb.inst_packagedb
self.package = packagedb.get_package(self.package_name) 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): if not ctx.installdb.is_installed(self.package_name):
raise Exception(_('Trying to remove nonexistent package ') raise Exception(_('Trying to remove nonexistent package ')
+ self.package_name) + self.package_name)
@@ -307,11 +318,13 @@ class Remove(AtomicOperation):
self.run_preremove() 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_file(fileinfo)
self.remove_db() self.remove_db()
self.remove_pisi_files() self.remove_pisi_files()
ctx.ui.status()
ctx.ui.notify(pisi.ui.removed, package = self.pkginfo, files = self.files)
def check_dependencies(self): def check_dependencies(self):
#we only have to check the dependencies to ensure the #we only have to check the dependencies to ensure the
+14
View File
@@ -25,6 +25,7 @@ _ = __trans.ugettext
import pisi import pisi
import pisi.context as ctx import pisi.context as ctx
from pisi.ui import UI from pisi.ui import UI
import pisi.ui as ui
from pisi.cli.colors import colorize from pisi.cli.colors import colorize
@@ -121,3 +122,16 @@ class CLI(UI):
out = '\r%-30.30s %3d%% %12.2f %s' % \ out = '\r%-30.30s %3d%% %12.2f %s' % \
(pd['filename'], pd['percent'], pd['rate'], pd['symbol']) (pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
self.output(out) 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'))
+1
View File
@@ -26,6 +26,7 @@ class Error(pisi.Error):
def make_com(): def make_com():
# FIXME: just try for others (that don't use comar) # FIXME: just try for others (that don't use comar)
# what does this mean? -- exa
try: try:
import comar import comar
comard = comar.Link() comard = comar.Link()
+11
View File
@@ -19,6 +19,8 @@ import sys
import pisi import pisi
import pisi.context as ctx import pisi.context as ctx
installed, upgraded, removed = range(3)
class UI(object): class UI(object):
"Abstract class for UI operations, derive from this." "Abstract class for UI operations, derive from this."
@@ -70,6 +72,7 @@ class UI(object):
"inform a (possibly fatal) error" "inform a (possibly fatal) error"
pass pass
#FIXME: merge this with info, this just means "important message"
def action(self,msg): def action(self,msg):
"uh?" "uh?"
pass pass
@@ -85,3 +88,11 @@ class UI(object):
def display_progress(self, pd): def display_progress(self, pd):
"display progress" "display progress"
pass 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