Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Python install script #64

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ If you find a bug you can fix, don't like how I did something, or want to add an

## Documentation
Check out the [wiki](https://github.com/pjreiniger/SnobotSim/wiki) for how to set up and use the simulator, or these [examples](https://github.com/pjreiniger/SnobotSimExamples) for how you might want to set things up.

## Automatic installation
Mac/Linux: Navigate to the root of your robot project, then run "curl https://raw.githubusercontent.com/pjreiniger/SnobotSim/master/install.py | python3 ".
158 changes: 56 additions & 102 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,120 +1,74 @@


buildscript {
repositories {
mavenLocal()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "http://raw.githubusercontent.com/pjreiniger/maven_repo/master/"
plugins {
//SnobotSim:
id "com.snobot.simulator.plugin.SnobotSimulatorPlugin" version "2019-0.2.0" apply false
id "java"
id "edu.wpi.first.GradleRIO" version "2019.2.1"
}

def ROBOT_MAIN_CLASS = "org.usfirst.frc5974.DeepSpace.Main"

// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project EmbeddedTools.
deploy {
targets {
roboRIO("roborio") {
// Team number is loaded either from the .wpilib/wpilib_preferences.json
// or from command line. If not found an exception will be thrown.
// You can use getTeamOrDefault(team) instead of getTeamNumber if you
// want to store a team number in this file.
team = frc.getTeamNumber()
}
}
dependencies {
classpath 'com.netflix.nebula:gradle-aggregate-javadocs-plugin:2.2.+'
artifacts {
frcJavaArtifact('frcJava') {
targets << "roborio"
// Debug can be overridden by command line, for use with VSCode
debug = frc.getDebugOrDefault(false)
}
// Built in artifact to deploy arbitrary files to the roboRIO.
fileTreeArtifact('frcStaticFileDeploy') {
// The directory below is the local directory to deploy
files = fileTree(dir: 'src/main/deploy')
// Deploy to RoboRIO target, into /home/lvuser/deploy
targets << "roborio"
directory = '/home/lvuser/deploy'
}
}
}

plugins {
id 'net.ltgt.errorprone' version '0.6' apply false
id 'edu.wpi.first.NativeUtils' version '2.1.2'
id 'edu.wpi.first.GradleJni' version '0.3.1' apply false
id "com.diffplug.gradle.spotless" version "3.10.0"
id 'com.gradle.build-scan' version '2.0.2'
id "com.github.spotbugs" version "1.6.4"
}
apply plugin: 'nebula-aggregate-javadocs'


ext.build_simulator_cpp = false
ext.build_simulator_java = true
//SnowbotSim:
apply plugin: com.snobot.simulator.plugin.SnobotSimulatorPlugin

/////////////////////////////////////////
// Specify WPI Versions

ext.allwpilibVersion = {
return '2019.3.1'
configurations {
snobotSimCompile
}

ext.getWpiUtilVersion = {
return allwpilibVersion()
}
ext.getNtCoreVersion = {
return allwpilibVersion()
}
ext.getCsCoreVersion = {
return allwpilibVersion()
}

ext.getWpilibOpencvVersion = {
return '3.2.0'
}
ext.getCtreVersion = {
return '5.12.0'
}
ext.getCtreSimVersion = {
return getCtreVersion() + "_V0_RC"
}
ext.getRevRoboticsVersion = {
return '1.1.8'
}
ext.getRevRoboticsSimVersion = {
return getRevRoboticsVersion() + "_V0"
}
ext.getNavxVersion = {
return '3.1.340'
}
ext.getWpiRepo = {
return "http://first.wpi.edu/FRC/roborio/maven/release/"
//return "http://first.wpi.edu/FRC/roborio/maven/development/"
}

ext.getNavxRepo = {
return 'http://www.kauailabs.com/maven2/'
}

ext.getCtreRepo = {
return 'http://devsite.ctr-electronics.com/maven/release/'
}

ext.getRevRepo = {
return 'http://www.revrobotics.com/content/sw/max/sdk/maven/'
}

ext.getCtreOverrideRepo = {
return "http://raw.githubusercontent.com/pjreiniger/maven_repo/master/"
}
// Set this to true to enable desktop support.
def includeDesktopSupport = false

// Maven central needed for JUnit
repositories {
mavenCentral()
mavenLocal()

maven { url getWpiRepo() }
maven { url getNavxRepo() }
maven { url getCtreRepo() }
maven { url getCtreOverrideRepo() }
}

/////////////////////////////////////////
ext {
SpotBugsTask = com.github.spotbugs.SpotBugsTask
}

// Publshing Information
ext.maven_publishing_path = "$rootDir/build/maven_repo/"
if(hasProperty('maven_repo'))
{
throw new GradleException("This isn't supported anymore")
}
// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 4.
dependencies {
compile wpi.deps.wpilib()
compile wpi.deps.vendor.java()
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
testCompile 'junit:junit:4.12'

ext.maven_version = "2019-1.1.0"
if(hasProperty('maven_version'))
{
ext.maven_version = maven_version
// SnobotSim
snobotSimCompile snobotSimJava()
}

wrapper {
gradleVersion = '5.0'
// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
// in order to make them all available at runtime. Also adding the manifest so WPILib
// knows where to look for our Robot Class.
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS)
}

77 changes: 77 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import subprocess
import time

def modifyScript(scriptFile):
scriptRead = open(scriptFile,"r")
scriptWrite = open(scriptFile+".tmp","w")
scriptList = scriptRead.readlines()
# print(scriptList)

if scriptList[0]=="//Configured for Snobot Sim\n":
print("Script already modified")
return None

scriptList.insert(0,"//Configured for Snobot Sim\n")
#Add to plugins block
for i in scriptList:
if i=="plugins {\n":
scriptList.insert(scriptList.index(i)+1,"//SnobotSim:\n id \"com.snobot.simulator.plugin.SnobotSimulatorPlugin\" version \"2019-0.2.0\" apply false\n")
break

#Apply plugin
deployBlock=False
bracketCount=0
counter=0
for i in scriptList:
counter=counter+1
if i=="deploy {\n":
deployBlock=True
if deployBlock and "{" in i:
bracketCount=bracketCount+1
if deployBlock and "}" in i:
bracketCount=bracketCount-1
if deployBlock and bracketCount==0:
deployBlock=False
scriptList.insert(counter+1,"\n//SnowbotSim:\napply plugin: com.snobot.simulator.plugin.SnobotSimulatorPlugin\n\nconfigurations {\n snobotSimCompile\n}\n\n")

#Update dependencies
counter=0
dependenciesBlock = False
for i in scriptList:
counter=counter+1
if i=="dependencies {\n":
dependenciesBlock=True
if dependenciesBlock and "}" in i:
scriptList.insert(counter-1,"\n // SnobotSim\n snobotSimCompile snobotSimJava()\n")
break

scriptWrite.write(''.join(scriptList))
subprocess.call(["mv",scriptFile,scriptFile+".bak"])
subprocess.call(["mv",scriptFile+".tmp",scriptFile])
print("Script modified successfully")

def executeGradle():
subprocess.call(["./gradlew","downloadAll"])
subprocess.call(["./gradlew","runJavaSnobotSim"])

def robotPath():
path = input("What is the name of your robot class? (e.g. org.usfirst.frc.project.Robot) ")
configFile = open("simulator_config/simulator_config.properties","r")
configWrite = open("simulator_config/s","w")
configList = configFile.readlines()
print(configList)
for i in configList:
if "robot_class" in i:
configList[configList.index(i)]="robot_class="+path
configWrite.write(''.join(configList))
subprocess.call(["rm","simulator_config/simulator_config.properties"])
subprocess.call(["mv","simulator_config/s","simulator_config/simulator_config.properties"])
print("Robot class updated successfully")

modifyScript("build.gradle")
executeGradle()
time.sleep(1)
robotPath()
print("Success!")
print("Run ./gradlew runJavaSnobotSim to run the simulator.")