def init(self):
        os.umask(
            0o022
        )  # umc umask is too restrictive for app center as it creates a lot of files in docker containers
        self.ucr = ucr_instance()

        self.update_applications_done = False
        install_opener(self.ucr)
        self._is_working = False

        try:
            self.package_manager = PackageManager(
                info_handler=MODULE.process,
                step_handler=None,
                error_handler=MODULE.warn,
                lock=False,
            )
        except SystemError as exc:
            MODULE.error(str(exc))
            raise umcm.UMC_Error(str(exc), status=500)
        self.package_manager.set_finished(
        )  # currently not working. accepting new tasks
        get_package_manager._package_manager = self.package_manager

        # build cache
        _update_modules()
        get_action('list').get_apps()

        # not initialize here: error prone due to network errors and also kinda slow
        self._uu = None
        self._cm = None

        # in order to set the correct locale
        locale.setlocale(locale.LC_ALL, str(self.locale))

        try:
            log_to_logfile()
        except IOError:
            pass

        # connect univention.appcenter.log to the progress-method
        handler = ProgressInfoHandler(self.package_manager)
        handler.setLevel(logging.INFO)
        get_base_logger().addHandler(handler)

        percentage = ProgressPercentageHandler(self.package_manager)
        percentage.setLevel(logging.DEBUG)
        get_base_logger().getChild('actions.install.progress').addHandler(
            percentage)
        get_base_logger().getChild('actions.upgrade.progress').addHandler(
            percentage)
        get_base_logger().getChild('actions.remove.progress').addHandler(
            percentage)
Exemplo n.º 2
0
	def init(self):
		os.umask(0o022)  # umc umask is too restrictive for app center as it creates a lot of files in docker containers
		self.ucr = ucr_instance()

		self.update_applications_done = False
		util.install_opener(self.ucr)
		self._remote_progress = {}

		try:
			self.package_manager = PackageManager(
				info_handler=MODULE.process,
				step_handler=None,
				error_handler=MODULE.warn,
				lock=False,
			)
		except SystemError as exc:
			MODULE.error(str(exc))
			raise umcm.UMC_Error(str(exc), status=500)
		self.package_manager.set_finished()  # currently not working. accepting new tasks
		self.uu = UniventionUpdater(False)
		self.component_manager = util.ComponentManager(self.ucr, self.uu)
		get_package_manager._package_manager = self.package_manager

		# in order to set the correct locale for Application
		locale.setlocale(locale.LC_ALL, str(self.locale))

		try:
			log_to_logfile()
		except IOError:
			pass

		# connect univention.appcenter.log to the progress-method
		handler = ProgressInfoHandler(self.package_manager)
		handler.setLevel(logging.INFO)
		get_base_logger().addHandler(handler)

		percentage = ProgressPercentageHandler(self.package_manager)
		percentage.setLevel(logging.DEBUG)
		get_base_logger().getChild('actions.install.progress').addHandler(percentage)
		get_base_logger().getChild('actions.upgrade.progress').addHandler(percentage)
		get_base_logger().getChild('actions.remove.progress').addHandler(percentage)
Exemplo n.º 3
0
import re
import stat
from shutil import rmtree
import subprocess
from contextlib import contextmanager

import pytest

from univention.appcenter.actions import get_action, Abort
from univention.appcenter.app_cache import Apps
from univention.appcenter.settings import SettingValueError
from univention.appcenter.ucr import ucr_get, ucr_save
from univention.appcenter.log import log_to_logfile, log_to_stream
from univention.appcenter.docker import Docker

log_to_logfile()
log_to_stream()


class Configuring(object):
    def __init__(self, app, revert='configure'):
        self.settings = set()
        self.app = app
        self.revert = revert

    def __enter__(self):
        return self

    def set(self, config):
        self.settings.update(config)
        configure = get_action('configure')
def do_app_updates(options: Namespace, checkForUpdates: bool,
                   silent: bool) -> Optional[bool]:
    dprint(silent, 'Checking for app updates: ', newline=False)
    if not options.app_updates:
        dprint(silent, 'skipped')
        return None

    interactive = not (options.noninteractive or checkForUpdates)
    try:
        from univention.appcenter.actions import get_action, Abort
        from univention.appcenter.app_cache import Apps
        import univention.appcenter.log as appcenter_log
        app_upgrade_search = get_action('upgrade-search')
        app_upgrade = get_action('upgrade')
        if app_upgrade is None:
            raise ImportError()
    except ImportError:
        # the new univention.appcenter package is not installed. Never mind
        # cannot be a dependency as the app center depends on updater...
        dprint(silent, 'unavailable')
        return False

    # check if component updates are available
    appcenter_log.log_to_logfile()

    # own logging
    logger = logging.getLogger('univention.appcenter.actions.upgrade.readme')
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.INFO)
    logger.addHandler(handler)

    try:
        app_upgrade_search.call()
    except Abort:
        pass

    new_apps = list(app_upgrade.iter_upgradable_apps())
    if not new_apps:
        dprint(silent, 'none')
        return False
    elif checkForUpdates:
        dprint(silent, 'found')
        return True

    dprint(silent, 'found\n')
    dprint(silent, 'The following apps can be upgraded:\n')
    for app in new_apps:
        newer_app = Apps().find_candidate(app)
        if newer_app:
            dprint(
                silent,
                '%(name)s: Version %(old)s can be upgraded to %(new)s' % {
                    'name': app.name,
                    'old': app.version,
                    'new': newer_app.version,
                })
        elif app.docker:
            dprint(
                silent,
                '%(name)s: The underlying container can be upgraded' % {
                    'name': app.name,
                })
        else:
            # don't know how this is possible... but anyways
            dprint(silent, '%(name)s' % {
                'name': app.name,
            })

    dprint(silent,
           'Starting univention-app upgrade at %s...' % time.ctime(),
           debug=True)
    dprint(silent,
           'Most of the output for App upgrades goes to %s' %
           appcenter_log.LOG_FILE,
           debug=True)
    dprint(silent, '\nStarting app upgrade', newline=False)
    success = True
    for app in new_apps:
        if interactive and not readcontinue(
                '\nDo you want to upgrade %s [Y|n]?' % app.name):
            continue
        success &= bool(
            app_upgrade.call_safe(
                app=app,
                noninteractive=not interactive,
                username=options.username,
                pwdfile=options.pwdfile.name if options.pwdfile else None,
            ))

    if not success:
        dprint(
            silent, 'ERROR: app upgrade failed. Please check %s\n' %
            appcenter_log.LOG_FILE)
        return False  # pretend no updates available; otherwise do_exec may result in infinite loop
    dprint(silent,
           'univention-app upgrade finished at %s...' % time.ctime(),
           debug=True)
    dprint(silent, 'done')
    return not success  # pending updates
 def init(self):
     locale.setlocale(locale.LC_ALL, str(self.locale))
     try:
         log_to_logfile()
     except IOError:
         pass