bind: Bump version and handle upgrade

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
James Valleroy 2020-02-15 09:32:46 -05:00
parent 3f0642109c
commit c78d96984b
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 12 additions and 7 deletions

View File

@ -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)

View File

@ -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)