Index: scripts/univention-migrate-apps
===================================================================
--- scripts/univention-migrate-apps (Revision 0)
+++ scripts/univention-migrate-apps (Revision 0)
@@ -0,0 +1,87 @@
+#!/usr/bin/python2.6
+# -*- coding: utf-8 -*-
+#
+# Univention App Center
+# univention-register-apps
+#
+# Copyright 2014 Univention GmbH
+#
+# http://www.univention.de/
+#
+# All rights reserved.
+#
+# The source code of this program is made available
+# under the terms of the GNU Affero General Public License version 3
+# (GNU AGPL V3) as published by the Free Software Foundation.
+#
+# Binary versions of this program provided by Univention to you as
+# well as other copyrighted, protected or trademarked materials like
+# Logos, graphics, fonts, specific documentations and configurations,
+# cryptographic keys etc. are subject to a license agreement between
+# you and Univention and not subject to the GNU AGPL V3.
+#
+# In the case you use this program under the terms of the GNU AGPL V3,
+# the program is provided in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License with the Debian GNU/Linux or Univention distribution in file
+# /usr/share/common-licenses/AGPL-3; if not, see
+# .
+#
+
+import sys
+from optparse import OptionParser
+
+from univention.lib.package_manager import PackageManager
+from univention.updater import UniventionUpdater
+from univention.config_registry import ConfigRegistry
+from univention.management.console.modules.appcenter.util import ComponentManager, install_opener, set_save_commit_load
+from univention.management.console.modules.appcenter.app_center import Application
+
+ucr = ConfigRegistry()
+ucr.load()
+
+if __name__ == '__main__':
+ usage = '%prog'
+ description = '%prog migrates the components of all installed apps to a new format. You most probably want to set UCR variable repository/app_center/new_format BEFORE calling this script'
+ parser = OptionParser(usage=usage, description=description)
+ parser.add_option("-n", "--to-new", action="store_true", dest="new_format", default=True,
+ help="all components are migrated to the new format (much faster, but less features and less integration) in /etc/apt/sources.list.d/25_ucs-appcenter.list")
+ parser.add_option("-o", "--to-old", action="store_false", dest="new_format", default=True,
+ help="all components are migrated to the old format (slower, more features, more integration) in /etc/apt/sources.list.d/20_ucs-onlince.component.list")
+ parser.add_option("-f", "--force", action="store_true", dest="force", default=False,
+ help="if migrating, you better have set the UCR variable repository/app_center/new_format accordingly. Specifying --force disables a check that will exit the script if those do not match.")
+ options, args = parser.parse_args()
+
+ if ucr.is_true('repository/app_center/new_format', True) != options.new_format:
+ if not options.force:
+ sys.stderr.write('New format is set to %s. Which does not correspond to UCR variable repository/app_center/new_format. Existing now. You may specify --force to override this check.\n' % options.new_format)
+ sys.exit(1)
+ uu = UniventionUpdater(False)
+ component_manager = ComponentManager(ucr, uu)
+ package_manager = PackageManager(lock=False)
+
+ install_opener(ucr)
+ try:
+ with set_save_commit_load(component_manager.ucr) as super_ucr:
+ for app in Application.all_installed(package_manager, only_local=True):
+ if app.get('withoutrepository'):
+ continue
+ sys.stdout.write('Migrating %r.\n' % app)
+ if options.new_format:
+ component_manager.remove_app_old_format(app, super_ucr)
+ component_manager.put_app_new_format(app, super_ucr)
+ else:
+ component_manager.put_app_old_format(app, super_ucr)
+ component_manager.remove_app_new_format(app, super_ucr)
+ except Exception as exc:
+ sys.stderr.write('univention-migrate-apps did not succeed. Check the internet connection and try again.\n')
+ sys.exit(1)
+ else:
+ package_manager.update()
+ sys.stdout.write('All applications have been migrated.\n')
+ sys.exit(0)
+
Index: conffiles/etc/apt/sources.list.d/25_ucs-appcenter.list
===================================================================
--- conffiles/etc/apt/sources.list.d/25_ucs-appcenter.list (Revision 0)
+++ conffiles/etc/apt/sources.list.d/25_ucs-appcenter.list (Revision 0)
@@ -0,0 +1,25 @@
+@%@UCRWARNING=#@%@
+
+@!@
+from univention.config_registry import ConfigRegistry
+
+from univention.management.console.modules.appcenter.app_center import Application
+
+Application.all(only_local=True)
+
+ucr = ConfigRegistry()
+ucr.load()
+
+app_ucr_key = 'repository/app_center/apps/'
+for key in ucr.iterkeys():
+ if key.startswith(app_ucr_key):
+ component = key[len(app_ucr_key):]
+ app = Application.find(component=component)
+ print
+ if app:
+ print '# %r' % app
+ print app.debian_repository(arch=False)
+ print app.debian_repository(arch=True)
+ else:
+ print '# %s not found' % component
+@!@
Index: debian/univention-management-console-module-appcenter.install
===================================================================
--- debian/univention-management-console-module-appcenter.install (Revision 50922)
+++ debian/univention-management-console-module-appcenter.install (Arbeitskopie)
@@ -3,3 +3,4 @@
ldap/*.acl usr/share/univention-management-console-module-appcenter
scripts/univention-register-apps usr/sbin/
scripts/univention-rename-app usr/sbin/
+scripts/univention-migrate-apps usr/sbin/
Index: debian/univention-management-console-module-apps.univention-config-registry
===================================================================
--- debian/univention-management-console-module-apps.univention-config-registry (Revision 50922)
+++ debian/univention-management-console-module-apps.univention-config-registry (Arbeitskopie)
@@ -1,4 +1,10 @@
Type: file
+File: etc/apt/sources.list.d/25_ucs-appcenter.list
+Variables: repository/app_center/apps/.*
+Variables: repository/app_center/server
+Variables: version/version
+
+Type: file
File: usr/share/univention-management-console/i18n/de/apps.mo
Type: file
Index: umc/python/appcenter/util.py
===================================================================
--- umc/python/appcenter/util.py (Revision 50922)
+++ umc/python/appcenter/util.py (Arbeitskopie)
@@ -44,10 +44,12 @@
from univention.admin.handlers.computers import domaincontroller_master
from univention.admin.handlers.computers import domaincontroller_backup
-
# local application
from constants import COMPONENT_BASE, COMP_PARAMS, STATUS_ICONS, DEFAULT_ICON, PUT_SUCCESS, PUT_PROCESSING_ERROR
+_ucr = univention.config_registry.ConfigRegistry()
+_ucr.load()
+
def rename_app(old_id, new_id, component_manager, package_manager):
from univention.management.console.modules.appcenter.app_center import Application
app = Application.find(old_id)
@@ -133,7 +135,7 @@
def component_registered(component_id, ucr):
''' Checks if a component is registered (enabled or disabled).
Moved outside of ComponentManager to avoid dependencies for
- UniventionUpdater when just using Application.all() '''
+ UniventionUpdater'''
return '%s/%s' % (COMPONENT_BASE, component_id) in ucr
def component_current(component_id, ucr):
@@ -273,10 +275,26 @@
def is_registered(self, component_id):
return component_registered(component_id, self.ucr)
- def put_app(self, app, super_ucr=None):
+ def put_app_new_format(self, app, super_ucr=None):
if super_ucr is None:
with set_save_commit_load(self.ucr) as super_ucr:
return self.put_app(app, super_ucr)
+ ucr_var = app.repository_ucr_var()
+ if ucr_var:
+ super_ucr.set_registry_var(ucr_var, 'enabled')
+
+ def remove_app_new_format(self, app, super_ucr=None):
+ if super_ucr is None:
+ with set_save_commit_load(self.ucr) as super_ucr:
+ return self.remove_app(app, super_ucr)
+ ucr_var = app.repository_ucr_var()
+ if ucr_var:
+ super_ucr.set_registry_var(ucr_var, '')
+
+ def put_app_old_format(self, app, super_ucr=None):
+ if super_ucr is None:
+ with set_save_commit_load(self.ucr) as super_ucr:
+ return self.put_app(app, super_ucr)
app_data = {
'server' : app.get_server(),
'prefix' : '',
@@ -296,12 +314,19 @@
app_data['version'] = 'current'
self.put(app_data, super_ucr)
- def remove_app(self, app, super_ucr=None):
+ def remove_app_old_format(self, app, super_ucr):
if super_ucr is None:
with set_save_commit_load(self.ucr) as super_ucr:
return self.remove_app(app, super_ucr)
self._remove(app.component_id, super_ucr)
+ if _ucr.is_true('repository/app_center/new_format', True):
+ put_app = put_app_new_format
+ remove_app = remove_app_new_format
+ else:
+ put_app = put_app_old_format
+ remove_app = remove_app_old_format
+
def put(self, data, super_ucr):
""" Does the real work of writing one component definition back.
Will be called for each element in the request array of
@@ -360,6 +385,30 @@
self.put({'name' : component_id, 'version' : ''}, super_ucr)
return super_ucr.changed()
+ def enable_app(self, app, super_ucr=None):
+ if super_ucr is None:
+ with set_save_commit_load(self.ucr) as super_ucr:
+ return self.enable_app(app, super_ucr)
+ if self.ucr.is_true('repository/app_center/new_format', True):
+ ucr_var = app.repository_ucr_var()
+ if ucr_var:
+ super_ucr.set_registry_var(ucr_var, 'enabled')
+ else:
+ self.currentify(app.component_id, super_ucr)
+ return super_ucr.changed()
+
+ def disable_app(self, app, super_ucr=None):
+ if super_ucr is None:
+ with set_save_commit_load(self.ucr) as super_ucr:
+ return self.disable_app(app, super_ucr)
+ if self.ucr.is_true('repository/app_center/new_format', True):
+ ucr_var = app.repository_ucr_var()
+ if ucr_var:
+ super_ucr.set_registry_var(ucr_var, 'disabled')
+ else:
+ self.uncurrentify(app.component_id, super_ucr)
+ return super_ucr.changed()
+
def _remove(self, component_id, super_ucr):
named_component_base = '%s/%s' % (COMPONENT_BASE, component_id)
for var in COMP_PARAMS:
Index: umc/python/appcenter/app_center.py
===================================================================
--- umc/python/appcenter/app_center.py (Revision 50922)
+++ umc/python/appcenter/app_center.py (Arbeitskopie)
@@ -515,10 +515,15 @@
)
@classmethod
- def find(cls, application_id):
+ def find(cls, application_id=None, component=None):
for application in cls.all():
- if application.id == application_id:
- return application
+ if component is None:
+ if application.id == application_id:
+ return application
+ else:
+ for version in application.versions:
+ if application.component_id == component:
+ return version
@classmethod
def _get_category_translations(cls, fake=False):
@@ -654,7 +659,7 @@
shutil.copymode(template_png, png_16)
@classmethod
- def all_installed(cls, package_manager, force_reread=False, only_local=False, localize=True):
+ def all_installed(cls, package_manager, force_reread=False, only_local=False, localize=None):
ret = []
for app in cls.all(force_reread=force_reread, only_local=only_local, localize=localize):
if app.allowed_on_local_server() and app.is_installed(package_manager, strict=False):
@@ -662,11 +667,13 @@
return ret
@classmethod
- def all(cls, force_reread=False, only_local=False, localize=True):
+ def all(cls, force_reread=False, only_local=False, localize=None):
# reload ucr variables
ucr.load()
# load the first time the category translations
+ if localize is None:
+ localize = not only_local
cls._get_category_translations(fake=not localize)
if force_reread:
@@ -743,24 +750,28 @@
def is_registered(self, ucr):
if self.get('withoutrepository'):
return True
- return component_registered(self.component_id, ucr)
+ if ucr.is_true('repository/app_center/new_format', True):
+ return self.repository_ucr_var() in ucr
+ else:
+ return component_registered(self.component_id, ucr)
def is_current(self, ucr):
if self.get('withoutrepository'):
return True
- return component_current(self.component_id, ucr)
+ if ucr.is_true('repository/app_center/new_format', True):
+ return ucr.get(self.repository_ucr_var()) == 'enabled'
+ else:
+ return component_current(self.component_id, ucr)
def disable_component(self, component_manager):
if self.get('withoutrepository'):
return
- with set_save_commit_load(component_manager.ucr) as super_ucr:
- return component_manager.uncurrentify(self.component_id, super_ucr)
+ return component_manager.disable_app(self)
def enable_component(self, component_manager):
if self.get('withoutrepository'):
return
- with set_save_commit_load(component_manager.ucr) as super_ucr:
- return component_manager.currentify(self.component_id, super_ucr)
+ return component_manager.enable_app(self)
def allowed_on_local_server(self):
server_role = ucr.get('server/role')
@@ -795,6 +806,21 @@
res['fully_loaded'] = True
return res
+ def repository_ucr_var(self):
+ if self.get('withoutrepository'):
+ return None
+ return 'repository/app_center/apps/%s' % self.component_id
+
+ def debian_repository(self, arch):
+ if arch is False:
+ arch = 'all'
+ if arch is True:
+ arch = '$(ARCH)'
+ server = self.get_server()
+ version = self.get_ucs_version()
+ repo_name = self.component_id
+ return 'deb http://%s/univention-repository/%s/maintained/component/ %s/%s/' % (server, version, repo_name, arch)
+
def __repr__(self):
return '' % (self.id, self.name, self.version, self.component_id)