|
33 |
# <http://www.gnu.org/licenses/>. |
33 |
# <http://www.gnu.org/licenses/>. |
34 |
|
34 |
|
35 |
import os |
35 |
import os |
|
|
36 |
import re |
36 |
import sys |
37 |
import sys |
37 |
import time |
38 |
import time |
38 |
from optparse import OptionParser, OptionGroup |
39 |
from optparse import OptionParser, OptionGroup |
|
39 |
import subprocess |
40 |
import subprocess |
40 |
import traceback |
41 |
import traceback |
41 |
import logging |
42 |
import logging |
|
|
43 |
import operator |
42 |
|
44 |
|
43 |
import univention.config_registry |
45 |
import univention.config_registry |
44 |
|
46 |
|
|
125 |
return False |
127 |
return False |
126 |
|
128 |
|
127 |
|
129 |
|
128 |
def _package_list(new_packages): |
130 |
def _shorten_package_version(package): |
129 |
"""Return comma separated list of packages.""" |
131 |
m = re.match(r'(.*)A~\d+', package) |
130 |
l = [] |
132 |
return m.groups()[0] if m else package |
131 |
for p in new_packages: |
|
|
132 |
l.append(p[0]) |
133 |
return ','.join(l) |
134 |
|
133 |
|
135 |
|
134 |
|
|
|
135 |
def _package_list(new_packages, terminal_width): |
136 |
""" |
137 |
Return new line separated list of packages. |
138 |
Lines will be truncated at terminal_width. |
139 |
""" |
140 |
if not new_packages: |
141 |
return '' |
142 |
if len(new_packages[0]) == 2: |
143 |
# install |
144 |
p_list = [(p[0], _shorten_package_version(p[1])) for p in new_packages] |
145 |
return '\n'.join(sorted( |
146 |
['{} ({})'.format(*p)[:terminal_width] for p in p_list], |
147 |
key=operator.itemgetter(0))) |
148 |
if len(new_packages[0]) == 3: |
149 |
# upgrade |
150 |
p_list = list() |
151 |
# shorten package version strings only if both versions can be reduced |
152 |
for p in new_packages: |
153 |
p1 = _shorten_package_version(p[1]) |
154 |
p2 = _shorten_package_version(p[2]) |
155 |
if p1 != p[1] and p2 != p[2]: |
156 |
p_list.append((p[0], p1, p2)) |
157 |
else: |
158 |
p_list.append(p) |
159 |
return '\n'.join(sorted( |
160 |
['{0} ({2} old: {1})'.format(*p)[:terminal_width] for p in p_list], |
161 |
key=operator.itemgetter(0))) |
162 |
return '\n'.join(sorted(p[0] for p in new_packages)) |
163 |
|
164 |
|
136 |
def performUpdate(options, checkForUpdates=False, silent=False): |
165 |
def performUpdate(options, checkForUpdates=False, silent=False): |
137 |
for func in (do_package_updates, do_app_updates, do_release_update): |
166 |
for func in (do_package_updates, do_app_updates, do_release_update): |
138 |
if func(options, checkForUpdates, silent): |
167 |
if func(options, checkForUpdates, silent): |
|
203 |
return True |
232 |
return True |
204 |
|
233 |
|
205 |
dprint(silent, 'found\n') |
234 |
dprint(silent, 'found\n') |
|
|
235 |
try: |
236 |
_length, _width = subprocess.check_output(['stty', 'size']).decode().split() |
237 |
terminal_width = int(_width) |
238 |
except (OSError, ValueError, subprocess.CalledProcessError): |
239 |
terminal_width = 80 |
206 |
if len(removed_packages) > 0: |
240 |
if len(removed_packages) > 0: |
207 |
dprint(silent, 'The following packages will be REMOVED:\n %s' % _package_list(removed_packages)) |
241 |
dprint(silent, 'The following packages will be REMOVED:\n%s' % _package_list(removed_packages, terminal_width)) |
208 |
if len(new_packages) > 0: |
242 |
if len(new_packages) > 0: |
209 |
dprint(silent, 'The following packages will be installed:\n %s' % _package_list(new_packages)) |
243 |
dprint(silent, 'The following packages will be installed:\n%s' % _package_list(new_packages, terminal_width)) |
210 |
if len(upgraded_packages) > 0: |
244 |
if len(upgraded_packages) > 0: |
211 |
dprint(silent, 'The following packages will be upgraded:\n %s' % _package_list(upgraded_packages)) |
245 |
dprint(silent, 'The following packages will be upgraded:\n%s' % _package_list(upgraded_packages, terminal_width)) |
212 |
if interactive and not readcontinue('\nDo you want to continue [Y|n]?'): |
246 |
if interactive and not readcontinue('\nDo you want to continue [Y|n]?'): |
213 |
return False |
247 |
return False |
214 |
|
248 |
|