def edit_custom_srv(self): text.srv_var_list = '' var_num = 0 text.var_type = 'int32' seq = '' while 1: res = raw_input('\nDo you want to add'+seq+' a variable into your srv file? (y for yes, n/CR for no) ') or -1 seq = ' another' if (res == -1) or (res[0]=='n') or (res[0] == 'N'): print('OK, please do not forget to edit the .srv file before compile') break else: while 1: req = raw_input('Enter the type of request variable '+str(var_num+1)+', [default: '+text.var_type+'], (CR or n for stop)') or text.var_type if (req[0]=='n') or (req[0] == 'N') or (req[0] == '\n'): break else: var_num += 1 text.var_type = req text.msv = 'my_request_var'+ str(var_num) text.srv_var_list = text.srv_var_list + text.tagsub(text.srv_list_element) text.srv_var_list = text.srv_var_list + '---\n' var_num = 0 print '---' while 1: req = raw_input('Enter the type of response variable '+str(var_num+1)+', [default: '+text.var_type+'], (CR or n for stop)') or text.var_type if (req[0]=='n') or (req[0] == 'N') or (req[0] == '\n'): break else: var_num += 1 text.var_type = req text.msv = 'my_response_var'+ str(var_num) text.srv_var_list = text.srv_var_list + text.tagsub(text.srv_list_element) break
def update_cmake_catkin(self): print 'Updating CMakeLists.txt (catkin)' #print 'msg_flag: '+str(self.msg_flag)+' srv_flag: '+str(self.srv_flag) text.exe_list = '' text.catkin_dependency_list = '' for i in self.node_list: text.node_name = i text.exe_list = text.exe_list + text.tagsub(text.executable_catkin) text.msg_list, text.srv_list = self.process_cmake_catkin() if (self.msg_flag == 1) or (self.srv_flag == 1): text.msg_gen = 'generate_messages(DEPENDENCIES std_msgs)' if self.msg_flag == 1: if not self.new_msg in text.msg_list: text.msg_list = text.msg_list + self.new_msg text.msg_add = text.tagsub(text.msg_add_file) self.new_msg = '' if self.srv_flag == 1: if not self.new_srv in text.srv_list: text.srv_list = text.srv_list + self.new_srv text.srv_add = text.tagsub(text.srv_add_file) self.new_srv = '' else: text.msg_gen = '' text.msg_add = '' text.srv_add = '' for i in self.dependency_list: print(i) text.catkin_dependency_list = text.catkin_dependency_list + i +' ' self.gen_cmake()
def update_package_catkin(self): print('start to update package.xml') text.dependency_list = '' for i in self.dependency_list: if not i == self.package_name: text.pkgd = i text.dependency_list = text.dependency_list + text.tagsub(text.depend_pkg_catkin) with open('templates/packageTemplate.xml', 'r') as mfile: m_template = mfile.readlines() with open(self.package_path+'/'+'package.xml', 'w') as outfile: for line in m_template: outfile.write(text.sectsub(text.tagsub(line)))
def gen_manifest(self): with open('templates/manifestTemplate.xml', 'r') as mfile: m_template = mfile.readlines() with open(self.package_path+'/'+'manifest.xml', 'w') as outfile: for line in m_template: outfile.write(text.sectsub(text.tagsub(line))) print('Created package file '+self.package_path+'/manifest.xml')
def gen_package_catkin(self): text.pkg = self.package_name with open('templates/packageTemplate.xml', 'r') as mfile: m_template = mfile.readlines() with open(self.package_path+'/'+'package.xml', 'w') as outfile: for line in m_template: outfile.write(text.sectsub(text.tagsub(line))) print('Created package file '+self.package_path+'/package.xml')
def gen_cmake(self): if self.build_system == 'ros_build': with open('templates/CMakeListTemplate_rosbuild.txt', 'r') as cfile: cm_template = cfile.readlines() else: # Catkin version of CMakeLists text.pkg = self.package_name with open('templates/CMakeListTemplate_catkin.txt', 'r') as cfile: cm_template = cfile.readlines() with open(self.package_path+'/'+'CMakeLists.txt', 'w') as outfile: for line in cm_template: outfile.write(text.sectsub(text.tagsub(line))) print('Created package file '+self.package_path+'/CMakeList.txt')
def gen_srv(self,srv_name): # generate a new service file if not os.path.exists(self.srv_path): os.makedirs(self.srv_path) self.srv_list = os.listdir(self.srv_path) while self.check_srv_name(srv_name): srv_name = raw_input('Service file exists already, please use another name: ') or srv_name print('Generating the '+srv_name+'.srv file') with open('templates/srvTemplate.srv', 'r') as sfile: s_template = sfile.readlines() with open(self.srv_path+'/'+srv_name+'.srv', 'w') as outfile: for line in s_template: outfile.write(text.sectsub(text.tagsub(line))) self.new_srv = srv_name+'.srv'
def gen_msg(self,msg_name): if not os.path.exists(self.msg_path): os.makedirs(self.msg_path) self.msg_list = os.listdir(self.msg_path) while self.check_msg_name(msg_name): msg_name = raw_input('Message file exists already, please use another name: ') or msg_name print('Generating '+msg_name+'.msg file') with open('templates/msgTemplate.msg', 'r') as mfile: m_template = mfile.readlines() with open(self.msg_path+'/'+msg_name+'.msg', 'w') as outfile: for line in m_template: outfile.write(text.sectsub(text.tagsub(line))) self.new_msg = msg_name+'.msg'
def edit_custom_msg(self): text.msg_var_list = '' var_num = 0 text.var_type = 'int32' seq = '' while 1: res = raw_input('\nDo you want to add'+seq+' a variable into your message file? (y for yes, n/CR for no) ') or -1 seq = ' another' if (res == -1) or (res[0]=='n') or (res[0] == 'N'): print('OK, do not forget to edit the .msg file before compile') break else: var_num += 1 text.msv = 'my_message_var'+ str(var_num) print 'New message variable: '+text.msv text.var_type = raw_input('New message variable type? [ex: int32, string, float64] [default: '+text.var_type+']') or text.var_type text.msg_var_list = text.msg_var_list + text.tagsub(text.msv_list_element)
def update_cmake_rosbuild(self): print 'Updating CMakeLists.txt (rosbuild)' text.exe_list = '' for i in self.node_list: text.node_name = i text.exe_list = text.exe_list + text.tagsub(text.executable_rosbuild) with open(self.package_path+'/'+'CMakeLists.txt', 'r') as cmfile: cmfile = cmfile.readlines() if (self.msg_flag == 1): text.msg_gen = 'rosbuild_genmsg()' else: if 'rosbuild_genmsg()\n' in cmfile: text.msg_gen = 'rosbuild_genmsg()' else: text.msg_gen = '#rosbuild_genmsg()' if (self.srv_flag == 1): text.srv_gen = 'rosbuild_gensrv()' else: if 'rosbuild_gensrv()\n' in cmfile: text.srv_gen = 'rosbuild_gensrv()' else: text.srv_gen = '#rosbuild_gensrv()' self.gen_cmake()
print 'Your package path is: '+ path print 'Ros system working properly!' rosOK = 1 except Exception as exc: name_of_exception = type(exc).__name__ print 'Could not "rospack.get_path" of package: '+pkg print ' in ROS workspace: '+rws print 'Ros exception: '+name_of_exception # here we try to fix up ROS environment using shell commands # which are in rosstart_bash.txt print ''' I'm trying to get ROS fixed ...''' with open('templates/rosstart_bash.txt') as ros_script: script = ros_script.readlines() with open('tmpscript','w') as outfile: for line in script: outfile.write(text.tagsub(line)) os.chmod('tmpscript', 0775) print 'running shell commands: > ' for l in script: print ' '+l subprocess.call('./tmpscript',shell=True) if(not rosOK == 1): # now try one more time after trying to fix ROS try: print 'Round2: Testing ros core setup.' ros_root = rospkg.get_ros_root() rp = rospkg.RosPack() path = rp.get_path(pkg) print 'Your package path is: '+ path print 'Ros system working properly!'
print 'Your package path is: ' + path print 'Ros system working properly!' rosOK = 1 except Exception as exc: name_of_exception = type(exc).__name__ print 'Could not "rospack.get_path" of package: ' + pkg print ' in ROS workspace: ' + rws print 'Ros exception: ' + name_of_exception # here we try to fix up ROS environment using shell commands # which are in rosstart_bash.txt print ''' I'm trying to get ROS fixed ...''' with open('templates/rosstart_bash.txt') as ros_script: script = ros_script.readlines() with open('tmpscript', 'w') as outfile: for line in script: outfile.write(text.tagsub(line)) os.chmod('tmpscript', 0775) print 'running shell commands: > ' for l in script: print ' ' + l subprocess.call('./tmpscript', shell=True) if (not rosOK == 1): # now try one more time after trying to fix ROS try: print 'Round2: Testing ros core setup.' ros_root = rospkg.get_ros_root() rp = rospkg.RosPack() path = rp.get_path(pkg) print 'Your package path is: ' + path print 'Ros system working properly!'