Skip to content

Commit

Permalink
Add command to remove robotpy
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Jan 12, 2024
1 parent 2b1f3d7 commit 1cffef5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
11 changes: 1 addition & 10 deletions robotpy_installer/cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,7 @@ def _ensure_requirements(
if no_install:
requirements_installed = True
elif not force_install:
# Use importlib.metadata instead of pip because it's way faster than pip
result = ssh.exec_cmd(
"/usr/local/bin/python3 -c "
"'from importlib.metadata import distributions;"
"import json; import sys; "
"json.dump({dist.name: dist.version for dist in distributions()},sys.stdout)'",
get_output=True,
)
assert result.stdout is not None
pkgdata = json.loads(result.stdout)
pkgdata = roborio_utils.get_rio_py_packages(ssh)

logger.debug("Roborio has these packages installed:")
for pkg, version in pkgdata.items():
Expand Down
34 changes: 34 additions & 0 deletions robotpy_installer/cli_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,39 @@ def run(
installer.uninstall_python()


class InstallerUninstallRobotPy:
"""
Uninstall RobotPy and user programs from a RoboRIO
"""

def __init__(self, parser: argparse.ArgumentParser) -> None:
_add_ssh_options(parser)
parser.add_argument("-y", "--yes", action="store_true", default=False)

@handle_cli_error
def run(
self,
project_path: pathlib.Path,
main_file: pathlib.Path,
ignore_image_version: bool,
robot: typing.Optional[str],
yes: bool,
):
if not yes and not yesno(
"This will delete all python and user data! Continue?"
):
return

installer = RobotpyInstaller()
with installer.connect_to_robot(
project_path=project_path,
main_file=main_file,
robot_or_team=robot,
ignore_image_version=ignore_image_version,
):
installer.uninstall_robotpy()


class InstallerUninstallJavaCpp:
"""
Uninstall FRC Java/C++ programs from a RoboRIO
Expand Down Expand Up @@ -375,5 +408,6 @@ class Installer:
("list", InstallerList),
("uninstall", InstallerUninstall),
("uninstall-python", InstallerUninstallPython),
("uninstall-robotpy", InstallerUninstallRobotPy),
("uninstall-frc-java-cpp", InstallerUninstallJavaCpp),
]
15 changes: 15 additions & 0 deletions robotpy_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from os.path import basename

from .version import version as __version__
from . import roborio_utils
from .cacheserver import CacheServer
from .errors import Error, SshExecError
from .sshcontroller import SshController, ssh_from_cfg
Expand Down Expand Up @@ -412,6 +413,20 @@ def uninstall_python(
print_output=True,
)

def uninstall_robotpy(self):
with catch_ssh_error("removing user program"):
self.ssh.exec_bash(
roborio_utils.kill_robot_cmd,
"rm -rf /home/lvuser/py",
f"rm -f {roborio_utils.robot_command}",
)

with catch_ssh_error("removing pip packages"):
pkgs = roborio_utils.get_rio_py_packages(self.ssh)
self.pip_uninstall([pkg for pkg in pkgs.keys() if pkg != "pip"])

self.uninstall_python()

#
# pip packages
#
Expand Down
15 changes: 15 additions & 0 deletions robotpy_installer/roborio_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import logging
import typing

from .sshcontroller import SshController

Expand Down Expand Up @@ -67,3 +69,16 @@ def uninstall_cpp_java_admin(ssh: SshController):
print_output=True,
check=True,
)


def get_rio_py_packages(ssh: SshController) -> typing.Dict[str, str]:
# Use importlib.metadata instead of pip because it's way faster than pip
result = ssh.exec_cmd(
"/usr/local/bin/python3 -c "
"'from importlib.metadata import distributions;"
"import json; import sys; "
"json.dump({dist.name: dist.version for dist in distributions()},sys.stdout)'",
get_output=True,
)
assert result.stdout is not None
return json.loads(result.stdout)

0 comments on commit 1cffef5

Please sign in to comment.