Commit 333f5b1c authored by Nelso Jost's avatar Nelso Jost

NEW: adopted ctautils/depman dependecy manager

parent a8829692
# encoding: utf-8
from __future__ import print_function, division
try:
input = raw_input
except NameError:
pass
'''
Author: Nelso G. Jost (nelsojost@gmail.com)
Licence: GPLv3
Version: 0.0.1
Purpose: Tired of the recurrent dependencies hell? This script provides a
fairly simple but useful mechanism of checking and installing debian,
python and general system dependencies.
The idea is to define all your linux dependencies here, along with
their check and install commands. Then you can add the following
rule on your project's Makefile:
setup:
@ python .deps.py
Additionally, if you want to perform dependency checking before any
important task, say a 'run' target, just execute 'setup' before it:
run: setup
@ python run.py # or whatever your 'run' target code is
This script handle three kinds of dependencies:
* Debian: Check if any of the listed commands exists. If at least
one fails, then apt-get update and install'em.
* Python3: Check if any of the listed libs can be imported. If at
least one fails, then get/update pip3 and install'em.
* General: Those who do not fall on any of the former categories.
Execute check code and if fail, the install code.
'''
# =============================================================================
# setup your dependecies here:
#
DEPENDENCIES =\
{
# apt-get installable packages. Format: '<package>@<shell_command>'
#
'debian': ['dialog@dialog', 'curl@curl'],
# python's pip3 installable packages. Format: '<package>@<import_name>'
#
'pip3': ['pyserial@serial'],
# dependencies that cannot be handled by the former specs
#
'general': [
# specify a dependency with the following dict format:
# {
# 'name': str with a name to be printed,
# 'check': str with shell command for testing existence
# 'install': str with shell command for installing
# }
{
'name': 'python3-pygame',
'check': 'python3 -c "import pygame"',
'install': '''\
sudo apt-get update &&
sudo apt-get install python3-dev \
python3-numpy libsdl-dev libsdl-image1.2-dev libsdl-mixer1.2-dev \
libsdl-ttf2.0-dev libsmpeg-dev libportmidi-dev libavformat-dev \
libswscale-dev libjpeg-dev libfreetype6-dev mercurial &&
rm -rf pygame &&
hg clone https://bitbucket.org/pygame/pygame &&
cd pygame && python3 setup.py build &&
sudo python3 setup.py install && cd .. && rm -rf pygame
'''
},
{
'name': 'paigamu',
'check': 'python3 -c "import paigamu"',
'install': '''\
rm -rf paigamu paigamu.git paigamu.zip && \
wget -O paigamu.zip https://git.cta.if.ufrgs.br/ctautils/paigamu/repository/archive.zip && \
unzip paigamu.zip && \
cp -rf paigamu.git/paigamu . && \
rm -rf paigamu.git paigamu.zip
'''
},
{
'name': 'platformiowizard',
'check': '[ -f firmware/.scripts/platformio_wizard.py ]',
'install': 'cd firmware && python -c "$(wget -O- https://git.cta.if.ufrgs.br/ctautils/platformiowizard/raw/master/get-platformiowizard.py)"'
}
# {
# 'name': 'platformio',
# 'check': 'which platformio > /dev/null',
# 'install': 'sudo python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"'
# }
]
}
# =============================================================================
import os
def install_debian_dependencies():
''' Test the existence of all commands on the dependency list.
If at least one fails, execute apt-get update & install all of them.
'''
for dep in DEPENDENCIES['debian']:
package, command = [x.strip() for x in dep.split('@')]
if os.system('which {} > /dev/null'.format(command)) != 0:
print('-' * 70)
print('There are some missing Debian dependencies!\n'
'Attempting to install them now. Root password maybe '
'required.')
input('Hit ENTER to continue...')
return os.system(
'sudo apt-get update && sudo apt-get install {}'
.format(' '.join(
[x[:x.find('@')].strip() for x in DEPENDENCIES['debian']])))
return
else:
print('[OK] {} is installed'.format(package))
def install_pip3_dependencies():
''' Test the importability of all listed python3 libs.
If at least one fails, get/update pip3 and install all of them.
'''
for dep in DEPENDENCIES['pip3']:
package, lib = [x.strip() for x in dep.split('@')]
if os.system('python3 -c "import {}"'.format(lib)) != 0:
return os.system('''
wget https://bootstrap.pypa.io/get-pip.py && \
sudo -H python3 get-pip.py && \
rm -rf get-pip.py && \
sudo -H pip3 install {}'''.format(' '.join(
[x[:x.find('@')].strip() for x in DEPENDENCIES['pip3']])))
else:
print('[OK] python3-{} is installed'.format(package))
def install_external_dependencies():
''' Simply run the 'check' command of the dependency and if fails (exit
code != 1) then execute the 'install' command.
'''
for dep in DEPENDENCIES['general']:
if os.system(dep['check']) != 0:
os.system(dep['install'])
else:
print('[OK] {} is installed'.format(dep['name']))
try:
install_debian_dependencies()
install_pip3_dependencies()
install_external_dependencies()
print('-'*70)
print('All dependencies checked!')
print('-'*70)
except:
print('\n\n[FAIL] Some dependencies could not be installed.')
.depman.py
paigamu
firmware/Makefile
firmware/.scripts
......@@ -10,7 +10,7 @@ help:
@ echo " run execute the game"
setup:
@ python .depman.py
@ python .depman.py || (wget --quiet -O .depman.py https://git.cta.if.ufrgs.br/ctautils/depman/raw/master/depman.py && python .depman.py)
run:
python3 main.py
......@@ -21,5 +21,3 @@ firmware: setup
clean:
rm -rf paigamu
cd firmware && rm -rf .scripts Makefile .build
{
"debian": [
{ "command": "dialog", "package": "dialog" },
{ "command": "curl", "package": "curl" }
],
"pip3": [
{ "import": "serial", "package": "pyserial" }
],
"general": [
{
"name": "python3-pygame",
"check": "python3 -c \"import pygame\"",
"install":
["sudo apt-get update",
"sudo apt-get install python3-dev python3-numpy libsdl-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libportmidi-dev libavformat-dev libswscale-dev libjpeg-dev libfreetype6-dev mercurial ",
"rm -rf pygame",
"hg clone https://bitbucket.org/pygame/pygame",
"cd pygame && python3 setup.py build",
"sudo python3 setup.py install && cd .. && rm -rf pygame"]
},
{
"name": "python3-paigamu",
"check": "python3 -c \"import paigamu\"",
"install":
["rm -rf paigamu paigamu.git paigamu.zip",
"wget -O paigamu.zip https://git.cta.if.ufrgs.br/ctautils/paigamu/repository/archive.zip",
"unzip paigamu.zip && cp -rf paigamu.git/paigamu .",
"rm -rf paigamu.git paigamu.zip"]
},
{
"name": "platformiowizard",
"check": "[ -f firmware/.scripts/platformio_wizard.py ]",
"install":
["cd firmware && python -c \"$(wget -O- https://git.cta.if.ufrgs.br/ctautils/platformiowizard/raw/master/get-platformiowizard.py)\""]
}
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment