Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from .. import config
config.mode = "upload"
# run the test suite before uploading
# TODO: disabled for 2020
if False and not options.skip_tests:
from .cli_test import PyFrcTest
tester = PyFrcTest()
retval = tester.run_test(
[], robot_class, options.builtin, ignore_missing_test=True
)
if retval != 0:
print_err("ERROR: Your robot tests failed, aborting upload.")
if not sys.stdin.isatty():
print_err("- Use --skip-tests if you want to upload anyways")
return retval
print()
if not yesno("- Upload anyways?"):
return retval
if not yesno("- Are you sure? Your robot code may crash!"):
return retval
print()
print("WARNING: Uploading code against my better judgement...")
# upload all files in the robot.py source directory
robot_file = abspath(inspect.getfile(robot_class))
config.mode = "upload"
# run the test suite before uploading
# TODO: disabled for 2020
if False and not options.skip_tests:
from .cli_test import PyFrcTest
tester = PyFrcTest()
retval = tester.run_test(
[], robot_class, options.builtin, ignore_missing_test=True
)
if retval != 0:
print_err("ERROR: Your robot tests failed, aborting upload.")
if not sys.stdin.isatty():
print_err("- Use --skip-tests if you want to upload anyways")
return retval
print()
if not yesno("- Upload anyways?"):
return retval
if not yesno("- Are you sure? Your robot code may crash!"):
return retval
print()
print("WARNING: Uploading code against my better judgement...")
# upload all files in the robot.py source directory
robot_file = abspath(inspect.getfile(robot_class))
robot_path = dirname(robot_file)
robot_filename = basename(robot_file)
controller.ssh_exec_commands(sshcmd, True)
except sshcontroller.SshExecError as e:
doret = True
if e.retval == 87:
print_err(
"ERROR: python3 was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 88:
print_err(
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
elif e.retval == 91:
# Not an error; ssh in as admin and fix the startup dlls (Saves 24M of RAM)
# -> https://github.com/wpilibsuite/EclipsePlugins/pull/154
logger.info("Fixing StartupDLLs to save RAM...")
controller.username = "admin"
controller.ssh_exec_commands(
'sed -i -e "s/^StartupDLLs/;StartupDLLs/" /etc/natinst/share/ni-rt.ini',
print()
print("WARNING: Uploading code against my better judgement...")
# upload all files in the robot.py source directory
robot_file = abspath(inspect.getfile(robot_class))
robot_path = dirname(robot_file)
robot_filename = basename(robot_file)
cfg_filename = join(robot_path, ".deploy_cfg")
if not options.nonstandard and robot_filename != "robot.py":
print_err(
"ERROR: Your robot code must be in a file called robot.py (launched from %s)!"
% robot_filename
)
print_err()
print_err(
"If you really want to do this, then specify the --nonstandard argument"
)
return 1
# This probably should be configurable... oh well
deploy_dir = PurePosixPath("/home/lvuser")
py_deploy_subdir = "py"
py_new_deploy_subdir = "py_new"
py_deploy_dir = deploy_dir / py_deploy_subdir
# note below: deployed_cmd appears that it only can be a single line
# In 2015, there were stdout/stderr issues. In 2016, they seem to
# have been fixed, but need to use -u for it to really work properly
)
controller.ssh_connect()
try:
# Housekeeping first
logger.debug("SSH: %s", sshcmd)
controller.ssh_exec_commands(sshcmd, True)
except sshcontroller.SshExecError as e:
doret = True
if e.retval == 87:
print_err(
"ERROR: python3 was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 88:
print_err(
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
if e.retval == 87:
print_err(
"ERROR: python3 was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 88:
print_err(
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
elif e.retval == 91:
# Not an error; ssh in as admin and fix the startup dlls (Saves 24M of RAM)
# -> https://github.com/wpilibsuite/EclipsePlugins/pull/154
logger.info("Fixing StartupDLLs to save RAM...")
controller.username = "admin"
controller.ssh_exec_commands(
'sed -i -e "s/^StartupDLLs/;StartupDLLs/" /etc/natinst/share/ni-rt.ini',
True,
)
"ERROR: python3 was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 88:
print_err(
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
elif e.retval == 91:
# Not an error; ssh in as admin and fix the startup dlls (Saves 24M of RAM)
# -> https://github.com/wpilibsuite/EclipsePlugins/pull/154
logger.info("Fixing StartupDLLs to save RAM...")
controller.username = "admin"
controller.ssh_exec_commands(
'sed -i -e "s/^StartupDLLs/;StartupDLLs/" /etc/natinst/share/ni-rt.ini',
True,
)
controller.username = "lvuser"
doret = False
logger.debug("SSH: %s", sshcmd)
controller.ssh_exec_commands(sshcmd, True)
except sshcontroller.SshExecError as e:
doret = True
if e.retval == 87:
print_err(
"ERROR: python3 was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 88:
print_err(
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
elif e.retval == 91:
# Not an error; ssh in as admin and fix the startup dlls (Saves 24M of RAM)
# -> https://github.com/wpilibsuite/EclipsePlugins/pull/154
logger.info("Fixing StartupDLLs to save RAM...")
controller.username = "admin"
controller.ssh_exec_commands(
try:
# Housekeeping first
logger.debug("SSH: %s", sshcmd)
controller.ssh_exec_commands(sshcmd, True)
except sshcontroller.SshExecError as e:
doret = True
if e.retval == 87:
print_err(
"ERROR: python3 was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 88:
print_err(
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
elif e.retval == 91:
# Not an error; ssh in as admin and fix the startup dlls (Saves 24M of RAM)
# -> https://github.com/wpilibsuite/EclipsePlugins/pull/154
logger.info("Fixing StartupDLLs to save RAM...")
"ERROR: WPILib was not found on the roboRIO: have you installed robotpy?"
)
elif e.retval == 89:
print_err("ERROR: expected WPILib version %s" % wpilib.__version__)
print_err()
print_err("You should either:")
print_err(
"- If the robot version is older, upgrade the RobotPy on your robot"
)
print_err("- Otherwise, upgrade pyfrc on your computer")
print_err()
print_err(
"Alternatively, you can specify --no-version-check to skip this check"
)
elif e.retval == 90:
print_err("ERROR: error running compileall")
elif e.retval == 91:
# Not an error; ssh in as admin and fix the startup dlls (Saves 24M of RAM)
# -> https://github.com/wpilibsuite/EclipsePlugins/pull/154
logger.info("Fixing StartupDLLs to save RAM...")
controller.username = "admin"
controller.ssh_exec_commands(
'sed -i -e "s/^StartupDLLs/;StartupDLLs/" /etc/natinst/share/ni-rt.ini',
True,
)
controller.username = "lvuser"
doret = False
else:
print_err("ERROR: %s" % e)
if doret: