def _sanitize(self, value, name, further_args):
     app = Apps().find(value)
     if not app.is_installed() and not app.install_permissions_exist():
         apps = Apps().get_all_apps_with_id(app.id)
         apps = [_app for _app in apps if not _app.install_permissions]
         if apps:
             app = sorted(apps)[-1]
     return app
예제 #2
0
 def _install_master_packages(self, app, unregister_if_uninstalled=False):
     old_app = Apps().find(app.id)
     was_installed = old_app.is_installed()
     if self._register_component(app):
         update_packages()
     ret = self._install_packages(app.default_packages_master)
     if was_installed:
         if old_app != app:
             self.log('Re-registering component for %s' % old_app)
             if self._register_component(old_app):
                 update_packages()
     elif unregister_if_uninstalled:
         self.log('Unregistering component for %s' % app)
         if self._unregister_component(app):
             update_packages()
     return ret
예제 #3
0
def app_is_running(app):
	from univention.appcenter.app_cache import Apps
	if isinstance(app, basestring):
		app = Apps().find(app)
	if app:
		if not app.docker:
			return False
		if not app.is_installed():
			return False
		try:
			from univention.appcenter.docker import Docker
		except ImportError:
			return None
		else:
			docker = Docker(app)
			return docker.is_running()
	else:
		return None
예제 #4
0
 def _sanitize(self, value, name, further_args):
     app_id = value
     app_version = None
     if '=' in value:
         app_id, app_version = tuple(value.split('=', 1))
     app = Apps().find(app_id, app_version=app_version)
     if not app.is_installed() and not app.install_permissions_exist():
         apps = Apps().get_all_apps_with_id(app.id)
         apps = [_app for _app in apps if not _app.install_permissions]
         if apps:
             if app_version:
                 for _app in apps:
                     if _app.version == app_version:
                         app = _app
                         break
             else:
                 app = sorted(apps)[-1]
     return app
예제 #5
0
 def _install_master_packages(self,
                              app,
                              percentage_end=100,
                              unregister_if_uninstalled=False):
     old_app = Apps().find(app.id)
     was_installed = old_app.is_installed()
     self._register_component(app)
     ret = self._install_packages(app.default_packages_master,
                                  percentage_end)
     if was_installed:
         if old_app != app:
             self.log('Re-registering component for %s' % old_app)
             self._register_component(old_app)
             self._apt_get_update()
     elif unregister_if_uninstalled:
         self.log('Unregistering component for %s' % app)
         self._unregister_component(app)
         self._apt_get_update()
     return ret
예제 #6
0
 def _install_packages_dry_run(self, app, args, with_dist_upgrade):
     original_app = Apps().find(app.id)
     if original_app.is_installed():
         was_installed = True
     else:
         was_installed = False
     self.log('Dry run for %s' % app)
     if self._register_component(app):
         self.debug('Updating packages')
         update_packages()
     self.debug('Component %s registered' % app.component_id)
     pkgs = self._get_packages_for_dry_run(app, args)
     self.debug('Dry running with %r' % pkgs)
     ret = install_packages_dry_run(pkgs)
     if with_dist_upgrade:
         upgrade_ret = dist_upgrade_dry_run()
         ret['install'] = sorted(
             set(ret['install']).union(set(upgrade_ret['install'])))
         ret['remove'] = sorted(
             set(ret['remove']).union(set(upgrade_ret['remove'])))
         ret['broken'] = sorted(
             set(ret['broken']).union(set(upgrade_ret['broken'])))
     if args.install_master_packages_remotely:
         # TODO: should test remotely
         self.log('Not testing package changes of remote packages!')
         pass
     if args.dry_run or ret['broken']:
         if was_installed:
             if self._register_component(original_app):
                 self.debug('Updating packages')
                 update_packages()
             self.debug('Component %s reregistered' %
                        original_app.component_id)
         else:
             if self._unregister_component(app):
                 self.debug('Updating packages')
                 update_packages()
             self.debug('Component %s unregistered' % app.component_id)
     return ret
