rosmsg_metafinder.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:rosimport 作者: pyros-dev 项目源码 文件源码
def __init__(self, *workspaces):
            """
            :param workspaces: can be a devel or install workspace (including a distro install directory), but also a directory containing packages (like a source workspace)
            These should all work, without catkin build necessary.
            """
            super(ROSDistroMetaFinder, self).__init__()
            # TODO : prevent that when we are in virtualenv and we have not allowed system site packages

            self.src_rospkgs = []

            broken_workspaces = []
            for w in workspaces:
                # Adding the share path (where we can find all packages and their messages)
                share_path = os.path.join(w, 'share')
                if os.path.exists(share_path):
                    self.share_path = share_path
                else:  # this is not a workspace, maybe we are expected to get the package directly from source ?
                    found_one = False
                    for root, dirs, files in os.walk(w, topdown=False):
                        if 'package.xml' in files:  # we have found a ros package
                            self.src_rospkgs.append(root)
                            found_one = True
                    if not found_one:
                        broken_workspaces.append(w)

                    raise ImportError

                python_libpath = os.path.join(w, 'lib', 'python' + sys.version_info.major + '.' + sys.version_info.minor)
                if os.path.exists(python_libpath):
                    # adding python site directories for the ROS distro (to find python modules as usual with ROS)
                    if os.path.exists(os.path.join(python_libpath, 'dist-packages')):
                        site.addsitedir(os.path.join(python_libpath, 'dist-packages'))
                    if os.path.exists(os.path.join(python_libpath, 'site-packages')):
                        site.addsitedir(os.path.join(python_libpath, 'site-packages'))
                else:  # this is not a workspace, maybe we are expected to get the package directly from source ?

                    for root, dirs, files in os.walk(w, topdown=False):
                        if 'package.xml' in files:  # we have found a ros package
                            self.src_rospkgs.append(root)

                    raise ImportError
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号