# -*- coding: utf-8 -*-
##################################################
# This file is part of WAPT Enterprise
# All right reserved, (c) Tranquil IT Systems 2023
# For more information please refer to
# https://wapt.tranquil.it/store/licences.html
##################################################
from setuphelpers import *


bin_path = makepath("/", "usr", "local", "bin")


def install():
    # unzipping bin to /usr/bin
    bin_name = glob.glob("*macos-x86_64.tar.gz")[0]
    run(f"tar -xzvf {bin_name}")
    print(f"copying nvim-macos-x86_64 to {bin_path}")
    copytree2("nvim-macos-x86_64", bin_path)
    

    # Creation symlink
    symlink_path = f"{bin_path}/nv"
    if isfile(symlink_path) or os.path.islink(symlink_path):
        print("Symlink already exists, removing it")
        os.remove(symlink_path)
    print("create nv alias in path")
    os.symlink(f"{bin_path}/nv", symlink_path)


def uninstall():
    if isdir(f"{bin_path}/nvim-macos-x86_64"):
        remove_tree(f"{bin_path}/nvim-macos-x86_64")
    if isfile(f"{bin_path}/nv"):
        remove_file(f"{bin_path}/nv")