예제 #7
0
def resolve_dependencies(apps, action):
	from univention.appcenter.app_cache import Apps
	from univention.appcenter.udm import get_machine_connection
	lo, pos = get_machine_connection()
	utils_logger.info('Resolving dependencies for %s' % ', '.join(app.id for app in apps))
	apps_with_their_dependencies = []
	depends = {}
	checked = []
	apps = apps[:]
	if action == 'remove':
		# special case: do not resolve dependencies as
		# we are going to uninstall the app
		# do not removed dependant apps either: the admin may want to keep them
		# => will get an error afterwards
		# BUT: reorder the apps if needed
		original_app_ids = [_app.id for _app in apps]
		for app in apps:
			checked.append(app)
			depends[app.id] = []
			for app_id in app.required_apps:
				if app_id not in original_app_ids:
					continue
				depends[app.id].append(app_id)
			for app_id in app.required_apps_in_domain:
				if app_id not in original_app_ids:
					continue
				depends[app.id].append(app_id)
		apps = []
	while apps:
		app = apps.pop()
		if app in checked:
			continue
		checked.insert(0, app)
		dependencies = depends[app.id] = []
		for app_id in app.required_apps:
			required_app = Apps().find(app_id)
			if required_app is None:
				utils_logger.warn('Could not find required App %s' % app_id)
				continue
			if not required_app.is_installed():
				utils_logger.info('Adding %s to the list of Apps' % required_app.id)
				apps.append(required_app)
				dependencies.append(app_id)
		for app_id in app.required_apps_in_domain:
			required_app = Apps().find(app_id)
			if required_app is None:
				utils_logger.warn('Could not find required App %s' % app_id)
				continue
			if required_app.is_installed():
				continue
			if lo.search('(&(univentionObjectType=appcenter/app)(univentionAppInstalledOnServer=*)(univentionAppID=%s_*))' % required_app.id):
				continue
			utils_logger.info('Adding %s to the list of Apps' % required_app.id)
			apps.append(required_app)
			dependencies.append(app_id)
	max_loop = len(checked) ** 2
	i = 0
	while checked:
		app = checked.pop(0)
		if not depends[app.id]:
			apps_with_their_dependencies.append(app)
			for app_id, required_apps in depends.items():
				try:
					required_apps.remove(app.id)
				except ValueError:
					pass
		else:
			checked.append(app)
		i += 1
		if i > max_loop:
			# this should never happen unless we release apps with dependency cycles
			raise RuntimeError('Cannot resolve dependency cycle!')
	if action == 'remove':
		# another special case:
		# we need to reverse the order: the app with the dependencies needs to be
		# removed first
		apps_with_their_dependencies.reverse()
	return apps_with_their_dependencies
 def test_upgrade(self, app):
     _app = Apps().find(app.id)
     if not _app.is_installed() or _app >= app:
         return False
예제 #9
0
from univention.appcenter.ucr import ucr_get, ucr_is_true

if len(sys.argv) < 2 or sys.argv[-1] == '-v':
    print('Usage: {} [-v] <app name>'.format(sys.argv[0]))
    sys.exit(2)
app_name = sys.argv[-1]

hostname_master = ucr_get('ldap/master').split('.')[0]
app = Apps().find(app_name)
if app is None:
    print('Unknown app "{}".'.format(app_name))
    sys.exit(2)
domain = get_action('domain')
info = domain.to_dict([app])[0]

if not app.is_installed():
    print('App "{}" is not installed on this host.'.format(app_name))
    sys.exit(2)

try:
    master_version = info['installations'][hostname_master]['version']
    if master_version is None:
        raise KeyError
except KeyError:
    print('App "{}" is not installed on DC master.'.format(app_name))
    sys.exit(2)

ret = LooseVersion(app.version) > LooseVersion(master_version)

if '-v' in sys.argv:
    print('Version of app "{}" on this host: "{}"'.format(