Skip to content

Commit

Permalink
auto-update feature improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
adangert committed May 4, 2019
1 parent ddba911 commit bcf6676
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.python_history
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
Binary file added audio/Menu/joustmania_failed.wav
Binary file not shown.
1 change: 1 addition & 0 deletions piparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ def check_update(self):
if move_opt[Opts.selection.value] == Selections.update.value:
if self.big_update:
update.big_update()
self.big_update = False

def game_loop(self):
self.play_menu_music = True
Expand Down
20 changes: 17 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/bin/bash
#test

setup() {
# Prevent apt from prompting us about restarting services.
export DEBIAN_FRONTEND=noninteractive

sudo apt-get install -y espeak

espeak "starting software upgrade"
#update OS
sudo cp -v conf/sources.list /etc/apt/sources.list || exit -1
sudo cp -v conf/apt.conf /etc/apt/apt.conf.d/10joustmania-conf || exit -1
sudo apt-get update -y || exit -1
sudo apt-get upgrade -y || exit -1
sudo apt-get dist-upgrade -y || exit -1
cd /home/pi

espeak "Installing Joustmania software updates"
#TODO: remove pyaudio and dependencies
#install components
sudo apt-get install -y \
Expand All @@ -26,6 +29,7 @@ setup() {
alsa-utils alsa-tools libasound2-dev \
python-dbus-dev libdbus-glib-1-dev espeak || exit -1

espeak "starting PS move A.P.I. software updates"
#install components for psmoveapi
sudo apt-get install -y \
build-essential \
Expand All @@ -35,7 +39,7 @@ setup() {




espeak "starting Joustmania software updates"
VENV=/home/pi/JoustMania/venv
# We install nearly all python deps in the virtualenv to avoid concflicts with system, except
# numpy and scipy because they take forever to build.
Expand All @@ -45,17 +49,21 @@ setup() {
sudo apt-get install -y python3-dev || exit -1
sudo python3 -m pip install --upgrade virtualenv || exit -1

espeak "installing virtual environment"
# Rebuilding this is pretty cheap, so just do it every time.
rm -rf $VENV
/usr/bin/python3 -m virtualenv --system-site-packages $VENV || exit -1
PYTHON=$VENV/bin/python3
espeak "installing virtual environment software"
$PYTHON -m pip install --ignore-installed psutil flask Flask-WTF pyalsaaudio pydub pygame pyaudio pyyaml dbus-python || exit -1

espeak "downloading PS move API"
#install psmoveapi
rm -rf psmoveapi
git clone --recursive git://github.com/thp/psmoveapi.git
cd psmoveapi

espeak "making PS move API components"
mkdir build
cd build
# we definitely don't need java, opengj, csharp, etc
Expand All @@ -82,6 +90,12 @@ setup() {
#Use amixer to set sound output to 100%
amixer sset PCM,0 100%
sudo alsactl store


#This will disable on-board bluetooth
#This will allow only class one long range btdongles to connect to psmove controllers
sudo grep -qxF 'dtoverlay=pi3-disable-bt' /boot/config.txt || echo "dtoverlay=pi3-disable-bt" | sudo tee -a /boot/config.txt
sudo systemctl disable hciuart || exit -1

# Pause a second before rebooting so we can see all the output from this script.
(sleep 1; sudo reboot) &
Expand Down
27 changes: 19 additions & 8 deletions update.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import subprocess
from piaudio import Audio, InitAudio

import time
import shlex

if __name__ == "__main__":
InitAudio()
check_for_update()

def run_command(command):
process = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE)
process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
outout = ""
while True:

Expand All @@ -21,24 +23,33 @@ def run_command(command):

def big_update():
Audio('audio/Menu/update_started.wav').start_effect_and_wait()
run_command("git pull")
current_hash = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git rev-parse HEAD'").strip()
run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git checkout master'")
run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git pull'")
run_command("sudo /home/pi/JoustMania/setup.sh")
Audio('audio/Menu/joustmania_updated.wav').start_effect_and_wait()
#it failed if it got this far
time.sleep(3)
run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git checkout {}'".format(current_hash))
Audio('audio/Menu/joustmania_failed.wav').start_effect_and_wait()

def tester():
current_hash = run_command("sudo runuser -l pi -c 'git rev-parse HEAD'").strip()
print(current_hash)

def check_for_update():
process = run_command("git fetch")
diff_files = run_command("git diff origin/master --name-only").split()
process = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;pwd'")
process = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git fetch'")
diff_files = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git diff origin/master --name-only'").split()
print(diff_files)


if('setup.sh' in diff_files):
print('big updtae available')
Audio('audio/Menu/large_update.wav').start_effect_and_wait()
return True

elif (len(diff_files) >= 1):
print("doing small pull")
pull = run_command("git pull")
pull = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git pull'")
Audio('audio/Menu/joustmania_updated.wav').start_effect_and_wait()
return False

Expand Down

0 comments on commit bcf6676

Please sign in to comment.