Ask Your Question
0

Get the ros version installed using python code

asked 2019-10-16 15:25:14 -0600

sai krishna gravatar image

Hello,

May I know which python package to used to find the ros version name and the detailed version number installed in my linux box.

TIA

edit retag flag offensive close merge delete

Comments

Are you specifically restricted to python or is bash OK?

stevemacenski gravatar imagestevemacenski ( 2019-10-16 16:14:31 -0600 )edit

And are you assuming you have sourced the setup file or not?

stevemacenski gravatar imagestevemacenski ( 2019-10-16 16:15:15 -0600 )edit

yes i'm trying to understand only in python and I have sourced setup.bash file. I have found the version numbers just by looking at the ros_master's 'package.xml' and 'common.h' in the roscpp package. But I wanted to just use the information in my python application.

sai krishna gravatar imagesai krishna ( 2019-10-16 16:27:22 -0600 )edit

If you know what files theyre in, you can easily use python to crawl those files and extract the versions

stevemacenski gravatar imagestevemacenski ( 2019-10-16 16:30:54 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-10-17 02:30:09 -0600

gvdhoorn gravatar image

I have found the version numbers just by looking at the ros_master's 'package.xml' and 'common.h' in the roscpp package.

That is exactly how rosversion -d does it. See here:

mm = ManifestManager(PACKAGE_FILE)
path = mm.get_path(args.package)
package_manifest = os.path.join(path, 'package.xml')
if os.path.exists(package_manifest):
    from xml.etree.ElementTree import ElementTree
    try:
        root = ElementTree(None, package_manifest)
        version = root.findtext('version')
    except Exception:
        pass
edit flag offensive delete link more

Comments

an ugly way to grep the version name is to create a subprocess pipe with the rosversion -d (or rosversion pkg_name for package version) command:

 new_proc = subprocess.Popen(["rosversion", "-d"], stdout=subprocess.PIPE)
 version_str = new_proc.communicate()[0]
pavel92 gravatar imagepavel92 ( 2019-10-17 03:12:46 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-10-16 15:25:14 -0600

Seen: 26 times

Last updated: Oct 17