diff --git a/src/install.py b/src/install.py index 3b883dd..aadcf01 100644 --- a/src/install.py +++ b/src/install.py @@ -6,21 +6,16 @@ import tarfile from rich.console import Console from rich.progress import SpinnerColumn +from util import check_ground_libs_path, check_sudo console = Console() def install(args): - # check if we are sudo - if os.getuid() != 0: - console.print("[b red]digpkg: the install command requires sudo to run[/]") - sys.exit(1) - # ensure the GROUND_LIBS var is set - if not os.getenv("GROUND_LIBS"): - console.print("digpkg: the [i]GROUND_LIBS[/] environment variable is not set, defaulting to /usr/lib/ground/") - os.environ["GROUND_LIBS"] = "/usr/lib/ground/" + check_sudo() + check_ground_libs_path() # figure out which version to install package_name = args.name @@ -81,5 +76,10 @@ def install(args): console.print(f"[d][:white_check_mark:] Extracted to {extract_dir}.") console.status("Finishing up...") - os.symlink(os.path.join(extract_dir, package_name, "main.so"), os.path.join(extract_dir, f"{package_name}.so")) + + # create a symlink from the main.so file to the ground libs folder so ground can find it + symlink_path = os.path.join(extract_dir, f"{package_name}.so") # the path where the symlink is + if not os.path.isfile(symlink_path): + os.symlink(os.path.join(extract_dir, package_name, "main.so"), symlink_path) + console.print("[:white_check_mark:] Done!") \ No newline at end of file diff --git a/src/list.py b/src/list.py index 9f401f9..ff2a90c 100644 --- a/src/list.py +++ b/src/list.py @@ -3,9 +3,13 @@ import configparser from rich import print from rich.table import Table +from util import check_ground_libs_path + def list_cmd(args): - ground_libs_folder = os.getenv("GROUND_LIBS") or "/usr/lib/ground/" + check_ground_libs_path() + + ground_libs_folder = os.getenv("GROUND_LIBS") folders = os.listdir(ground_libs_folder) table = Table("Name", "Version", "Description", title="Installed") diff --git a/src/main.py b/src/main.py index b5990a3..e537b8d 100644 --- a/src/main.py +++ b/src/main.py @@ -5,6 +5,7 @@ from install import install from publish import publish from remove import remove from list import list_cmd +from uninstall import uninstall def parse_arguments(): @@ -23,7 +24,6 @@ def parse_arguments(): # list command list_command = sub_parsers.add_parser(name="list", description="list all minerals installed in the current environment") - list_command.add_argument("--env_name", help="list all minerals from a specific environment.", default=None, required=False) # publish command publish_command = sub_parsers.add_parser(name="publish", description="publish a package to the repository") @@ -66,6 +66,8 @@ def parse_arguments(): remove(args) elif args.command == "list": list_cmd(args) + elif args.command == "uninstall": + uninstall(args) def main(): parse_arguments() diff --git a/src/uninstall.py b/src/uninstall.py new file mode 100644 index 0000000..076c87a --- /dev/null +++ b/src/uninstall.py @@ -0,0 +1,36 @@ +import os, sys +import shutil + +from util import check_ground_libs_path, check_sudo +from rich.console import Console + + +console = Console() + + +def uninstall(args): + check_sudo() + check_ground_libs_path() + + with console.status(status=f"Looking for [i]{args.name}[/]...", spinner="bouncingBall", spinner_style="blue") as status: + mineral_path = os.path.join(os.getenv("GROUND_LIBS"), args.name) + symlink_path = os.path.join(os.getenv("GROUND_LIBS"), f"{args.name}.so") + + # check to make sure the mineral is installed + if not os.path.isdir(mineral_path): + console.print(f"[b red]digpkg: failed to uninstall [i]{args.name}[/]: mineral is not installed[/b red]") + sys.exit(1) + + # remove the symlink + status.update("Removing symlink...") + if os.path.islink(symlink_path): + os.unlink(symlink_path) + console.print(f"[d][:white_check_mark:] Removed symlink!") + + # delete the folder + shutil.rmtree(mineral_path) + console.print(f"[d][:white_check_mark:] Removed mineral folder!") + + + console.print(f"[:white_check_mark:] Done!") + \ No newline at end of file diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000..e78289d --- /dev/null +++ b/src/util.py @@ -0,0 +1,16 @@ +import os, sys + +from rich import print + + +def check_ground_libs_path(): + # ensure the GROUND_LIBS var is set + if not os.getenv("GROUND_LIBS"): + print("digpkg: the [i]GROUND_LIBS[/] environment variable is not set, defaulting to /usr/lib/ground/") + os.environ["GROUND_LIBS"] = "/usr/lib/ground/" + +def check_sudo(): + # check if we are sudo + if os.getuid() != 0: + print("[b red]digpkg: that command requires sudo to run[/]") + sys.exit(1) \ No newline at end of file