98 lines
4.0 KiB
Python
Executable File
98 lines
4.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
from __future__ import with_statement
|
|
|
|
from optparse import OptionParser
|
|
import sys, os
|
|
|
|
def usage(exit_code):
|
|
print """Usage:
|
|
rosorg [svn command] args
|
|
"""
|
|
sys.exit(exit_code)
|
|
|
|
def load_distro():
|
|
import yaml, urllib2
|
|
if 1:
|
|
f = urllib2.urlopen('http://ros.org/rosdistro.yaml')
|
|
d = yaml.load(f)
|
|
else:
|
|
with open(os.path.join(os.environ['ROS_ROOT'], 'rosdistro.yaml'), 'r') as f:
|
|
d = yaml.load(f)
|
|
|
|
distros = d['distros']
|
|
for distro in distros:
|
|
if 'latest' in distro:
|
|
released = distro['latest']
|
|
|
|
rp_urlbase = 'https://code.ros.org/svn/ros-pkg/stacks/%s/tags/latest/'
|
|
wg_urlbase = 'https://code.ros.org/svn/wg-ros-pkg/stacks/%s/tags/latest/'
|
|
released = [s for s in released if s != 'ros']
|
|
rp_urls = [(s, rp_urlbase%s) for s in released if 'pr2' not in s]
|
|
wg_urls = [(s, wg_urlbase%s) for s in released if 'pr2' in s]
|
|
return rp_urls + wg_urls
|
|
|
|
def main(argv=sys.argv):
|
|
if len(sys.argv) < 2:
|
|
usage(1)
|
|
cmd = sys.argv[1]
|
|
|
|
repos = load_distro()
|
|
repos.append(('ros-pkg','https://code.ros.org/svn/ros-pkg/trunk/'))
|
|
repos.append(('wg-ros-pkg','https://code.ros.org/svn/wg-ros-pkg/trunk/'))
|
|
|
|
from subprocess import Popen, PIPE, call, check_call
|
|
stderrs = []
|
|
if cmd in ['checkout', 'co']:
|
|
for k, url in repos:
|
|
v = Popen(['svn', 'co', url, k], stdout=sys.stdout, stdin=sys.stdin, stderr=sys.stderr).communicate()
|
|
elif cmd in ['ci', 'commit']:
|
|
print >> sys.stderr, "commit is disabled for rosorg-svn command. Please cd to the appropriate directory where changes are and used svn normally"
|
|
elif cmd == 'urls':
|
|
for k, url in repos:
|
|
print url
|
|
elif cmd == 'build' or cmd == 'build-test':
|
|
if 'WORKSPACE' not in os.environ:
|
|
print 'Building is not supported when WORKSPACE is not set'
|
|
sys.exit(1)
|
|
|
|
if 'PATH' in os.environ:
|
|
path = ':'.join([os.path.join(os.environ['ROS_ROOT'], 'bin'), os.environ['PATH']])
|
|
else:
|
|
path = os.path.join(os.environ['ROS_ROOT'], 'bin')
|
|
|
|
if 'PYTHONPATH' in os.environ:
|
|
pythonpath = ':'.join([os.environ['PYTHONPATH'], os.path.join(os.environ['ROS_ROOT'], 'core', 'roslib', 'src')])
|
|
else:
|
|
pythonpath = os.path.join(os.environ['ROS_ROOT'], 'core', 'roslib', 'src')
|
|
ros_package_path = ':'.join([os.path.join(os.environ['WORKSPACE'], 'ros-pkg'), os.path.join(os.environ['WORKSPACE'], 'ros_experimental')])
|
|
env_vars = os.environ.copy()
|
|
env_vars.update({'ROS_PACKAGE_PATH' : ros_package_path,
|
|
'PATH' : path,
|
|
'PYTHONPATH' : pythonpath,
|
|
'ROS_MASTER_URI' : 'http://localhost:11311'})
|
|
if 'SVN_REVISION' in env_vars:
|
|
del env_vars['SVN_REVISION']
|
|
check_call(['make'], cwd=os.environ['ROS_ROOT'], env=env_vars, stdout=sys.stdout, stdin=sys.stdin, stderr=sys.stderr)
|
|
# Temporary
|
|
if os.uname()[0] == 'Darwin':
|
|
build_cmd = [os.path.join(os.environ['ROS_ROOT'], 'core', 'rosbuild', 'bin', 'rosmakeall_osx')]
|
|
else:
|
|
build_cmd = [os.path.join(os.environ['ROS_ROOT'], 'core', 'rosbuild', 'bin', 'rosmakeall')]
|
|
if cmd == 'build-test':
|
|
build_cmd.append('test')
|
|
check_call(build_cmd, cwd=os.environ['ROS_ROOT'], env=env_vars, stdout=sys.stdout, stdin=sys.stdin, stderr=sys.stderr)
|
|
else:
|
|
for k, url in repos:
|
|
if os.path.isdir(k):
|
|
v = Popen(['svn', cmd]+sys.argv[2:], cwd=k, stdout=PIPE, stderr=PIPE).communicate()
|
|
if v[0]:
|
|
print "-- [%s] -------"%k
|
|
print v[0]
|
|
stderrs.append(v[1])
|
|
stderrs = [s for s in stderrs if s.strip()]
|
|
if stderrs:
|
|
print "WARNING: svn reported the following errors:"
|
|
print "\n----\n".join(stderrs)
|
|
if __name__ == '__main__':
|
|
main(sys.argv)
|