radicale: Handle migration from 1.x to 2.x

When radicale 2.x is available in testing, the migration can be
triggered by bumping the module's version.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2019-01-30 16:53:03 -05:00 committed by Sunil Mohan Adapa
parent 62b4f67a2e
commit 3941ec10fe
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 51 additions and 6 deletions

View File

@ -38,6 +38,7 @@ def parse_arguments():
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
subparsers.add_parser('setup', help='Setup Radicale configuration')
subparsers.add_parser('migrate', help='Migrate config to radicale 2.x')
subparsers.add_parser('enable', help='Enable Radicale service')
subparsers.add_parser('disable', help='Disable Radicale service')
configure = subparsers.add_parser('configure',
@ -74,6 +75,26 @@ def subcommand_setup(_):
subcommand_enable(None)
def subcommand_migrate(_):
"""Migrate config from radicale 1.x to 2.x."""
action_utils.webserver_disable('radicale-plinth')
aug = load_augeas()
# Revert the config to package's original.
aug.remove('/files' + DEFAULT_FILE + '/ENABLE_RADICALE')
aug.remove('/files' + CONFIG_FILE + '/server/hosts')
aug.remove('/files' + CONFIG_FILE + '/server/base_prefix')
aug.remove('/files' + CONFIG_FILE + '/well-known/caldav')
aug.remove('/files' + CONFIG_FILE + '/well-known/carddav')
aug.remove('/files' + CONFIG_FILE + '/auth/type')
current_version = radicale.get_package_version()
if current_version and current_version < radicale.VERSION_2:
aug.remove('/files' + CONFIG_FILE + '/rights/type')
aug.save()
def subcommand_configure(arguments):
"""Sets the radicale rights type to a particular value"""
current_version = radicale.get_package_version()
@ -122,8 +143,8 @@ def subcommand_disable(_):
def load_augeas():
"""Initialize Augeas."""
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
aug = augeas.Augeas(
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
# shell-script config file lens
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')

View File

@ -21,6 +21,7 @@ FreedomBox app for radicale.
import subprocess
from distutils.version import LooseVersion as LV
from apt.cache import Cache
import augeas
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
@ -84,8 +85,31 @@ def init():
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'radicale', ['setup'])
if old_version == 1:
# Check that radicale 2.x is available for install.
cache = Cache()
candidate = cache['radicale'].candidate
if candidate < '2':
raise RuntimeError('Radicale 2.x is not available to install.')
# Try to upgrade radicale 1.x to 2.x.
helper.call('pre', actions.superuser_run, 'radicale', ['migrate'])
helper.install(managed_packages)
# Check that radicale 2.x is installed.
current_version = get_package_version()
if not current_version:
raise RuntimeError(
'Could not determine installed version of radicale.')
elif current_version < VERSION_2:
raise RuntimeError('Could not install radicale 2.x.')
# Enable radicale.
helper.call('post', actions.superuser_run, 'radicale', ['setup'])
else:
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'radicale', ['setup'])
global service
if service is None:
service = service_module.Service(managed_services[0], name, ports=[
@ -162,8 +186,8 @@ def disable():
def load_augeas():
"""Prepares the augeas."""
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
aug = augeas.Augeas(
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
# INI file lens
aug.set('/augeas/load/Puppet/lens', 'Puppet.lns')