ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Workaround?

#!/usr/bin/env python
import os
pkg_name = os.path.basename(os.getcwd())
    if pkg_name in ['src','bin','python']: # typical sub dirs 
    pkg_name = os.path.basename(os.path.dirname(os.getcwd()))
import roslib; roslib.load_manifest(pkg_name)
  :
  :

A "more proper but expensive" solution would be to recursively search the path for a manifest.xml and parse that.

Workaround?

#!/usr/bin/env python
import os
os, sys

#pkg_name = os.path.basename(os.getcwd()) # not working when called from wherever
#pkg_name = os.path.basename(os.path.realpath(sys.path[0])) # might work in every case
pkg_name = os.path.basename(os.getcwd())
    os.path.basename(os.path.dirname(os.path.realpath(__file__))) # should work in every case

if pkg_name in ['src','bin','python']: # typical sub dirs 
    pkg_name = os.path.basename(os.path.dirname(os.getcwd()))
import roslib; roslib.load_manifest(pkg_name)
  :
  :

A "more proper but expensive" solution would be to recursively search the path for a manifest.xml and parse that.

click to hide/show revision 3
incomplete edit fixed

Workaround?

#!/usr/bin/env python
import os, sys

#pkg_name = os.path.basename(os.getcwd()) # not working when called from wherever
#pkg_name = os.path.basename(os.path.realpath(sys.path[0])) # might work in every case
pkg_name = os.path.basename(os.path.dirname(os.path.realpath(__file__))) # should work in every case

if pkg_name in ['src','bin','python']: # typical sub dirs 
    pkg_name = os.path.basename(os.path.dirname(os.getcwd()))
os.path.basename(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
import roslib; roslib.load_manifest(pkg_name)
  :

A "more proper but expensive" solution would be to recursively search the path for a manifest.xml and parse that.