euscanwww: Added ansi to html helper

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino
2012-07-20 15:12:44 +02:00
parent 1aaee90ab7
commit ad02fd4b81
4 changed files with 109 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import portage
from portage.output import EOutput, TermProgressBar
from gentoolkit import pprinter as pp
class ProgressHandler(object):
def __init__(self, progress_bar):
self.curval = 0
@ -72,24 +73,26 @@ def transform_url(config, cpv, url):
url = to_ebuild_uri(cpv, url)
return url
def to_ebuild_uri(cpv, url):
cat, pkg, ver, rev = portage.catpkgsplit(cpv)
p = '%s-%s' % (pkg, ver)
pvr = '%s%s' % (ver, '-%s' % rev if rev != 'r0' else '')
pf = '%s-%s' % (pkg, pvr)
evars = (
(p , 'P'),
(p, 'P'),
(pkg, 'PN'),
(ver, 'PV'),
(rev, 'PR'),
(pvr, 'PVR'),
(pf , 'PF'),
(pf, 'PF'),
(cat, 'CATEGORY')
)
for src, dst in evars:
url = url.replace(src, '${%s}' % dst)
return url
def to_mirror(url):
mirrors = portage.settings.thirdpartymirrors()
for mirror_name in mirrors:
@ -113,7 +116,7 @@ class EOutputMem(EOutput):
self.out = StringIO()
def getvalue(self):
return clean_colors(self.out.getvalue())
return self.out.getvalue()
def _write(self, f, msg):
super(EOutputMem, self)._write(self.out, msg)
@ -173,9 +176,11 @@ class EuscanOutput(object):
from euscan.version import get_version_type
cpv = '%s-%s' % (cp, version)
urls = ' '.join(transform_url(self.config, cpv, url) for url in urls.split())
urls = ' '.join(
transform_url(self.config, cpv, url) for url in urls.split()
)
if self.config['format'] in ['json']:
if self.config['format'] in ['json', 'dict']:
_curr = self.queries[self.current_query]
_curr["result"].append(
{
@ -195,8 +200,7 @@ class EuscanOutput(object):
def metadata(self, key, value, show=True):
if self.config["format"]:
self.queries[self.current_query]["metadata"][key] = \
clean_colors(value)
self.queries[self.current_query]["metadata"][key] = value
elif show:
print "%s: %s" % (key.capitalize(), value)