View | Details | Raw Unified | Return to bug 34989
Collapse All | Expand All

(-)scripts/univention-migrate-apps (+87 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.6
2
# -*- coding: utf-8 -*-
3
#
4
# Univention App Center
5
#  univention-register-apps
6
#
7
# Copyright 2014 Univention GmbH
8
#
9
# http://www.univention.de/
10
#
11
# All rights reserved.
12
#
13
# The source code of this program is made available
14
# under the terms of the GNU Affero General Public License version 3
15
# (GNU AGPL V3) as published by the Free Software Foundation.
16
#
17
# Binary versions of this program provided by Univention to you as
18
# well as other copyrighted, protected or trademarked materials like
19
# Logos, graphics, fonts, specific documentations and configurations,
20
# cryptographic keys etc. are subject to a license agreement between
21
# you and Univention and not subject to the GNU AGPL V3.
22
#
23
# In the case you use this program under the terms of the GNU AGPL V3,
24
# the program is provided in the hope that it will be useful,
25
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
# GNU Affero General Public License for more details.
28
#
29
# You should have received a copy of the GNU Affero General Public
30
# License with the Debian GNU/Linux or Univention distribution in file
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
33
#
34
35
import sys
36
from optparse import OptionParser
37
38
from univention.lib.package_manager import PackageManager
39
from univention.updater import UniventionUpdater
40
from univention.config_registry import ConfigRegistry
41
from univention.management.console.modules.appcenter.util import ComponentManager, install_opener, set_save_commit_load
42
from univention.management.console.modules.appcenter.app_center import Application
43
44
ucr = ConfigRegistry()
45
ucr.load()
46
47
if __name__ == '__main__':
48
	usage = '%prog'
49
	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'
50
	parser = OptionParser(usage=usage, description=description)
51
	parser.add_option("-n", "--to-new", action="store_true", dest="new_format", default=True,
52
			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")
53
	parser.add_option("-o", "--to-old", action="store_false", dest="new_format", default=True,
54
			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")
55
	parser.add_option("-f", "--force", action="store_true", dest="force", default=False,
56
			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.")
57
	options, args = parser.parse_args()
58
59
	if ucr.is_true('repository/app_center/new_format', True) != options.new_format:
60
		if not options.force:
61
			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)
62
			sys.exit(1)
63
	uu = UniventionUpdater(False)
64
	component_manager = ComponentManager(ucr, uu)
65
	package_manager = PackageManager(lock=False)
66
67
	install_opener(ucr)
68
	try:
69
		with set_save_commit_load(component_manager.ucr) as super_ucr:
70
			for app in Application.all_installed(package_manager, only_local=True):
71
				if app.get('withoutrepository'):
72
					continue
73
				sys.stdout.write('Migrating %r.\n' % app)
74
				if options.new_format:
75
					component_manager.remove_app_old_format(app, super_ucr)
76
					component_manager.put_app_new_format(app, super_ucr)
77
				else:
78
					component_manager.put_app_old_format(app, super_ucr)
79
					component_manager.remove_app_new_format(app, super_ucr)
80
	except Exception as exc:
81
		sys.stderr.write('univention-migrate-apps did not succeed. Check the internet connection and try again.\n')
82
		sys.exit(1)
83
	else:
84
		package_manager.update()
85
		sys.stdout.write('All applications have been migrated.\n')
86
		sys.exit(0)
87
(-)conffiles/etc/apt/sources.list.d/25_ucs-appcenter.list (+25 lines)
Line 0    Link Here 
1
@%@UCRWARNING=#@%@
2
3
@!@
4
from univention.config_registry import ConfigRegistry
5
6
from univention.management.console.modules.appcenter.app_center import Application
7
8
Application.all(only_local=True)
9
10
ucr = ConfigRegistry()
11
ucr.load()
12
13
app_ucr_key = 'repository/app_center/apps/'
14
for key in ucr.iterkeys():
15
        if key.startswith(app_ucr_key):
16
                component = key[len(app_ucr_key):]
17
                app = Application.find(component=component)
18
                print
19
                if app:
20
                        print '# %r' % app 
21
                        print app.debian_repository(arch=False)
22
                        print app.debian_repository(arch=True)
23
                else:
24
                        print '# %s not found' % component
25
@!@
(-)debian/univention-management-console-module-appcenter.install (+1 lines)
 Lines 3-5    Link Here 
3
ldap/*.acl usr/share/univention-management-console-module-appcenter
3
ldap/*.acl usr/share/univention-management-console-module-appcenter
4
scripts/univention-register-apps usr/sbin/
4
scripts/univention-register-apps usr/sbin/
5
scripts/univention-rename-app usr/sbin/
5
scripts/univention-rename-app usr/sbin/
6
scripts/univention-migrate-apps usr/sbin/
(-)debian/univention-management-console-module-apps.univention-config-registry (+6 lines)
 Lines 1-4    Link Here 
1
Type: file
1
Type: file
2
File: etc/apt/sources.list.d/25_ucs-appcenter.list
3
Variables: repository/app_center/apps/.*
4
Variables: repository/app_center/server
5
Variables: version/version
6
7
Type: file
2
File: usr/share/univention-management-console/i18n/de/apps.mo
8
File: usr/share/univention-management-console/i18n/de/apps.mo
3
9
4
Type: file
10
Type: file
(-)umc/python/appcenter/util.py (-4 / +53 lines)
 Lines 44-53    Link Here 
44
from univention.admin.handlers.computers import domaincontroller_master
44
from univention.admin.handlers.computers import domaincontroller_master
45
from univention.admin.handlers.computers import domaincontroller_backup
45
from univention.admin.handlers.computers import domaincontroller_backup
46
46
47
48
# local application
47
# local application
49
from constants import COMPONENT_BASE, COMP_PARAMS, STATUS_ICONS, DEFAULT_ICON, PUT_SUCCESS, PUT_PROCESSING_ERROR
48
from constants import COMPONENT_BASE, COMP_PARAMS, STATUS_ICONS, DEFAULT_ICON, PUT_SUCCESS, PUT_PROCESSING_ERROR
50
49
50
_ucr = univention.config_registry.ConfigRegistry()
51
_ucr.load()
52
51
def rename_app(old_id, new_id, component_manager, package_manager):
53
def rename_app(old_id, new_id, component_manager, package_manager):
52
	from univention.management.console.modules.appcenter.app_center import Application
54
	from univention.management.console.modules.appcenter.app_center import Application
53
	app = Application.find(old_id)
55
	app = Application.find(old_id)
 Lines 133-139    Link Here 
133
def component_registered(component_id, ucr):
135
def component_registered(component_id, ucr):
134
	''' Checks if a component is registered (enabled or disabled).
136
	''' Checks if a component is registered (enabled or disabled).
135
	Moved outside of ComponentManager to avoid dependencies for
137
	Moved outside of ComponentManager to avoid dependencies for
136
	UniventionUpdater when just using Application.all() '''
138
	UniventionUpdater'''
137
	return '%s/%s' % (COMPONENT_BASE, component_id) in ucr
139
	return '%s/%s' % (COMPONENT_BASE, component_id) in ucr
138
140
139
def component_current(component_id, ucr):
141
def component_current(component_id, ucr):
 Lines 273-282    Link Here 
273
	def is_registered(self, component_id):
275
	def is_registered(self, component_id):
274
		return component_registered(component_id, self.ucr)
276
		return component_registered(component_id, self.ucr)
275
277
276
	def put_app(self, app, super_ucr=None):
278
	def put_app_new_format(self, app, super_ucr=None):
277
		if super_ucr is None:
279
		if super_ucr is None:
278
			with set_save_commit_load(self.ucr) as super_ucr:
280
			with set_save_commit_load(self.ucr) as super_ucr:
279
				return self.put_app(app, super_ucr)
281
				return self.put_app(app, super_ucr)
282
		ucr_var = app.repository_ucr_var()
283
		if ucr_var:
284
			super_ucr.set_registry_var(ucr_var, 'enabled')
285
286
	def remove_app_new_format(self, app, super_ucr=None):
287
		if super_ucr is None:
288
			with set_save_commit_load(self.ucr) as super_ucr:
289
				return self.remove_app(app, super_ucr)
290
		ucr_var = app.repository_ucr_var()
291
		if ucr_var:
292
			super_ucr.set_registry_var(ucr_var, '')
293
294
	def put_app_old_format(self, app, super_ucr=None):
295
		if super_ucr is None:
296
			with set_save_commit_load(self.ucr) as super_ucr:
297
				return self.put_app(app, super_ucr)
280
		app_data = {
298
		app_data = {
281
			'server' : app.get_server(),
299
			'server' : app.get_server(),
282
			'prefix' : '',
300
			'prefix' : '',
 Lines 296-307    Link Here 
296
			app_data['version'] = 'current'
314
			app_data['version'] = 'current'
297
		self.put(app_data, super_ucr)
315
		self.put(app_data, super_ucr)
298
316
299
	def remove_app(self, app, super_ucr=None):
317
	def remove_app_old_format(self, app, super_ucr):
300
		if super_ucr is None:
318
		if super_ucr is None:
301
			with set_save_commit_load(self.ucr) as super_ucr:
319
			with set_save_commit_load(self.ucr) as super_ucr:
302
				return self.remove_app(app, super_ucr)
320
				return self.remove_app(app, super_ucr)
303
		self._remove(app.component_id, super_ucr)
321
		self._remove(app.component_id, super_ucr)
304
322
323
	if _ucr.is_true('repository/app_center/new_format', True):
324
		put_app = put_app_new_format
325
		remove_app = remove_app_new_format
326
	else:
327
		put_app = put_app_old_format
328
		remove_app = remove_app_old_format
329
305
	def put(self, data, super_ucr):
330
	def put(self, data, super_ucr):
306
		"""	Does the real work of writing one component definition back.
331
		"""	Does the real work of writing one component definition back.
307
			Will be called for each element in the request array of
332
			Will be called for each element in the request array of
 Lines 360-365    Link Here 
360
		self.put({'name' : component_id, 'version' : ''}, super_ucr)
385
		self.put({'name' : component_id, 'version' : ''}, super_ucr)
361
		return super_ucr.changed()
386
		return super_ucr.changed()
362
387
388
	def enable_app(self, app, super_ucr=None):
389
		if super_ucr is None:
390
			with set_save_commit_load(self.ucr) as super_ucr:
391
				return self.enable_app(app, super_ucr)
392
		if self.ucr.is_true('repository/app_center/new_format', True):
393
			ucr_var = app.repository_ucr_var()
394
			if ucr_var:
395
				super_ucr.set_registry_var(ucr_var, 'enabled')
396
		else:
397
			self.currentify(app.component_id, super_ucr)
398
		return super_ucr.changed()
399
400
	def disable_app(self, app, super_ucr=None):
401
		if super_ucr is None:
402
			with set_save_commit_load(self.ucr) as super_ucr:
403
				return self.disable_app(app, super_ucr)
404
		if self.ucr.is_true('repository/app_center/new_format', True):
405
			ucr_var = app.repository_ucr_var()
406
			if ucr_var:
407
				super_ucr.set_registry_var(ucr_var, 'disabled')
408
		else:
409
			self.uncurrentify(app.component_id, super_ucr)
410
		return super_ucr.changed()
411
363
	def _remove(self, component_id, super_ucr):
412
	def _remove(self, component_id, super_ucr):
364
		named_component_base = '%s/%s' % (COMPONENT_BASE, component_id)
413
		named_component_base = '%s/%s' % (COMPONENT_BASE, component_id)
365
		for var in COMP_PARAMS:
414
		for var in COMP_PARAMS:
(-)umc/python/appcenter/app_center.py (-11 / +37 lines)
 Lines 515-524    Link Here 
515
		)
515
		)
516
516
517
	@classmethod
517
	@classmethod
518
	def find(cls, application_id):
518
	def find(cls, application_id=None, component=None):
519
		for application in cls.all():
519
		for application in cls.all():
520
			if application.id == application_id:
520
			if component is None:
521
				return application
521
				if application.id == application_id:
522
					return application
523
			else:
524
				for version in application.versions:
525
					if application.component_id == component:
526
						return version
522
527
523
	@classmethod
528
	@classmethod
524
	def _get_category_translations(cls, fake=False):
529
	def _get_category_translations(cls, fake=False):
 Lines 654-660    Link Here 
654
				shutil.copymode(template_png, png_16)
659
				shutil.copymode(template_png, png_16)
655
660
656
	@classmethod
661
	@classmethod
657
	def all_installed(cls, package_manager, force_reread=False, only_local=False, localize=True):
662
	def all_installed(cls, package_manager, force_reread=False, only_local=False, localize=None):
658
		ret = []
663
		ret = []
659
		for app in cls.all(force_reread=force_reread, only_local=only_local, localize=localize):
664
		for app in cls.all(force_reread=force_reread, only_local=only_local, localize=localize):
660
			if app.allowed_on_local_server() and app.is_installed(package_manager, strict=False):
665
			if app.allowed_on_local_server() and app.is_installed(package_manager, strict=False):
 Lines 662-672    Link Here 
662
		return ret
667
		return ret
663
668
664
	@classmethod
669
	@classmethod
665
	def all(cls, force_reread=False, only_local=False, localize=True):
670
	def all(cls, force_reread=False, only_local=False, localize=None):
666
		# reload ucr variables
671
		# reload ucr variables
667
		ucr.load()
672
		ucr.load()
668
673
669
		# load the first time the category translations
674
		# load the first time the category translations
675
		if localize is None:
676
			localize = not only_local
670
		cls._get_category_translations(fake=not localize)
677
		cls._get_category_translations(fake=not localize)
671
678
672
		if force_reread:
679
		if force_reread:
 Lines 743-766    Link Here 
743
	def is_registered(self, ucr):
750
	def is_registered(self, ucr):
744
		if self.get('withoutrepository'):
751
		if self.get('withoutrepository'):
745
			return True
752
			return True
746
		return component_registered(self.component_id, ucr)
753
		if ucr.is_true('repository/app_center/new_format', True):
754
			return self.repository_ucr_var() in ucr
755
		else:
756
			return component_registered(self.component_id, ucr)
747
757
748
	def is_current(self, ucr):
758
	def is_current(self, ucr):
749
		if self.get('withoutrepository'):
759
		if self.get('withoutrepository'):
750
			return True
760
			return True
751
		return component_current(self.component_id, ucr)
761
		if ucr.is_true('repository/app_center/new_format', True):
762
			return ucr.get(self.repository_ucr_var()) == 'enabled'
763
		else:
764
			return component_current(self.component_id, ucr)
752
765
753
	def disable_component(self, component_manager):
766
	def disable_component(self, component_manager):
754
		if self.get('withoutrepository'):
767
		if self.get('withoutrepository'):
755
			return
768
			return
756
		with set_save_commit_load(component_manager.ucr) as super_ucr:
769
		return component_manager.disable_app(self)
757
			return component_manager.uncurrentify(self.component_id, super_ucr)
758
770
759
	def enable_component(self, component_manager):
771
	def enable_component(self, component_manager):
760
		if self.get('withoutrepository'):
772
		if self.get('withoutrepository'):
761
			return
773
			return
762
		with set_save_commit_load(component_manager.ucr) as super_ucr:
774
		return component_manager.enable_app(self)
763
			return component_manager.currentify(self.component_id, super_ucr)
764
775
765
	def allowed_on_local_server(self):
776
	def allowed_on_local_server(self):
766
		server_role = ucr.get('server/role')
777
		server_role = ucr.get('server/role')
 Lines 795-800    Link Here 
795
		res['fully_loaded'] = True
806
		res['fully_loaded'] = True
796
		return res
807
		return res
797
808
809
	def repository_ucr_var(self):
810
		if self.get('withoutrepository'):
811
			return None
812
		return 'repository/app_center/apps/%s' % self.component_id
813
814
	def debian_repository(self, arch):
815
		if arch is False:
816
			arch = 'all'
817
		if arch is True:
818
			arch = '$(ARCH)'
819
		server = self.get_server()
820
		version = self.get_ucs_version()
821
		repo_name = self.component_id
822
		return 'deb http://%s/univention-repository/%s/maintained/component/ %s/%s/' % (server, version, repo_name, arch)
823
798
	def __repr__(self):
824
	def __repr__(self):
799
		return '<Application id="%s" name="%s (%s)" component="%s">' % (self.id, self.name, self.version, self.component_id)
825
		return '<Application id="%s" name="%s (%s)" component="%s">' % (self.id, self.name, self.version, self.component_id)
800
826

Return to bug 34989