Skip to content

Instantly share code, notes, and snippets.

@pelson
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelson/a9e8b25496309fa2997d to your computer and use it in GitHub Desktop.
Save pelson/a9e8b25496309fa2997d to your computer and use it in GitHub Desktop.
Allows control the travis-ci machine via a text file, as a poor-man's keyboard.
Allows control the travis-ci machine via a text file, as a poor-man's keyboard.
Note: This is only a hacky example when I got frustrated by the queue time for travis-ci builds.
Run with the URL of the command file as the only argument:
python listen_and_execute.py https://gist.githubusercontent.com/pelson/a9e8b25496309fa2997d/raw/commands.txt
# sudo apt-get install g++-3.4 --force-yes
gcc -v
#exit
locate gcc
#ls /usr/local/bin
ls /usr/bin/*gcc*
/usr/bin/gcc-3.4 -v
/usr/bin/g++-3.4 -v
sudo rm /usr/bin/gcc
sudo rm /usr/bin/g++
sudo ln -s /usr/bin/gcc-3.4 /usr/bin/gcc
sudo ln -s /usr/bin/g++-3.4 /usr/bin/g++
g++ --version
#export CC=gcc-3.4
sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
exit
import os
import urllib2
import time
def listen_and_execute(url, max_iterations=60, sleep_time=10):
last_contents = ''
for i in xrange(max_iterations):
response = urllib2.urlopen(url)
contents = response.read().strip()
if last_contents != contents:
for command in contents.split('\n'):
if command == 'exit':
print 'Exiting.'
exit()
print 'Executing {}'.format(command)
os.system(command)
last_contents = contents
time.sleep(sleep_time)
if __name__ == '__main__':
import sys
url = sys.argv[1]
listen_and_execute(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment