diff --git a/management/univention-management-console-module-appcenter/umc/python/appcenter/__init__.py b/management/univention-management-console-module-appcenter/umc/python/appcenter/__init__.py index 113f254..fcc938d 100644 --- a/management/univention-management-console-module-appcenter/umc/python/appcenter/__init__.py +++ b/management/univention-management-console-module-appcenter/umc/python/appcenter/__init__.py @@ -46,7 +46,7 @@ import notifier.threads from univention.lib.package_manager import PackageManager, LockError from univention.management.console.log import MODULE from univention.management.console.modules.decorators import simple_response, sanitize, sanitize_list, multi_response -from univention.management.console.modules.sanitizers import PatternSanitizer, MappingSanitizer, DictSanitizer, StringSanitizer, ChoicesSanitizer, ListSanitizer, EmailSanitizer +from univention.management.console.modules.sanitizers import PatternSanitizer, MappingSanitizer, DictSanitizer, StringSanitizer, ChoicesSanitizer, ListSanitizer, EmailSanitizer, BooleanSanitizer from univention.updater import UniventionUpdater from univention.updater.errors import ConfigurationError import univention.config_registry @@ -135,42 +135,39 @@ class Instance(umcm.Base): return application.to_dict(self.package_manager) return props - @sanitize( - function=ChoicesSanitizer(['install', 'update'], required=True), - application=StringSanitizer(minimum=1, required=True) - ) - def invoke_dry_run(self, request): - MODULE.info('invoke_dry_run') - function = request.options.get('function') - application_id = request.options.get('application') - application = Application.find(application_id) - - if not application: - MODULE.info('Application not found') - return self.finished(request.id, False) - if (function == 'install' and not - application.can_be_installed(self.package_manager)): - reason = application.cannot_install_reason(self.package_manager) - MODULE.info('Application cannot be installed: %s' % (reason, )) - return self.finished(request.id, False) - if function == 'update' and not application.can_be_updated(): - MODULE.info('Application cannot be updated') - return self.finished(request.id, False) - - result = application.install_dry_run(self.package_manager, self.component_manager) - self.finished(request.id, result) - @sanitize(function=ChoicesSanitizer(['install', 'uninstall', 'update'], required=True), - application=StringSanitizer(minimum=1, required=True) + application=StringSanitizer(minimum=1, required=True), + force=BooleanSanitizer() ) def invoke(self, request): function = request.options.get('function') application_id = request.options.get('application') + force = request.options.get('force') application = Application.find(application_id) try: # make sure that the application cane be installed/updated - can_continue = application is not None and not (function == 'install' and not application.can_be_installed(self.package_manager)) and not (function == 'update' and not application.can_be_updated()) - self.finished(request.id, can_continue) + can_continue = True + if not application: + MODULE.info('Application not found') + can_continue = False + if (function == 'install' and not + application.can_be_installed(self.package_manager)): + reason = application.cannot_install_reason(self.package_manager) + MODULE.info('Application cannot be installed: %s' % (reason, )) + can_continue = False + if function == 'update' and not application.can_be_updated(): + MODULE.info('Application cannot be updated') + can_continue = False + packages = application.install_dry_run(self.package_manager, + self.component_manager, + remove_component=False) + if not force and (packages['remove'] or packages['broken']): + can_continue = False + + result = {'success': can_continue, + 'packages': packages, } + self.finished(request.id, result) + if can_continue: def _thread(module, application, function): with module.package_manager.locked(reset_status=True, set_finished=True): diff --git a/management/univention-management-console-module-appcenter/umc/python/appcenter/app_center.py b/management/univention-management-console-module-appcenter/umc/python/appcenter/app_center.py index 455d7cd..3d7bfa1 100644 --- a/management/univention-management-console-module-appcenter/umc/python/appcenter/app_center.py +++ b/management/univention-management-console-module-appcenter/umc/python/appcenter/app_center.py @@ -439,7 +439,7 @@ class Application(object): self._send_information('uninstall', status) return status == 200 - def install_dry_run(self, package_manager, component_manager): + def install_dry_run(self, package_manager, component_manager, remove_component=True): MODULE.info('Invoke install_dry_run') result = None try: @@ -465,10 +465,11 @@ class Application(object): result = dict(zip(['install', 'remove', 'broken', ], result)) MODULE.info('Package changes: %s' % (result, )) - # remove the newly added component - MODULE.info('Remove component: %s' % (self.component_id, )) - component_manager.remove_app(self) - package_manager.update() + if remove_component and not result['remove'] and not result['broken']: + # remove the newly added component + MODULE.info('Remove component: %s' % (self.component_id, )) + component_manager.remove_app(self) + package_manager.update() except: MODULE.warn(traceback.format_exc())