Index: base/univention-updater/python/univention-upgrade =================================================================== --- base/univention-updater/python/univention-upgrade (Revision 79032) +++ base/univention-updater/python/univention-upgrade (Arbeitskopie) @@ -33,6 +33,7 @@ # . import os +import re import sys import time from optparse import OptionParser, OptionGroup @@ -39,6 +40,7 @@ import subprocess import traceback import logging +import operator import univention.config_registry @@ -125,14 +127,41 @@ return False -def _package_list(new_packages): - """Return comma separated list of packages.""" - l = [] - for p in new_packages: - l.append(p[0]) - return ','.join(l) +def _shorten_package_version(package): + m = re.match(r'(.*)A~\d+', package) + return m.groups()[0] if m else package +def _package_list(new_packages, terminal_width): + """ + Return new line separated list of packages. + Lines will be truncated at terminal_width. + """ + if not new_packages: + return '' + if len(new_packages[0]) == 2: + # install + p_list = [(p[0], _shorten_package_version(p[1])) for p in new_packages] + return '\n'.join(sorted( + ['{} ({})'.format(*p)[:terminal_width] for p in p_list], + key=operator.itemgetter(0))) + if len(new_packages[0]) == 3: + # upgrade + p_list = list() + # shorten package version strings only if both versions can be reduced + for p in new_packages: + p1 = _shorten_package_version(p[1]) + p2 = _shorten_package_version(p[2]) + if p1 != p[1] and p2 != p[2]: + p_list.append((p[0], p1, p2)) + else: + p_list.append(p) + return '\n'.join(sorted( + ['{0} ({2} old: {1})'.format(*p)[:terminal_width] for p in p_list], + key=operator.itemgetter(0))) + return '\n'.join(sorted(p[0] for p in new_packages)) + + def performUpdate(options, checkForUpdates=False, silent=False): for func in (do_package_updates, do_app_updates, do_release_update): if func(options, checkForUpdates, silent): @@ -203,12 +232,17 @@ return True dprint(silent, 'found\n') + try: + _length, _width = subprocess.check_output(['stty', 'size']).decode().split() + terminal_width = int(_width) + except (OSError, ValueError, subprocess.CalledProcessError): + terminal_width = 80 if len(removed_packages) > 0: - dprint(silent, 'The following packages will be REMOVED:\n %s' % _package_list(removed_packages)) + dprint(silent, 'The following packages will be REMOVED:\n%s' % _package_list(removed_packages, terminal_width)) if len(new_packages) > 0: - dprint(silent, 'The following packages will be installed:\n %s' % _package_list(new_packages)) + dprint(silent, 'The following packages will be installed:\n%s' % _package_list(new_packages, terminal_width)) if len(upgraded_packages) > 0: - dprint(silent, 'The following packages will be upgraded:\n %s' % _package_list(upgraded_packages)) + dprint(silent, 'The following packages will be upgraded:\n%s' % _package_list(upgraded_packages, terminal_width)) if interactive and not readcontinue('\nDo you want to continue [Y|n]?'): return False