Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 from roslib.packages import get_pkg_dir, ROSPkgException
00020 import os
00021 import sys
00022 import __builtin__
00023
00024 from python_qt_binding.QtGui import *
00025 from python_qt_binding.QtCore import *
00026 from python_qt_binding import loadUi
00027 from roslib.packages import get_pkg_dir
00028 from xml.etree import ElementTree
00029
00030
00031 RE_PREFIXED_TAG = "$"
00032 RE_PREFIXED_BEGIN_TAG = "${"
00033 RE_PREFIXED_END_TAG = "}"
00034
00035
00036 DEFAULT_PREFIX_NAME = "prefix"
00037 ROS_WS_PREFIX_NAME = "rosws"
00038 ROS_WS_SRC_PREFIX_NAME = "rossrc"
00039
00040
00041
00042
00043
00044 def get_pkg_dir_from_prefix(path, ros_package_path=None):
00045
00046 if RE_PREFIXED_TAG not in path:
00047 return path
00048
00049 splitpath = path.split(RE_PREFIXED_END_TAG)
00050
00051 after_prefix_path = splitpath[-1]
00052
00053 prefix = splitpath[0].split(RE_PREFIXED_BEGIN_TAG)[-1]
00054
00055 if prefix == DEFAULT_PREFIX_NAME:
00056 if ros_package_path is not None:
00057 rpath = ros_package_path+after_prefix_path
00058 else:
00059 raise ROSPkgException("Unknown prefixed ${prefix} path ! not associated to ros package path !")
00060 elif prefix == ROS_WS_PREFIX_NAME:
00061 rpath = get_ros_workspace_dir()+after_prefix_path
00062 elif prefix == ROS_WS_SRC_PREFIX_NAME:
00063 print get_ros_workspace_src_dir(),after_prefix_path
00064 rpath = get_ros_workspace_src_dir()+after_prefix_path
00065 else:
00066 rpath = get_pkg_dir(prefix)+after_prefix_path
00067
00068 return rpath
00069
00070 def get_ros_workspace_dir():
00071 return os.environ["ROS_WORKSPACE"]
00072
00073 def get_ros_workspace_src_dir():
00074 return os.path.join(os.environ["ROS_WORKSPACE"],'src')
00075
00076 class PyModule:
00077
00078 def __init__(self, module_name):
00079
00080 rospy.logdebug("Try to import module %s ..."%module_name)
00081
00082 self._module = None
00083
00084 try:
00085 self._module = __import__(module_name)
00086 except Exception as ex:
00087 rospy.logerr(str(ex))
00088 raise ex
00089
00090 rospy.logdebug("Module %s imported."%str(self._module))
00091
00092 def __import__(self, py_class):
00093 rospy.logdebug(" - Try to class %s ..."%py_class)
00094 class_ref = getattr(self._module, py_class, None)
00095 rospy.logdebug(" - Class %s imported."%str(class_ref))
00096 return class_ref
00097
00098 class PyPkg:
00099
00100 def __init__(self, pkg):
00101 self._pkg_dir = get_pkg_dir(pkg)
00102
00103 def __module__(self, _module):
00104
00105 _module = _module.replace('.','/')
00106
00107 fullpath = self._pkg_dir+"/"+_module
00108
00109 fullpath_split = fullpath.split('/')
00110 module_dir = '/'.join(fullpath_split[:-1])
00111 module_name = fullpath_split[-1]
00112
00113 sys.path.append(str(module_dir))
00114
00115 return PyModule(str(module_name))
00116
00117 class QAgiPackages:
00118
00119 def __init__(self, pkg):
00120 return QAgiPackages.__pkg__(pkg)
00121
00122 @staticmethod
00123 def get_pkg_dir(exp):
00124 return get_pkg_dir_from_prefix(exp)
00125
00126 @staticmethod
00127 def getDirByName(pkg_name):
00128 return get_pkg_dir(pkg_name)
00129
00130 def getRessources(self):
00131 return None
00132
00133 def getRessourcesById(self, category, resid):
00134 return None
00135
00136 @staticmethod
00137 def __ws_dir__():
00138 return os.environ[ROS_PACKAGE_PATH].split(':')[0]
00139
00140 @staticmethod
00141 def __src_dir__():
00142 return os.environ[ROS_PACKAGE_PATH].split(':')[1]
00143
00144 @staticmethod
00145 def __pkg__(pkg):
00146 return PyPkg(pkg)
00147