00001
00002
00003 import sys
00004 import cgi
00005 import urllib
00006 import os
00007 import subprocess
00008 import tempfile
00009 import re
00010
00011 import cgitb
00012 cgitb.enable()
00013
00014
00015 def main():
00016 legacy_distro = ['cturtle', 'diamondback', 'electric']
00017
00018 print "Content-Type: text/html"
00019 print
00020
00021 form = cgi.FieldStorage()
00022 keys = ['rosdistro', 'variant', 'overlay']
00023 for k in keys:
00024 if not k in form.keys():
00025 return 'Missing parameters: %s'%k
00026 if form['overlay'].value not in ['yes', 'no']:
00027
00028 return 'invalid overlay parameter'
00029 p = re.compile('\A[A-Za-z]+[\w\-]*\Z')
00030 if not bool(p.match(form['variant'].value)):
00031
00032 return 'invalid variant parameter'
00033
00034
00035
00036 if form['rosdistro'].value in legacy_distro:
00037 command = 'export ROS_HOME=/tmp && export ROS_PACKAGE_PATH="/home/willow/ros_release:/opt/ros/cturtle/stacks" && export ROS_ROOT="/opt/ros/cturtle/ros" && export PATH="/opt/ros/cturtle/ros/bin:$PATH" && export PYTHONPATH="/opt/ros/cturtle/ros/core/roslib/src" && rosrun job_generation generate_rosinstall.py --rosdistro %s --variant %s --overlay %s --database /home/log/rosinstall.db'%(form['rosdistro'].value, form['variant'].value, form['overlay'].value)
00038
00039
00040 else:
00041 command = 'generate_rosinstall.py --rosdistro %s --variant %s --overlay %s --database /home/log/rosinstall.db'%(form['rosdistro'].value, form['variant'].value, form['overlay'].value)
00042
00043 helper = subprocess.Popen(['bash', '-c', command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00044 res, err = helper.communicate()
00045 if helper.returncode != 0:
00046 return '%s'%str(err)
00047 else:
00048 print '%s'%str(res)
00049 return 0
00050
00051
00052 if __name__ == '__main__':
00053 sys.exit(main())
00054