# -*- coding: utf-8 -*-
from setuphelpers import *

r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()

"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls


def install():

    # Uninstalling older version of the software that can remains
    for to_uninstall in installed_softwares(name="Duplicati"):
      if Version(to_uninstall["version"]) < Version(control.get_software_version()):
        print(f"Removing: {to_uninstall['name']} ({to_uninstall['version']})")
        killalltasks(ensure_list(control.impacted_process))
        run(uninstall_cmd(to_uninstall["key"]))
        wait_uninstallkey_absent(to_uninstall["key"])
        
    # Declaring local variables
    bin_name = glob.glob('duplicati-*-win-x86-gui.msi')[0]
    # Installing the software
    install_msi_if_needed(bin_name)



