From c78d96984ba32875891a36ea6e39eb4873f2384d Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 15 Feb 2020 09:32:46 -0500 Subject: [PATCH] bind: Bump version and handle upgrade Signed-off-by: James Valleroy --- actions/bind | 13 ++++++++----- plinth/modules/bind/__init__.py | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/actions/bind b/actions/bind index b4020a79d..e445c9f10 100755 --- a/actions/bind +++ b/actions/bind @@ -31,7 +31,10 @@ def parse_arguments(): """Return parsed command line arguments as dictionary""" parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') - subparsers.add_parser('setup', help='Setup for BIND') + setup = subparsers.add_parser('setup', help='Setup for BIND') + setup.add_argument( + '--old-version', type=int, required=True, + help='Earlier version of the app that is already setup.') configure = subparsers.add_parser('configure', help='Configure BIND') configure.add_argument('--forwarders', @@ -43,11 +46,11 @@ def parse_arguments(): return parser.parse_args() -def subcommand_setup(_): +def subcommand_setup(arguments): """Setup BIND configuration.""" - conf_file = open(CONFIG_FILE, "w") - conf_file.write(DEFAULT_CONFIG) - conf_file.close() + if arguments.old_version == 0: + with open(CONFIG_FILE, "w") as conf_file: + conf_file.write(DEFAULT_CONFIG) Path(ZONES_DIR).mkdir(exist_ok=True, parents=True) diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index c6ae633b5..353fc27a3 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -34,7 +34,7 @@ from plinth.utils import format_lazy from .manifest import backup # noqa, pylint: disable=unused-import -version = 1 +version = 2 name = _('BIND') @@ -127,7 +127,9 @@ def init(): def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) - helper.call('post', actions.superuser_run, 'bind', ['setup']) + helper.call( + 'post', actions.superuser_run, 'bind', + ['setup', '--old-version', str(old_version)]) helper.call('post', app.enable)