[MERGE] colors to constants, colorize to util module.
This commit is contained in:
@@ -22,7 +22,6 @@ import pisi
|
|||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
import pisi.ui
|
import pisi.ui
|
||||||
import pisi.util
|
import pisi.util
|
||||||
import pisi.cli.colors as colors
|
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -76,7 +75,7 @@ class CLI(pisi.ui.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(colors.colorize(msg + '\n', 'brightred'), err=True, verbose=verbose)
|
self.output(pisi.util.colorize(msg + '\n', 'brightred'), err=True, verbose=verbose)
|
||||||
|
|
||||||
def error(self, msg):
|
def error(self, msg):
|
||||||
msg = unicode(msg)
|
msg = unicode(msg)
|
||||||
@@ -85,21 +84,21 @@ class CLI(pisi.ui.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(colors.colorize(msg + '\n', 'red'), err=True)
|
self.output(pisi.util.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(colors.colorize(msg + '\n', 'green'))
|
self.output(pisi.util.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 + colors.colorize('1-%d' % len(opts), 'red'))
|
s = raw_input(msg + pisi.util.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):
|
||||||
@@ -115,7 +114,7 @@ class CLI(pisi.ui.UI):
|
|||||||
import re
|
import re
|
||||||
yesexpr = re.compile(locale.nl_langinfo(locale.YESEXPR))
|
yesexpr = re.compile(locale.nl_langinfo(locale.YESEXPR))
|
||||||
|
|
||||||
prompt = msg + colors.colorize(_(' (yes/no)'), 'red')
|
prompt = msg + pisi.util.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
|
||||||
@@ -136,12 +135,12 @@ class CLI(pisi.ui.UI):
|
|||||||
self.output("\r%s (%d%%)" % (info, percent))
|
self.output("\r%s (%d%%)" % (info, percent))
|
||||||
|
|
||||||
if percent == 100:
|
if percent == 100:
|
||||||
self.output(colors.colorize(_(' [complete]\n'), 'gray'))
|
self.output(pisi.util.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(colors.colorize(msg + '\n', 'brightgreen'))
|
self.output(pisi.util.colorize(msg + '\n', 'brightgreen'))
|
||||||
pisi.util.xterm_title(msg)
|
pisi.util.xterm_title(msg)
|
||||||
|
|
||||||
def notify(self, event, **keywords):
|
def notify(self, event, **keywords):
|
||||||
@@ -158,6 +157,6 @@ class CLI(pisi.ui.UI):
|
|||||||
else:
|
else:
|
||||||
msg = None
|
msg = None
|
||||||
if msg:
|
if msg:
|
||||||
self.output(colors.colorize(msg + '\n', 'cyan'))
|
self.output(pisi.util.colorize(msg + '\n', 'cyan'))
|
||||||
if ctx.log:
|
if ctx.log:
|
||||||
ctx.log.info(msg)
|
ctx.log.info(msg)
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# Copyright (C) 2005 - 2007, TUBITAK/UEKAE
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU General Public License as published by the Free
|
|
||||||
# Software Foundation; either version 2 of the License, or (at your option)
|
|
||||||
# any later version.
|
|
||||||
#
|
|
||||||
# Please read the COPYING file.
|
|
||||||
#
|
|
||||||
|
|
||||||
"""Colors module provides some color codes for console output."""
|
|
||||||
|
|
||||||
import pisi.context as ctx
|
|
||||||
|
|
||||||
colors = {'black' : "\033[30m",
|
|
||||||
'red' : "\033[31m",
|
|
||||||
'green' : "\033[32m",
|
|
||||||
'yellow' : "\033[33m",
|
|
||||||
'blue' : "\033[34m",
|
|
||||||
'purple' : "\033[35m",
|
|
||||||
'cyan' : "\033[36m",
|
|
||||||
'white' : "\033[37m",
|
|
||||||
'brightblack' : "\033[01;30m",
|
|
||||||
'brightred' : "\033[01;31m",
|
|
||||||
'brightgreen' : "\033[01;32m",
|
|
||||||
'brightyellow' : "\033[01;33m",
|
|
||||||
'brightblue' : "\033[01;34m",
|
|
||||||
'brightmagenta' : "\033[01;35m",
|
|
||||||
'brightcyan' : "\033[01;36m",
|
|
||||||
'brightwhite' : "\033[01;37m",
|
|
||||||
'underlineblack' : "\033[04;30m",
|
|
||||||
'underlinered' : "\033[04;31m",
|
|
||||||
'underlinegreen' : "\033[04;32m",
|
|
||||||
'underlineyellow' : "\033[04;33m",
|
|
||||||
'underlineblue' : "\033[04;34m",
|
|
||||||
'underlinemagenta' : "\033[04;35m",
|
|
||||||
'underlinecyan' : "\033[04;36m",
|
|
||||||
'underlinewhite' : "\033[04;37m",
|
|
||||||
'blinkingblack' : "\033[05;30m",
|
|
||||||
'blinkingred' : "\033[05;31m",
|
|
||||||
'blinkinggreen' : "\033[05;32m",
|
|
||||||
'blinkingyellow' : "\033[05;33m",
|
|
||||||
'blinkingblue' : "\033[05;34m",
|
|
||||||
'blinkingmagenta' : "\033[05;35m",
|
|
||||||
'blinkingcyan' : "\033[05;36m",
|
|
||||||
'blinkingwhite' : "\033[05;37m",
|
|
||||||
'backgroundblack' : "\033[07;30m",
|
|
||||||
'backgroundred' : "\033[07;31m",
|
|
||||||
'backgroundgreen' : "\033[07;32m",
|
|
||||||
'backgroundyellow' : "\033[07;33m",
|
|
||||||
'backgroundblue' : "\033[07;34m",
|
|
||||||
'backgroundmagenta' : "\033[07;35m",
|
|
||||||
'backgroundcyan' : "\033[07;36m",
|
|
||||||
'backgroundwhite' : "\033[07;37m",
|
|
||||||
'default' : "\033[0m" }
|
|
||||||
|
|
||||||
def colorize(msg, color):
|
|
||||||
"""Colorize the given message for console output"""
|
|
||||||
if colors.has_key(color) and not ctx.get_option('no_color'):
|
|
||||||
return colors[color] + msg + colors['default']
|
|
||||||
else:
|
|
||||||
return msg
|
|
||||||
@@ -22,8 +22,6 @@ import pisi.cli
|
|||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
from pisi.uri import URI
|
from pisi.uri import URI
|
||||||
import pisi.util as util
|
import pisi.util as util
|
||||||
import pisi.api as api
|
|
||||||
from colors import colorize
|
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -1367,7 +1365,7 @@ all repositories.
|
|||||||
self.init(database = True, write = False)
|
self.init(database = True, write = False)
|
||||||
|
|
||||||
if not (ctx.get_option('no_color') or ctx.config.get_option('uninstalled')):
|
if not (ctx.get_option('no_color') or ctx.config.get_option('uninstalled')):
|
||||||
ctx.ui.info(colorize(_('Installed packages are shown in this color'), 'green'))
|
ctx.ui.info(util.colorize(_('Installed packages are shown in this color'), 'green'))
|
||||||
|
|
||||||
if self.args:
|
if self.args:
|
||||||
for arg in self.args:
|
for arg in self.args:
|
||||||
@@ -1397,7 +1395,7 @@ all repositories.
|
|||||||
if p in installed_list:
|
if p in installed_list:
|
||||||
if ctx.config.get_option('uninstalled'):
|
if ctx.config.get_option('uninstalled'):
|
||||||
continue
|
continue
|
||||||
p = colorize(p, 'green')
|
p = util.colorize(p, 'green')
|
||||||
p = p + ' ' * max(0, 15 - lenp)
|
p = p + ' ' * max(0, 15 - lenp)
|
||||||
ctx.ui.info('%s - %s ' % (p, unicode(package.summary)))
|
ctx.ui.info('%s - %s ' % (p, unicode(package.summary)))
|
||||||
|
|
||||||
@@ -1435,7 +1433,7 @@ repositories.
|
|||||||
else:
|
else:
|
||||||
lenp = len(p)
|
lenp = len(p)
|
||||||
#if p in installed_list:
|
#if p in installed_list:
|
||||||
# p = colorize(p, 'cyan')
|
# p = util.colorize(p, 'cyan')
|
||||||
p = p + ' ' * max(0, 15 - lenp)
|
p = p + ' ' * max(0, 15 - lenp)
|
||||||
ctx.ui.info('%s - %s ' % (component.name, unicode(component.summary)))
|
ctx.ui.info('%s - %s ' % (component.name, unicode(component.summary)))
|
||||||
self.finalize()
|
self.finalize()
|
||||||
@@ -1475,7 +1473,7 @@ Gives a brief list of sources published in the repositories.
|
|||||||
else:
|
else:
|
||||||
lenp = len(p)
|
lenp = len(p)
|
||||||
#if p in installed_list:
|
#if p in installed_list:
|
||||||
# p = colorize(p, 'cyan')
|
# p = util.colorize(p, 'cyan')
|
||||||
p = p + ' ' * max(0, 15 - lenp)
|
p = p + ' ' * max(0, 15 - lenp)
|
||||||
ctx.ui.info('%s - %s' % (sf.source.name, unicode(sf.source.summary)))
|
ctx.ui.info('%s - %s' % (sf.source.name, unicode(sf.source.summary)))
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|||||||
@@ -101,6 +101,47 @@ class Constants:
|
|||||||
self.__c.executable = "executable"
|
self.__c.executable = "executable"
|
||||||
self.__c.data = "data"
|
self.__c.data = "data"
|
||||||
self.__c.localedata = "localedata"
|
self.__c.localedata = "localedata"
|
||||||
|
self.__c.colors = {'black' : "\033[30m",
|
||||||
|
'red' : "\033[31m",
|
||||||
|
'green' : "\033[32m",
|
||||||
|
'yellow' : "\033[33m",
|
||||||
|
'blue' : "\033[34m",
|
||||||
|
'purple' : "\033[35m",
|
||||||
|
'cyan' : "\033[36m",
|
||||||
|
'white' : "\033[37m",
|
||||||
|
'brightblack' : "\033[01;30m",
|
||||||
|
'brightred' : "\033[01;31m",
|
||||||
|
'brightgreen' : "\033[01;32m",
|
||||||
|
'brightyellow' : "\033[01;33m",
|
||||||
|
'brightblue' : "\033[01;34m",
|
||||||
|
'brightmagenta' : "\033[01;35m",
|
||||||
|
'brightcyan' : "\033[01;36m",
|
||||||
|
'brightwhite' : "\033[01;37m",
|
||||||
|
'underlineblack' : "\033[04;30m",
|
||||||
|
'underlinered' : "\033[04;31m",
|
||||||
|
'underlinegreen' : "\033[04;32m",
|
||||||
|
'underlineyellow' : "\033[04;33m",
|
||||||
|
'underlineblue' : "\033[04;34m",
|
||||||
|
'underlinemagenta' : "\033[04;35m",
|
||||||
|
'underlinecyan' : "\033[04;36m",
|
||||||
|
'underlinewhite' : "\033[04;37m",
|
||||||
|
'blinkingblack' : "\033[05;30m",
|
||||||
|
'blinkingred' : "\033[05;31m",
|
||||||
|
'blinkinggreen' : "\033[05;32m",
|
||||||
|
'blinkingyellow' : "\033[05;33m",
|
||||||
|
'blinkingblue' : "\033[05;34m",
|
||||||
|
'blinkingmagenta' : "\033[05;35m",
|
||||||
|
'blinkingcyan' : "\033[05;36m",
|
||||||
|
'blinkingwhite' : "\033[05;37m",
|
||||||
|
'backgroundblack' : "\033[07;30m",
|
||||||
|
'backgroundred' : "\033[07;31m",
|
||||||
|
'backgroundgreen' : "\033[07;32m",
|
||||||
|
'backgroundyellow' : "\033[07;33m",
|
||||||
|
'backgroundblue' : "\033[07;34m",
|
||||||
|
'backgroundmagenta' : "\033[07;35m",
|
||||||
|
'backgroundcyan' : "\033[07;36m",
|
||||||
|
'backgroundwhite' : "\033[07;37m",
|
||||||
|
'default' : "\033[0m" }
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
return getattr(self.__c, attr)
|
return getattr(self.__c, attr)
|
||||||
|
|||||||
@@ -675,3 +675,11 @@ def filter_latest_packages(package_paths):
|
|||||||
latest[name] = (root, name, version)
|
latest[name] = (root, name, version)
|
||||||
|
|
||||||
return map(lambda x:"%s/%s-%s.pisi" % x, latest.values())
|
return map(lambda x:"%s/%s-%s.pisi" % x, latest.values())
|
||||||
|
|
||||||
|
def colorize(msg, color):
|
||||||
|
"""Colorize the given message for console output"""
|
||||||
|
if ctx.const.colors.has_key(color) and not ctx.get_option('no_color'):
|
||||||
|
return ctx.const.colors[color] + msg + ctx.const.colors['default']
|
||||||
|
else:
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user