* 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:
@@ -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
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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()
|
||||
|
||||
+11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user