def parse_manifest_file(dirpath, manifest_name): """ Parse manifest file (package, stack). Type will be inferred from manifest_name. :param dirpath: directory of manifest file, ``str`` :param manifest_name: ``MANIFEST_FILE`` or ``STACK_FILE``, ``str`` :returns: return :class:`Manifest` instance, populated with parsed fields :raises: :exc:`InvalidManifest` :raises: :exc:`IOError` """ filename = os.path.join(dirpath, manifest_name) if not os.path.isfile(filename): # hack for backward compatibility package_filename = os.path.join(dirpath, PACKAGE_FILE) if not os.path.isfile(package_filename): raise IOError("Invalid/non-existent manifest file: %s" % filename) manifest = Manifest(filename=filename, is_catkin=True) # extract all information from package.xml from catkin_pkg.package import parse_package p = parse_package(package_filename) # put these into manifest manifest.description = p.description manifest.author = ', '.join([('Maintainer: %s' % str(m)) for m in p.maintainers] + [str(a) for a in p.authors]) manifest.license = ', '.join(p.licenses) if p.urls: manifest.url = str(p.urls[0]) manifest.version = p.version for export in p.exports: manifest.exports.append(Export(export.tagname, export.attributes, export.content)) # split ros and system dependencies (using rosdep) try: from rosdep2.rospack import init_rospack_interface, is_ros_package, is_system_dependency, is_view_empty global _static_rosdep_view # initialize rosdep view once if _static_rosdep_view is None: _static_rosdep_view = init_rospack_interface() if is_view_empty(_static_rosdep_view): sys.stderr.write("the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'\n") _static_rosdep_view = False if _static_rosdep_view: depends = set([]) rosdeps = set([]) for d in (p.buildtool_depends + p.build_depends + p.run_depends): if is_ros_package(_static_rosdep_view, d.name): depends.add(d.name) if is_system_dependency(_static_rosdep_view, d.name): rosdeps.add(d.name) for name in depends: manifest.depends.append(Depend(name, 'package')) for name in rosdeps: manifest.rosdeps.append(RosDep(name)) except ImportError: pass return manifest with open(filename, 'r') as f: return parse_manifest(manifest_name, f.read(), filename)
def parse_manifest_file(dirpath, manifest_name, rospack=None): """ Parse manifest file (package, stack). Type will be inferred from manifest_name. :param dirpath: directory of manifest file, ``str`` :param manifest_name: ``MANIFEST_FILE`` or ``STACK_FILE``, ``str`` :param rospack: a RosPack instance to identify local packages as ROS packages :returns: return :class:`Manifest` instance, populated with parsed fields :raises: :exc:`InvalidManifest` :raises: :exc:`IOError` """ filename = os.path.join(dirpath, manifest_name) if not os.path.isfile(filename): # hack for backward compatibility package_filename = os.path.join(dirpath, PACKAGE_FILE) if not os.path.isfile(package_filename): raise IOError("Invalid/non-existent manifest file: %s" % filename) manifest = Manifest(filename=filename, is_catkin=True) # extract all information from package.xml from catkin_pkg.package import parse_package p = parse_package(package_filename) # put these into manifest manifest.description = p.description manifest.author = ', '.join([('Maintainer: %s' % str(m)) for m in p.maintainers] + [str(a) for a in p.authors]) manifest.license = ', '.join(p.licenses) if p.urls: manifest.url = str(p.urls[0]) manifest.version = p.version for export in p.exports: manifest.exports.append( Export(export.tagname, export.attributes, export.content)) # split ros and system dependencies (using rosdep) try: from rosdep2.rospack import init_rospack_interface, is_ros_package, is_system_dependency, is_view_empty global _static_rosdep_view # initialize rosdep view once if _static_rosdep_view is None: _static_rosdep_view = init_rospack_interface() if is_view_empty(_static_rosdep_view): sys.stderr.write( "the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'\n" ) _static_rosdep_view = False if _static_rosdep_view: depends = set([]) rosdeps = set([]) for d in (p.buildtool_depends + p.build_depends + p.run_depends + p.test_depends): if (rospack and d.name in rospack.list()) or is_ros_package( _static_rosdep_view, d.name): depends.add(d.name) if is_system_dependency(_static_rosdep_view, d.name): rosdeps.add(d.name) for name in depends: manifest.depends.append(Depend(name, 'package')) for name in rosdeps: manifest.rosdeps.append(RosDep(name)) except ImportError: pass return manifest with open(filename, 'rb') as f: data = f.read() if sys.version_info[0] >= 3: data = data.decode('utf-8') return parse_manifest(manifest_name, data, filename)