euscan: better output

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary 2011-09-21 10:58:41 +02:00
parent a13d593d8d
commit 7fb4e6edff
2 changed files with 37 additions and 20 deletions

View File

@ -23,9 +23,11 @@ import errno
import httplib import httplib
from portage.output import white, yellow, turquoise, green, EOutput from portage.output import white, yellow, turquoise, green, EOutput
from portage.exception import AmbiguousPackageName
import gentoolkit.pprinter as pp from gentoolkit import pprinter as pp
from gentoolkit.eclean.search import (port_settings) from gentoolkit.eclean.search import (port_settings)
from gentoolkit.errors import GentoolkitException
from euscan import CONFIG, output from euscan import CONFIG, output
from euscan.scan import scan_upstream from euscan.scan import scan_upstream
@ -77,7 +79,7 @@ def printUsage(_error=None, help=None):
if _error in ('global-options', 'packages',) or help == 'all': if _error in ('global-options', 'packages',) or help == 'all':
print( " "+turquoise(__productname__), print( " "+turquoise(__productname__),
yellow("[options]"), yellow("[options]"),
green("<package>"), file=out) green("<package> [<package> [...]]"), file=out)
if _error in ('global-options',) or help == 'all': if _error in ('global-options',) or help == 'all':
print( " "+turquoise(__productname__), print( " "+turquoise(__productname__),
yellow("[--help, --version]"), file=out) yellow("[--help, --version]"), file=out)
@ -103,7 +105,7 @@ def printUsage(_error=None, help=None):
print( file=out) print( file=out)
if _error in ('packages',) or help: if _error in ('packages',) or help:
print( green(" package")+ print( green(" package")+
" - the package (or ebuild) you want to scan", file=out) " - the packages (or ebuilds) you want to scan", file=out)
print( file=out) print( file=out)
'''print( "More detailed instruction can be found in", '''print( "More detailed instruction can be found in",
turquoise("`man %s`" % __productname__), file=out)''' turquoise("`man %s`" % __productname__), file=out)'''
@ -167,10 +169,10 @@ def parseArgs():
' set options accordingly ' ' set options accordingly '
optionSwitch(opts) optionSwitch(opts)
if len(args) != 1: if len(args) < 1:
raise ParseArgsException('packages') raise ParseArgsException('packages')
return args[0] return args
def main(): def main():
"""Parse command line and execute all actions.""" """Parse command line and execute all actions."""
@ -180,7 +182,7 @@ def main():
pp.output.nocolor() pp.output.nocolor()
' parse command line options and actions ' ' parse command line options and actions '
try: try:
package = parseArgs() packages = parseArgs()
except ParseArgsException as e: except ParseArgsException as e:
if e.value == 'help': if e.value == 'help':
printUsage(help='all') printUsage(help='all')
@ -197,11 +199,28 @@ def main():
""" Change euscan's output """ """ Change euscan's output """
output = EOutput(CONFIG['quiet']) output = EOutput(CONFIG['quiet'])
ret = scan_upstream(package)
if CONFIG['verbose'] > 2: if CONFIG['verbose'] > 2:
httplib.HTTPConnection.debuglevel = 1 httplib.HTTPConnection.debuglevel = 1
for package in packages:
try:
ret = scan_upstream(package)
except AmbiguousPackageName as e:
pkgs = e.args[0]
for candidate in pkgs:
print(candidate)
from os.path import basename # To get the short name
print(file=sys.stderr)
print(pp.error("The short ebuild name '%s' is ambiguous. Please specify" % basename(pkgs[0])),
file=sys.stderr, end="")
pp.die(1, "one of the above fully-qualified ebuild names instead.")
except GentoolkitException as err:
pp.die(1, str(err))
finally:
ret = []
print () print ()
for url, version in ret: for url, version in ret:

View File

@ -1,5 +1,3 @@
from __future__ import print_function
import os import os
import sys import sys
@ -39,7 +37,7 @@ def scan_upstream_urls(cpv, urls):
for filename in urls: for filename in urls:
for url in urls[filename]: for url in urls[filename]:
print () pp.uprint()
output.einfo("SRC_URI is '%s'" % url) output.einfo("SRC_URI is '%s'" % url)
if '://' not in url: if '://' not in url: