From-Import-Removal
This commit is contained in:
+16
-18
@@ -20,11 +20,9 @@ _ = __trans.ugettext
|
|||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
from pisi.ui import UI
|
import pisi.ui
|
||||||
import pisi.ui as ui
|
|
||||||
import pisi.util as util
|
import pisi.util as util
|
||||||
from pisi.cli.colors import colorize
|
import pisi.cli.colors as colors
|
||||||
|
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -44,7 +42,7 @@ def printu(obj, err = False):
|
|||||||
out.write(obj.encode('utf-8'))
|
out.write(obj.encode('utf-8'))
|
||||||
out.flush()
|
out.flush()
|
||||||
|
|
||||||
class CLI(UI):
|
class CLI(pisi.ui.UI):
|
||||||
"Command Line Interface"
|
"Command Line Interface"
|
||||||
|
|
||||||
def __init__(self, show_debug = False, show_verbose = False):
|
def __init__(self, show_debug = False, show_verbose = False):
|
||||||
@@ -78,7 +76,7 @@ class CLI(UI):
|
|||||||
if ctx.get_option('no_color'):
|
if ctx.get_option('no_color'):
|
||||||
self.output(_('Warning: ') + msg + '\n', err=True, verbose=verbose)
|
self.output(_('Warning: ') + msg + '\n', err=True, verbose=verbose)
|
||||||
else:
|
else:
|
||||||
self.output(colorize(msg + '\n', 'brightred'), err=True, verbose=verbose)
|
self.output(colors.colorize(msg + '\n', 'brightred'), err=True, verbose=verbose)
|
||||||
|
|
||||||
def error(self, msg):
|
def error(self, msg):
|
||||||
msg = unicode(msg)
|
msg = unicode(msg)
|
||||||
@@ -87,21 +85,21 @@ class CLI(UI):
|
|||||||
if ctx.get_option('no_color'):
|
if ctx.get_option('no_color'):
|
||||||
self.output(_('Error: ') + msg + '\n', err=True)
|
self.output(_('Error: ') + msg + '\n', err=True)
|
||||||
else:
|
else:
|
||||||
self.output(colorize(msg + '\n', 'red'), err=True)
|
self.output(colors.colorize(msg + '\n', 'red'), err=True)
|
||||||
|
|
||||||
def action(self, msg, verbose = False):
|
def action(self, msg, verbose = False):
|
||||||
#TODO: this seems quite redundant?
|
#TODO: this seems quite redundant?
|
||||||
msg = unicode(msg)
|
msg = unicode(msg)
|
||||||
if ctx.log:
|
if ctx.log:
|
||||||
ctx.log.info(msg)
|
ctx.log.info(msg)
|
||||||
self.output(colorize(msg + '\n', 'green'))
|
self.output(colors.colorize(msg + '\n', 'green'))
|
||||||
|
|
||||||
def choose(self, msg, opts):
|
def choose(self, msg, opts):
|
||||||
print msg
|
print msg
|
||||||
for i in range(0,len(opts)):
|
for i in range(0,len(opts)):
|
||||||
print i + 1, opts(i)
|
print i + 1, opts(i)
|
||||||
while True:
|
while True:
|
||||||
s = raw_input(msg + colorize('1-%d' % len(opts), 'red'))
|
s = raw_input(msg + colors.colorize('1-%d' % len(opts), 'red'))
|
||||||
try:
|
try:
|
||||||
opt = int(s)
|
opt = int(s)
|
||||||
if 1 <= opt and opt <= len(opts):
|
if 1 <= opt and opt <= len(opts):
|
||||||
@@ -117,7 +115,7 @@ class CLI(UI):
|
|||||||
import re
|
import re
|
||||||
yesexpr = re.compile(locale.nl_langinfo(locale.YESEXPR))
|
yesexpr = re.compile(locale.nl_langinfo(locale.YESEXPR))
|
||||||
|
|
||||||
prompt = msg + colorize(_(' (yes/no)'), 'red')
|
prompt = msg + colors.colorize(_(' (yes/no)'), 'red')
|
||||||
s = raw_input(prompt.encode('utf-8'))
|
s = raw_input(prompt.encode('utf-8'))
|
||||||
if yesexpr.search(s):
|
if yesexpr.search(s):
|
||||||
return True
|
return True
|
||||||
@@ -138,28 +136,28 @@ class CLI(UI):
|
|||||||
self.output("\r%s (%d%%)" % (info, percent))
|
self.output("\r%s (%d%%)" % (info, percent))
|
||||||
|
|
||||||
if percent == 100:
|
if percent == 100:
|
||||||
self.output(colorize(_(' [complete]\n'), 'gray'))
|
self.output(colors.colorize(_(' [complete]\n'), 'gray'))
|
||||||
|
|
||||||
def status(self, msg = None):
|
def status(self, msg = None):
|
||||||
if msg:
|
if msg:
|
||||||
msg = unicode(msg)
|
msg = unicode(msg)
|
||||||
self.output(colorize(msg + '\n', 'brightgreen'))
|
self.output(colors.colorize(msg + '\n', 'brightgreen'))
|
||||||
util.xterm_title(msg)
|
util.xterm_title(msg)
|
||||||
|
|
||||||
def notify(self, event, **keywords):
|
def notify(self, event, **keywords):
|
||||||
if event == ui.installed:
|
if event == pisi.ui.installed:
|
||||||
msg = _('Installed %s') % keywords['package'].name
|
msg = _('Installed %s') % keywords['package'].name
|
||||||
elif event == ui.removed:
|
elif event == pisi.ui.removed:
|
||||||
msg = _('Removed %s') % keywords['package'].name
|
msg = _('Removed %s') % keywords['package'].name
|
||||||
elif event == ui.upgraded:
|
elif event == pisi.ui.upgraded:
|
||||||
msg = _('Upgraded %s') % keywords['package'].name
|
msg = _('Upgraded %s') % keywords['package'].name
|
||||||
elif event == ui.configured:
|
elif event == pisi.ui.configured:
|
||||||
msg = _('Configured %s') % keywords['package'].name
|
msg = _('Configured %s') % keywords['package'].name
|
||||||
elif event == ui.extracting:
|
elif event == pisi.ui.extracting:
|
||||||
msg = _('Extracting the files of %s') % keywords['package'].name
|
msg = _('Extracting the files of %s') % keywords['package'].name
|
||||||
else:
|
else:
|
||||||
msg = None
|
msg = None
|
||||||
if msg:
|
if msg:
|
||||||
self.output(colorize(msg + '\n', 'cyan'))
|
self.output(colors.colorize(msg + '\n', 'cyan'))
|
||||||
if ctx.log:
|
if ctx.log:
|
||||||
ctx.log.info(msg)
|
ctx.log.info(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user