Updated few function calls to fill empty spaces. Thanks to Michal (mgorny) for suggestions. Now it works a bit faster :)
Tomas
--- eshowkwng.py.old 2010-10-27 00:13:21.476218699 +0200
+++ eshowkwng.py 2010-10-27 00:11:33.929218700 +0200
@@ -34,32 +34,33 @@
"""Prepare list of aditional fileds displayed by eshowkw"""
return [ 'unused', 'slot' ]
- def __prepareChar(self, arch, position, count, maxlen, order =
'bottom', imp_arch = '', bold = False):
+ def __prepareChar(self, string, position, count, maxlen, imp_arch = '',
order = 'bottom', bold = False):
"""Return specified character for the list position."""
# first figure out what character we want to work with
# based on order and position in the string
- char = ' '
- if order == 'bottom' and (position < maxlen) and (position >=
maxlen-len(arch)):
- char = list(arch)[position-maxlen+len(arch)]
- elif order == 'top' and position < len(arch):
- char = list(arch)[position]
+ if order == 'bottom':
+ string = string.rjust(maxlen)
+ else:
+ string = string.ljust(maxlen)
+ char = list(string)[position]
+
# figure out what color we want to use
- if arch in imp_arch:
+ if string in imp_arch:
color = 'blue'
if char == ' ':
color = 'bg_lightgray'
- elif arch in self.__IMPARCHS:
+ elif string in self.__IMPARCHS:
color = 'darkyellow'
# colors
- if arch in imp_arch or arch in self.__IMPARCHS:
+ if string in imp_arch or string in self.__IMPARCHS:
char = colorize(color, char)
# bolding
if bold != False and count%2 == 0:
char = colorize('bold', char)
return char
- def __rotateContent(self, string, length, order = 'bottom', imp_arch =
'', bold = False):
+ def __rotateContent(self, lister, length, imp_arch = '', order =
'bottom', bold = False):
"""
Rotate string over 90 degrees:
alpha -> a
@@ -69,21 +70,17 @@
a
"""
# join used to have list of lines rather than list of chars
- return [' '.join([self.__prepareChar(line, i, count, length,
order, imp_arch, bold)
- for count, line in enumerate(string)])
+ return [' '.join([self.__prepareChar(string, i, count, length,
imp_arch, order, bold)
+ for count, string in enumerate(lister)])
for i in range(length)]
def getFormatedKeywordsList(self):
"""Return the formated output as one string for printout."""
return ''.join([x for x in self.__keywords_list])
- def __getVersionSpacer(self, length):
- """Generate spaces to have version string nicely aligned."""
- return ''.join([' ' for i in range(length)])
-
def __prepareFormatting(self, rotated_keywords, rotated_additional,
length):
"""Format result for printout as list per line of content."""
- return ['%s| %s | %s\n' % (self.__getVersionSpacer(length), x,
y)
+ return ['%s | %s | %s\n' % (''.rjust(length), x, y)
for x, y in zip(rotated_keywords, rotated_additional)]
def __init__(self, imp_arch, version_length, order, bold):
@@ -98,10 +95,9 @@
self.keywords = self.__readKeywords()
self.keywords = self.__sortKeywords(self.keywords)
additional = self.__prepareAdditionalFields()
- keywords_maxlen = reduce(lambda x, y: (x, y)[x < y],
- [len(str) for str in self.keywords])
- rotated_keywords = self.__rotateContent(self.keywords,
keywords_maxlen, order, imp_arch, bold)
- rotated_additional = self.__rotateContent(additional,
keywords_maxlen, order, imp_arch, bold)
+ keywords_maxlen = len(max(self.keywords))
+ rotated_keywords = self.__rotateContent(self.keywords,
keywords_maxlen, imp_arch, order, bold)
+ rotated_additional = self.__rotateContent(additional,
keywords_maxlen, imp_arch, order, bold)
self.__keywords_list =
self.__prepareFormatting(rotated_keywords, rotated_additional, version_length)
self.keywords_count = len(self.keywords)
self.additional_count = len(additional)
@@ -115,17 +111,16 @@
def __listRedundant(self, keywords, ignore_slots, slots):
"""List all redundant packages."""
if ignore_slots:
- return self.__getRedundantAll(keywords)
+ return self.__listRedundantAll(keywords)
else:
- return self.__getRedundantSlots(keywords, slots)
+ return self.__listRedundantSlots(keywords,
slots)
- def __getRedundantSlots(self, keywords, slots):
+ def __listRedundantSlots(self, keywords, slots):
"""Search for redundant packages walking per keywords
for specified slot."""
result = [self.__compareSelected([k for k, s in
zip(keywords, slots)
if s == slot])
for slot in self.__uniq(slots)]
# this is required because the list itself is not just
one level depth
- print ''.join(result)
return list(''.join(result))
def __uniq(self, seq):
@@ -139,7 +134,7 @@
result.append(item)
return result
- def __getRedundantAll(self, keywords):
+ def __listRedundantAll(self, keywords):
"""Search for redundant packages using all versions
ignoring its slotting."""
tmp = keywords[:]
# this is required because the list itself is not just
one level depth
@@ -196,9 +191,7 @@
class VersionChecker:
def getVersionsLength(self):
"""Get version string length."""
- # + 1 to add trailing space
- return reduce(lambda x, y: (x, y)[x < y],
- [len(str) for str in self.__versions]) + 1
+ return len(self.__versions[0])
def getVersions(self):
"""Get list of availible versions."""
@@ -211,17 +204,11 @@
def __stripStartingSpaces(self, pvs):
"""Strip starting whitespace if there is no real reason
for it."""
-
if not self.__require_prepend:
- return [x[len('[M]'):] for x in pvs]
+ return [x.lstrip() for x in pvs]
else:
return pvs
- def __fillSpaces(self, string, length):
- """Fill spaces to match maximal version length."""
- spacer = ''.join([' ' for i in
range(length-len(string))])
- return '%s%s' % (string, spacer)
-
def __separateVersion(self, cpv):
"""Get version string for specfied cpv"""
#pv = portage.versions.cpv_getversion(cpv)
@@ -282,15 +269,17 @@
Format version string. Append trailing whitespace and
prepend information if it is masked or installed
version.
"""
- pv = self.__fillSpaces(pv, self.getVersionsLength())
+ # allign package versions
+ pv = pv.rjust(self.getVersionsLength())
+
# allign the versions nicely (before colors mess lining
up)
# set fontcolor on the package version if it is masked
od installed
# we figure it out of the prepended string on the start
of the pv
- if pv.startswith('[M][I]'):
+ if pv.find('[M][I]') != -1:
pv = colorize('darkyellow', pv)
- elif pv.startswith('[M]'):
+ elif pv.find('[M]') != -1:
pv = colorize('darkred', pv)
- elif pv.startswith('[I]'):
+ elif pv.find('[I]') != -1:
pv = colorize('bold', pv)
return pv
@@ -411,16 +400,16 @@
d = ' '
c = colorize('purple', c)
d = colorize('bold', d)
- lister.append('%s| %s | %s %s\n' % (a, b, c, d))
+ lister.append('%s | %s | %s %s\n' % (a, b, c, d))
return lister
def __getHorizontalSeparator(self, slots_length, pv_length,
keywords_length, additional_length):
"""Create nice horizontal separator."""
- ver_sep = ''.join(['-' for i in range(pv_length)])
# +1 required for additional trailing space
- arch_sep = ''.join(['-' for i in range(keywords_length*2+1)])
+ ver_sep = ''.ljust(pv_length+1, '-')
+ arch_sep = ''.ljust(keywords_length*2+1, '-')
# -1 because it is already covered by additional_len
- add_sep = ''.join(['-' for i in
range(additional_length*2+slots_length-1)])
+ add_sep = ''.ljust(additional_length*2+slots_length-1, '-')
return '%s+%s+%s\n' % (ver_sep, arch_sep, add_sep)
def __init__(self, pkg_versions, pkg_keywords, pkg_slots,
pkg_redundant, keywords_list, keywords_count, additional_count, pv_length,
imp_arch, bold):
@@ -429,8 +418,7 @@
Accessable:
class.getKeywords()
"""
- slots_length = reduce(lambda x, y: (x, y)[x < y],
- [len(str) for str in pkg_slots])
+ slots_length = len(max(pkg_slots))
keywords = self.__convertKeywords(keywords_list, pkg_keywords,
imp_arch, bold)
self.__horizontal_separator =
self.__getHorizontalSeparator(slots_length, pv_length, keywords_count,
additional_count)
self.__formated_keywords = self.__formatKeywords(pkg_versions,
keywords, pkg_redundant, pkg_slots)
signature.asc
Description: OpenPGP digital signature
