$search
00001 #!/usr/bin/python 00002 00003 from roslib import stack_manifest 00004 from jobs_common import * 00005 import sys 00006 import os 00007 import optparse 00008 import subprocess 00009 import traceback 00010 00011 00012 def main(): 00013 # global try 00014 try: 00015 print "Starting run_auto_stack_devel script" 00016 00017 # parse command line options 00018 print "Parsing command line options" 00019 (options, args) = get_options(['stack', 'rosdistro'], ['repeat', 'source-only']) 00020 if not options: 00021 return -1 00022 if len(options.stack) > 1: 00023 print "You can only provide one stack at a time" 00024 return -1 00025 options.stack = options.stack[0] 00026 print "parsed options: %s"%str(options) 00027 00028 # set environment 00029 print "Setting up environment" 00030 env = get_environment() 00031 if options.source_only or options.stack == 'ros': 00032 ros_path = env['WORKSPACE'] 00033 else: 00034 ros_path = '/opt/ros/%s'%options.rosdistro 00035 print "Working in %s"%ros_path 00036 env['ROS_PACKAGE_PATH'] = '%s:%s'%(env['WORKSPACE'], ros_path) 00037 env['ROS_ROOT'] = '%s/ros'%ros_path 00038 env['PYTHONPATH'] = env['ROS_ROOT']+'/core/roslib/src' 00039 env['PATH'] = '%s/ros/bin:%s'%(ros_path, os.getenv('PATH')) 00040 stack_dir = env['WORKSPACE']+'/'+options.stack 00041 print("Environment set to %s"%str(env)) 00042 00043 # Parse distro file 00044 rosdistro_obj = rosdistro.Distro(get_rosdistro_file(options.rosdistro)) 00045 print 'Operating on ROS distro %s'%rosdistro_obj.release_name 00046 00047 # get all stack dependencies of the stack we're testing 00048 depends = [] 00049 stack_xml = '%s/stack.xml'%stack_dir 00050 call('ls %s'%stack_xml, env, 'Checking if stack %s contains "stack.xml" file'%options.stack) 00051 with open(stack_xml) as stack_file: 00052 depends_one = [str(d) for d in stack_manifest.parse(stack_file.read()).depends] # convert to list 00053 print 'Dependencies of stack %s: %s'%(options.stack, str(depends_one)) 00054 for d in depends_one: 00055 if not d == options.stack and not d in depends: 00056 print 'Adding dependencies of stack %s'%d 00057 get_depends_all(rosdistro_obj, d, depends) 00058 print 'Resulting total dependencies: %s'%str(depends) 00059 00060 if len(depends) > 0: 00061 if not options.source_only: 00062 # Install Debian packages of stack dependencies 00063 print 'Installing debian packages of stack dependencies from stacks %s'%str(options.stack) 00064 call('sudo apt-get update', env) 00065 print 'Installing debian packages of "%s" dependencies: %s'%(options.stack, str(depends)) 00066 call('sudo apt-get install %s --yes'%(stacks_to_debs(depends, options.rosdistro)), env) 00067 else: 00068 # Install stack dependencies from source 00069 print 'Installing stack dependencies from source' 00070 rosinstall = stacks_to_rosinstall(depends, rosdistro_obj.released_stacks, 'release-tar') 00071 print 'Using rosinstall yaml: %s'%rosinstall 00072 rosinstall_file = '%s.rosinstall'%options.stack 00073 with open(rosinstall_file, 'w') as f: 00074 f.write(rosinstall) 00075 call('rosinstall --delete-changed-uris --rosdep-yes %s %s'%(env['WORKSPACE'], rosinstall_file), env, 00076 'Install the stack dependencies from source.') 00077 else: 00078 print 'Stack %s does not have any dependencies, not installing anything now'%str(options.stack) 00079 00080 # Install system dependencies of stack itself 00081 print 'Installing system dependencies of stack %s'%options.stack 00082 call('rosmake rosdep', env) 00083 call('rosdep install -y %s'%options.stack, env, 00084 'Install system dependencies of stack %s'%options.stack) 00085 00086 # Start Hudson Helper 00087 print 'Running Hudson Helper in folder %s'%stack_dir 00088 res = 0 00089 test_results = env['ROS_TEST_RESULTS_DIR'] 00090 for r in range(0, options.repeat+1): 00091 env['ROS_TEST_RESULTS_DIR'] = test_results + '/run_'+str(r) 00092 #res_one = subprocess.call(('./hudson_helper --dir-test %s build'%stack_dir).split(' '), env=env) 00093 res_one = subprocess.call(('./hudson_helper --pkg-test %s build'%options.stack).split(' '), env=env) 00094 if res_one != 0: 00095 res = res_one 00096 return res 00097 00098 # global except 00099 except Exception, ex: 00100 print "Global exception caught. Generating email with exception text %s"%str(ex) 00101 generate_email("%s. Check the console output for test failure details."%str(ex), env) 00102 traceback.print_exc(file=sys.stdout) 00103 raise ex 00104 00105 00106 if __name__ == '__main__': 00107 try: 00108 res = main() 00109 sys.exit( res ) 00110 except Exception, ex: 00111 sys.exit(-1) 00112 00113 00114 00115