2012-07-18 10:48:14 +02:00
|
|
|
#!/usr/bin/env python
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
"""Copyright 2011 Gentoo Foundation
|
|
|
|
Distributed under the terms of the GNU General Public License v2
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2012-07-24 08:33:19 +02:00
|
|
|
import os
|
2012-05-21 22:24:44 +02:00
|
|
|
|
|
|
|
# Meta
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
__author__ = "Corentin Chary (iksaif)"
|
|
|
|
__email__ = "corentin.chary@gmail.com"
|
|
|
|
__version__ = "git"
|
|
|
|
__productname__ = "euscan"
|
|
|
|
__description__ = "A tool to detect new upstream releases."
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
|
|
|
|
# Imports
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import getopt
|
2012-06-28 12:20:57 +02:00
|
|
|
from errno import EINTR, EINVAL
|
|
|
|
from httplib import HTTPConnection
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-07-27 13:58:51 +02:00
|
|
|
from portage import settings
|
2012-05-21 22:24:44 +02:00
|
|
|
from portage.output import white, yellow, turquoise, green
|
2011-09-21 10:58:41 +02:00
|
|
|
from portage.exception import AmbiguousPackageName
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-09-21 10:58:41 +02:00
|
|
|
from gentoolkit import pprinter as pp
|
|
|
|
from gentoolkit.errors import GentoolkitException
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
from euscan import CONFIG, output
|
2012-07-27 13:58:51 +02:00
|
|
|
from euscan.out import progress_bar
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
# Globals
|
2012-06-28 12:20:57 +02:00
|
|
|
isatty = os.environ.get('TERM') != 'dumb' and sys.stdout.isatty()
|
2012-07-24 08:10:56 +02:00
|
|
|
isatty_stderr = os.environ.get('TERM') != 'dumb' and sys.stderr.isatty()
|
2012-06-28 12:20:57 +02:00
|
|
|
|
2012-08-15 15:37:55 +02:00
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
def exit_helper(status):
|
|
|
|
if CONFIG["format"]:
|
|
|
|
print(output.get_formatted_output())
|
|
|
|
sys.exit(status)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_signals():
|
|
|
|
"""This block ensures that ^C interrupts are handled quietly."""
|
2011-08-31 15:38:32 +02:00
|
|
|
import signal
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
def exithandler(signum, frame):
|
2011-08-31 15:38:32 +02:00
|
|
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
|
|
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
2012-05-05 14:28:48 +02:00
|
|
|
print()
|
2012-06-28 12:20:57 +02:00
|
|
|
exit_helper(EINTR)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, exithandler)
|
|
|
|
signal.signal(signal.SIGTERM, exithandler)
|
|
|
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
|
|
|
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
def print_version():
|
2011-08-31 15:38:32 +02:00
|
|
|
"""Output the version info."""
|
2012-04-28 18:16:05 +02:00
|
|
|
print("%s (%s) - %s" \
|
2011-08-31 15:38:32 +02:00
|
|
|
% (__productname__, __version__, __description__))
|
|
|
|
print()
|
2012-04-28 18:16:05 +02:00
|
|
|
print("Author: %s <%s>" % (__author__, __email__))
|
2011-08-31 15:38:32 +02:00
|
|
|
print("Copyright 2011 Gentoo Foundation")
|
|
|
|
print("Distributed under the terms of the GNU General Public License v2")
|
|
|
|
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
def print_usage(_error=None, help=None):
|
2011-08-31 15:38:32 +02:00
|
|
|
"""Print help message. May also print partial help to stderr if an
|
|
|
|
error from {'options'} is specified."""
|
|
|
|
|
|
|
|
out = sys.stdout
|
|
|
|
if _error:
|
|
|
|
out = sys.stderr
|
2012-05-21 22:24:44 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
if not _error in ('global-options', 'packages',):
|
|
|
|
_error = None
|
2012-05-21 22:24:44 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
if not _error and not help:
|
|
|
|
help = 'all'
|
2012-05-21 22:24:44 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
if _error in ('global-options',):
|
2012-05-21 22:24:44 +02:00
|
|
|
output.eerror("Wrong option on command line.\n")
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
if _error in ('packages',):
|
2012-05-21 22:24:44 +02:00
|
|
|
output.eerror("You need to specify exactly one package.\n")
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
print(white("Usage:"), file=out)
|
2011-08-31 15:38:32 +02:00
|
|
|
if _error in ('global-options', 'packages',) or help == 'all':
|
2012-04-28 18:16:05 +02:00
|
|
|
print(" " + turquoise(__productname__),
|
2011-09-06 17:35:17 +02:00
|
|
|
yellow("[options]"),
|
2011-09-21 10:58:41 +02:00
|
|
|
green("<package> [<package> [...]]"), file=out)
|
2011-08-31 15:38:32 +02:00
|
|
|
if _error in ('global-options',) or help == 'all':
|
2012-04-28 18:16:05 +02:00
|
|
|
print(" " + turquoise(__productname__),
|
2011-09-06 17:35:17 +02:00
|
|
|
yellow("[--help, --version]"), file=out)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
print(file=out)
|
|
|
|
if _error in ('global-options',) or help:
|
2012-04-28 18:16:05 +02:00
|
|
|
print("Available ", yellow("options") + ":", file=out)
|
|
|
|
print(yellow(" -C, --nocolor") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - turn off colors on output", file=out)
|
2012-04-28 18:16:05 +02:00
|
|
|
print(yellow(" -q, --quiet") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - be as quiet as possible", file=out)
|
2012-04-28 18:16:05 +02:00
|
|
|
print(yellow(" -h, --help") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - display the help screen", file=out)
|
2012-04-28 18:16:05 +02:00
|
|
|
print(yellow(" -V, --version") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - display version info", file=out)
|
2012-04-28 18:16:05 +02:00
|
|
|
print(file=out)
|
|
|
|
print(yellow(" -1, --oneshot") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - stop as soon as a new version is found",
|
2012-04-28 18:16:05 +02:00
|
|
|
file=out)
|
|
|
|
print(yellow(" -b, --brute-force=<level>") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - define the brute force " + yellow("<level>") +
|
2012-04-28 18:16:05 +02:00
|
|
|
" (default: 2)\n" +
|
2012-07-17 12:27:22 +02:00
|
|
|
" " * 38 + "bigger levels will generate more versions numbers\n" +
|
|
|
|
" " * 38 + "0 means disabled", file=out)
|
2012-05-21 22:24:44 +02:00
|
|
|
print(yellow(" -f, --format=<format>") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - define the output " + yellow("<format>") +
|
2012-07-02 17:44:55 +02:00
|
|
|
" (available: json)", file=out)
|
2012-06-28 12:20:57 +02:00
|
|
|
print(yellow(" -p, --progress") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" - display a progress bar", file=out)
|
|
|
|
print(yellow(" -i, --ignore-pre-release") +
|
|
|
|
" " * 11 + "- Ignore non-stable versions", file=out)
|
|
|
|
print(yellow(" -I, --ignore-pre-release-if-stable") +
|
|
|
|
" - Ignore non-stable versions only if current\n" +
|
|
|
|
" " * 38 + "version is stable", file=out)
|
2012-07-20 08:22:52 +02:00
|
|
|
print(yellow(" --mirror") +
|
2012-07-26 10:44:10 +02:00
|
|
|
" - use mirror:// URIs", file=out)
|
2012-07-20 08:22:52 +02:00
|
|
|
print(yellow(" --ebuild-uri") +
|
2012-07-26 10:44:10 +02:00
|
|
|
" - use ebuild variables in URIs", file=out)
|
2012-04-28 18:16:05 +02:00
|
|
|
print(file=out)
|
2012-05-21 22:24:44 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
if _error in ('packages',) or help:
|
2012-04-28 18:16:05 +02:00
|
|
|
print(green(" package") +
|
2012-07-17 12:27:22 +02:00
|
|
|
" " * 28 + "- the packages (or ebuilds) you want to scan",
|
2012-04-28 18:16:05 +02:00
|
|
|
file=out)
|
|
|
|
print(file=out)
|
2012-05-21 22:24:44 +02:00
|
|
|
|
|
|
|
#print( "More detailed instruction can be found in",
|
|
|
|
#turquoise("`man %s`" % __productname__), file=out)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ParseArgsException(Exception):
|
|
|
|
"""For parseArgs() -> main() communications."""
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
def __str__(self):
|
|
|
|
return repr(self.value)
|
|
|
|
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
def parse_args():
|
2011-08-31 15:38:32 +02:00
|
|
|
"""Parse the command line arguments. Raise exceptions on
|
2012-05-21 22:24:44 +02:00
|
|
|
errors. Returns packages and affects the CONFIG dict.
|
2011-08-31 15:38:32 +02:00
|
|
|
"""
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
def option_switch(opts):
|
2011-08-31 15:38:32 +02:00
|
|
|
"""local function for interpreting command line options
|
|
|
|
and setting options accordingly"""
|
|
|
|
return_code = True
|
|
|
|
for o, a in opts:
|
|
|
|
if o in ("-h", "--help"):
|
2012-04-28 18:16:05 +02:00
|
|
|
raise ParseArgsException('help')
|
2011-08-31 15:38:32 +02:00
|
|
|
elif o in ("-V", "--version"):
|
|
|
|
raise ParseArgsException('version')
|
|
|
|
elif o in ("-C", "--nocolor"):
|
|
|
|
CONFIG['nocolor'] = True
|
|
|
|
pp.output.nocolor()
|
|
|
|
elif o in ("-q", "--quiet"):
|
|
|
|
CONFIG['quiet'] = True
|
2011-09-21 10:09:50 +02:00
|
|
|
CONFIG['verbose'] = 0
|
2011-08-31 15:38:32 +02:00
|
|
|
elif o in ("-1", "--oneshot"):
|
|
|
|
CONFIG['oneshot'] = True
|
|
|
|
elif o in ("-b", "--brute-force"):
|
|
|
|
CONFIG['brute-force'] = int(a)
|
|
|
|
elif o in ("-v", "--verbose") and not CONFIG['quiet']:
|
2012-05-21 22:24:44 +02:00
|
|
|
CONFIG['verbose'] += 1
|
|
|
|
elif o in ("-f", "--format"):
|
|
|
|
CONFIG['format'] = a
|
|
|
|
CONFIG['nocolor'] = True
|
|
|
|
pp.output.nocolor()
|
2012-06-28 12:20:57 +02:00
|
|
|
elif o in ("-p", "--progress"):
|
2012-07-24 08:10:56 +02:00
|
|
|
CONFIG['progress'] = isatty_stderr
|
2012-07-20 08:22:52 +02:00
|
|
|
elif o in ("--mirror"):
|
2012-07-02 17:44:55 +02:00
|
|
|
CONFIG['mirror'] = True
|
2012-07-17 12:27:22 +02:00
|
|
|
elif o in ("-i", "--ignore-pre-release"):
|
|
|
|
CONFIG['ignore-pre-release'] = True
|
|
|
|
elif o in ("-I", "--ignore-pre-release-if-stable"):
|
|
|
|
CONFIG['ignore-pre-release-if-stable'] = True
|
2012-07-20 08:22:52 +02:00
|
|
|
elif o in ("--ebuild-uri"):
|
|
|
|
CONFIG['ebuild-uri'] = True
|
2011-08-31 15:38:32 +02:00
|
|
|
else:
|
|
|
|
return_code = False
|
|
|
|
|
|
|
|
return return_code
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
# here are the different allowed command line options (getopt args)
|
2012-04-28 18:16:05 +02:00
|
|
|
getopt_options = {'short': {}, 'long': {}}
|
2012-07-20 08:22:52 +02:00
|
|
|
getopt_options['short']['global'] = "hVCqv1bf:piI"
|
2012-05-21 22:24:44 +02:00
|
|
|
getopt_options['long']['global'] = [
|
|
|
|
"help", "version", "nocolor", "quiet", "verbose", "oneshot",
|
2012-07-17 12:27:22 +02:00
|
|
|
"brute-force=", "format=", "progress", "mirror", "ignore-pre-release",
|
2012-07-20 08:22:52 +02:00
|
|
|
"ignore-pre-release-if-stable", "ebuild-uri"
|
2012-05-21 22:24:44 +02:00
|
|
|
]
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
short_opts = getopt_options['short']['global']
|
|
|
|
long_opts = getopt_options['long']['global']
|
|
|
|
opts_mode = 'global'
|
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
# apply getopts to command line, show partial help on failure
|
2011-08-31 15:38:32 +02:00
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], short_opts, long_opts)
|
|
|
|
except:
|
2012-04-28 18:16:05 +02:00
|
|
|
raise ParseArgsException(opts_mode + '-options')
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-21 22:24:44 +02:00
|
|
|
# set options accordingly
|
|
|
|
option_switch(opts)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-09-21 10:58:41 +02:00
|
|
|
if len(args) < 1:
|
2012-04-28 18:16:05 +02:00
|
|
|
raise ParseArgsException('packages')
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-09-21 10:58:41 +02:00
|
|
|
return args
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
def main():
|
|
|
|
"""Parse command line and execute all actions."""
|
2012-05-21 22:24:44 +02:00
|
|
|
CONFIG['nocolor'] = (
|
2012-09-02 18:58:01 +02:00
|
|
|
CONFIG['nocolor'] or
|
|
|
|
(settings["NOCOLOR"] in ('yes', 'true') or not isatty)
|
2012-05-21 22:24:44 +02:00
|
|
|
)
|
2011-08-31 15:38:32 +02:00
|
|
|
if CONFIG['nocolor']:
|
|
|
|
pp.output.nocolor()
|
2012-05-21 22:24:44 +02:00
|
|
|
|
|
|
|
# parse command line options and actions
|
2011-08-31 15:38:32 +02:00
|
|
|
try:
|
2012-05-23 16:30:43 +02:00
|
|
|
queries = parse_args()
|
2011-08-31 15:38:32 +02:00
|
|
|
except ParseArgsException as e:
|
|
|
|
if e.value == 'help':
|
2012-05-21 22:24:44 +02:00
|
|
|
print_usage(help='all')
|
|
|
|
exit_helper(0)
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
elif e.value[:5] == 'help-':
|
2012-05-21 22:24:44 +02:00
|
|
|
print_usage(help=e.value[5:])
|
|
|
|
exit_helper(0)
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
elif e.value == 'version':
|
2012-05-21 22:24:44 +02:00
|
|
|
print_version()
|
|
|
|
exit_helper(0)
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
else:
|
2012-05-21 22:24:44 +02:00
|
|
|
print_usage(e.value)
|
2012-06-28 12:20:57 +02:00
|
|
|
exit_helper(EINVAL)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-09-21 10:09:50 +02:00
|
|
|
if CONFIG['verbose'] > 2:
|
2012-06-28 12:20:57 +02:00
|
|
|
HTTPConnection.debuglevel = 1
|
|
|
|
|
2012-07-02 11:20:18 +02:00
|
|
|
if not CONFIG["format"] and not CONFIG['quiet']:
|
2012-06-28 12:20:57 +02:00
|
|
|
CONFIG["progress"] = False
|
2011-09-21 10:09:50 +02:00
|
|
|
|
2012-06-28 12:20:57 +02:00
|
|
|
on_progress = None
|
|
|
|
if CONFIG['progress']:
|
|
|
|
on_progress_gen = progress_bar()
|
|
|
|
on_progress = on_progress_gen.next()
|
2012-07-09 18:15:34 +02:00
|
|
|
on_progress(maxval=len(queries) * 100, increment=0, label="Working...")
|
2012-05-27 10:09:39 +02:00
|
|
|
|
2012-07-27 13:58:51 +02:00
|
|
|
# Importing stuff here for performance reasons
|
|
|
|
from euscan.scan import scan_upstream
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
for query in queries:
|
2012-06-28 12:43:46 +02:00
|
|
|
if CONFIG["progress"]:
|
|
|
|
on_progress(increment=10, label=query)
|
2012-05-27 10:09:39 +02:00
|
|
|
|
2011-10-02 10:03:49 +02:00
|
|
|
ret = []
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
output.set_query(query)
|
|
|
|
|
2011-09-21 10:58:41 +02:00
|
|
|
try:
|
2012-05-27 10:09:39 +02:00
|
|
|
ret = scan_upstream(query, on_progress)
|
2012-03-27 18:58:19 +02:00
|
|
|
except AmbiguousPackageName as e:
|
2011-12-11 14:32:38 +01:00
|
|
|
pkgs = e.args[0]
|
2012-05-21 22:24:44 +02:00
|
|
|
output.eerror("\n".join(pkgs))
|
2011-09-21 10:58:41 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
from os.path import basename # To get the short name
|
2011-09-21 10:58:41 +02:00
|
|
|
|
2012-09-15 23:20:30 +02:00
|
|
|
output.eerror(
|
2012-05-21 22:24:44 +02:00
|
|
|
"The short ebuild name '%s' is ambiguous. Please specify" %
|
2012-09-15 23:20:30 +02:00
|
|
|
basename(pkgs[0]) +
|
2012-05-21 22:24:44 +02:00
|
|
|
"one of the above fully-qualified ebuild names instead."
|
2012-04-28 18:16:05 +02:00
|
|
|
)
|
2012-05-21 22:24:44 +02:00
|
|
|
exit_helper(1)
|
|
|
|
|
2012-03-27 18:58:19 +02:00
|
|
|
except GentoolkitException as err:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.eerror('%s: %s' % (query, str(err)))
|
2012-05-21 22:24:44 +02:00
|
|
|
exit_helper(1)
|
|
|
|
|
2011-10-02 10:03:49 +02:00
|
|
|
except Exception as err:
|
2012-08-03 21:50:54 +02:00
|
|
|
import traceback
|
2012-08-07 09:39:49 +02:00
|
|
|
print ('-' * 60)
|
2012-08-03 21:50:54 +02:00
|
|
|
traceback.print_exc(file=sys.stderr)
|
2012-08-07 09:39:49 +02:00
|
|
|
print ('-' * 60)
|
2012-08-03 21:50:54 +02:00
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
output.eerror('%s: %s' % (query, str(err)))
|
2012-05-21 22:24:44 +02:00
|
|
|
exit_helper(1)
|
2011-09-21 10:58:41 +02:00
|
|
|
|
2012-06-08 14:43:18 +02:00
|
|
|
if not ret and not CONFIG['quiet']:
|
2012-08-03 21:50:54 +02:00
|
|
|
output.einfo(
|
2012-06-08 14:43:18 +02:00
|
|
|
"Didn't find any new version, check package's homepage " +
|
|
|
|
"for more informations"
|
|
|
|
)
|
2012-05-23 16:30:43 +02:00
|
|
|
|
2012-07-26 21:31:10 +02:00
|
|
|
if not (CONFIG['format'] or CONFIG['quiet']) and len(queries) > 1:
|
|
|
|
print("")
|
|
|
|
|
2012-06-28 12:20:57 +02:00
|
|
|
if CONFIG['progress']:
|
|
|
|
on_progress_gen.next()
|
|
|
|
print("\n", file=sys.stderr)
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
output.set_query(None)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-05-21 22:24:44 +02:00
|
|
|
setup_signals()
|
|
|
|
main()
|
|
|
|
exit_helper(0)
|