Skip to content

Commit

Permalink
Refactor installer
Browse files Browse the repository at this point in the history
- Make RobotpyInstaller object able to do all the things for future
  extensions
- Store team number in .wpilib/wpilib_preferences.json for vscode compat
- Remove CLI command, use robotpy entry point instead
  • Loading branch information
virtuald committed Jan 6, 2024
1 parent 4290aa3 commit 8d22670
Show file tree
Hide file tree
Showing 11 changed files with 914 additions and 658 deletions.
4 changes: 0 additions & 4 deletions robotpy_installer/__main__.py

This file was deleted.

38 changes: 15 additions & 23 deletions robotpy_installer/cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from os.path import join, splitext

from . import sshcontroller
from .utils import print_err, yesno
from .utils import handle_cli_error, print_err, yesno

import logging

Expand Down Expand Up @@ -107,6 +107,7 @@ def __init__(self, parser: argparse.ArgumentParser):
help="If specified, don't do a DNS lookup, allow ssh et al to do it instead",
)

@handle_cli_error
def run(
self,
main_file: pathlib.Path,
Expand Down Expand Up @@ -158,32 +159,23 @@ def run(
# upload all files in the robot.py source directory

robot_filename = main_file.name
cfg_filename = project_path / ".deploy_cfg"

if not large and not self._check_large_files(project_path):
return 1

hostname_or_team = robot or team

try:
with sshcontroller.ssh_from_cfg(
cfg_filename,
username="lvuser",
password="",
hostname=hostname_or_team,
no_resolve=no_resolve,
) as ssh:
if not self._check_requirements(ssh, no_version_check):
return 1

if not self._do_deploy(
ssh, debug, nc, nc_ds, robot_filename, project_path
):
return 1

except sshcontroller.SshExecError as e:
print_err("ERROR:", str(e))
return 1
with sshcontroller.ssh_from_cfg(
project_path,
main_file,
username="lvuser",
password="",
robot_or_team=robot or team,
no_resolve=no_resolve,
) as ssh:
if not self._check_requirements(ssh, no_version_check):
return 1

if not self._do_deploy(ssh, debug, nc, nc_ds, robot_filename, project_path):
return 1

print("\nSUCCESS: Deploy was successful!")
return 0
Expand Down
53 changes: 24 additions & 29 deletions robotpy_installer/cli_deploy_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from . import sshcontroller

from .utils import handle_cli_error
from .utils import print_err


Expand All @@ -33,8 +34,10 @@ def __init__(self, parser: argparse.ArgumentParser):
help="If specified, don't do a DNS lookup, allow ssh et al to do it instead",
)

@handle_cli_error
def run(
self,
project_path: pathlib.Path,
main_file: pathlib.Path,
robot: typing.Optional[str],
team: typing.Optional[int],
Expand All @@ -47,34 +50,26 @@ def run(
)
return 1

cfg_filename = main_file.parent / ".deploy_cfg"

hostname_or_team = robot or team

try:
with sshcontroller.ssh_from_cfg(
cfg_filename,
username="lvuser",
password="",
hostname=hostname_or_team,
no_resolve=no_resolve,
) as ssh:
result = ssh.exec_cmd(
(
"[ -f /home/lvuser/py/deploy.json ] && "
"cat /home/lvuser/py/deploy.json || "
"echo {}"
),
get_output=True,
)
if not result.stdout:
print("{}")
else:
data = json.loads(result.stdout)
print(json.dumps(data, indent=2, sort_keys=True))

except sshcontroller.SshExecError as e:
print_err("ERROR:", str(e))
return 1
with sshcontroller.ssh_from_cfg(
project_path,
main_file,
username="lvuser",
password="",
robot_or_team=robot or team,
no_resolve=no_resolve,
) as ssh:
result = ssh.exec_cmd(
(
"[ -f /home/lvuser/py/deploy.json ] && "
"cat /home/lvuser/py/deploy.json || "
"echo {}"
),
get_output=True,
)
if not result.stdout:
print("{}")
else:
data = json.loads(result.stdout)
print(json.dumps(data, indent=2, sort_keys=True))

return 0
Loading

0 comments on commit 8d22670

Please sign in to comment.