Ejemplo n.º 1
0
 def __init__(self, alt_paths = None):
     self.packages = []
     self.rospack = RosPack.get_instance()
     self.rosstack = RosStack.get_instance()
     if alt_paths is None:
         self.altpack = self.rospack
         self.altstack = self.rosstack
     else:
         self.altpack = RosPack.get_instance(alt_paths)
         self.altstack = RosStack.get_instance(alt_paths)
Ejemplo n.º 2
0
 def _setup(self):
     try:
         with open(self.index_file, "r") as handle:
             data = yaml.safe_load(handle)
     except IOError as e:
         data = {}
     self.project = Project(data.get("project", "default"))
     self.repositories = data.get("repositories", {})
     self.packages = set(data.get("packages")
                         or RosPack.get_instance(["."]).list())
     self.missing = set(self.packages)
     self.configurations = data.get("configurations", {})
     self.rules = data.get("rules", {})
Ejemplo n.º 3
0
 def locate_offline(cls, name, repo_path=None):
     _log.debug("Package.locate_offline(%s, %s)", name, repo_path)
     # Step 1: use repository download directory
     if repo_path:
         rp = RosPack.get_instance([repo_path])
         try:
             path = rp.get_path(name)
             path = os.path.join(path, "package.xml")
             if os.path.isfile(path):
                 _log.debug("Found %s in local repositories.", name)
                 return cls.from_manifest(path)
         except ResourceNotFound as e:
             _log.debug("%s was not found in local repositories.", name)
     # Step 2: use known directories
     rp = RosPack.get_instance()
     try:
         path = rp.get_path(name)
         path = os.path.join(path, "package.xml")
         if os.path.isfile(path):
             _log.debug("Found %s in default paths.", name)
             return cls.from_manifest(path)
     except ResourceNotFound as e:
         _log.debug("%s was not found in default paths.", name)
     return None
Ejemplo n.º 4
0
    def index_source(self, index_file, repo_path=None, index_repos=False):
        _log.debug("DataManager.index_source(%s, %s)", index_file, repo_path)
        if os.path.isfile(index_file):
            with open(index_file, "r") as handle:
                data = yaml.load(handle)
        else:
            data = {"packages": []}
    # Step 1: find packages locally
        _log.info("Looking for packages locally.")
        missing = []
        pkg_list = self._read_launch_listing(data.get("launch"))
        pkg_list.extend(data.get("packages", []))
        if not pkg_list and os.path.isfile("src/CMakeLists.txt"):
            _log.info("Harvesting packages from catkin workspace")
            pkg_list = RosPack.get_instance(".").list()
        pkg_list = set(pkg_list)
        for id in pkg_list:
            pkg = Package.locate_offline(id, repo_path)
            if pkg is None:
                missing.append(id)
            else:
                SourceFile.populate_package(pkg, self.files)
                self.packages[id] = pkg
    # Step 2: load repositories only if explicitly told to
        _log.debug("Missing packages: %s", missing)
        if index_repos:
            _log.info("Indexing repositories.")
            self.repositories = Repository.load_repositories(
                data.get("repositories", {}), pkg_list)
            repos = set()
            for _, repo in self.repositories.iteritems():
                for id in repo.declared_packages:
                    if id in missing:
                        _log.debug("%s contains missing %s", _, id)
                        repos.add(repo)
    # Step 3: clone necessary repositories
            wd = os.getcwd()
            refresh = False
            for repo in repos:
                try:
                    repo.download(repo_path)
                    refresh = True
                except RepositoryCloneError as e:
                    _log.warning("Could not download %s: %s", repo.id, e.value)
            os.chdir(wd)
            if refresh:
                _log.debug("Refreshing package cache for %s", repo_path)
                Package.refresh_package_cache(repo_path)
    # Step 4: find packages and link to repositories
            _log.info("Looking for missing packages in local repositories.")
            for _, repo in self.repositories.iteritems():
                for id in repo.declared_packages:
                    if id in self.packages:
                        _log.debug("Binding %s to %s", id, _)
                        repo.packages.append(self.packages[id])
                        self.packages[id].repository = repo
                    elif id in missing:
                        pkg = Package.locate_offline(id, repo_path)
                        if pkg:
                            _log.debug("Found %s in clones.", id)
                            SourceFile.populate_package(pkg, self.files)
                            self.packages[id] = pkg
                            missing.remove(id)
                            repo.packages.append(pkg)
                            pkg.repository = repo
                        else:
                            _log.debug("%s was not found in clones.", id)
    # Step 5: sort packages in topological order
        self._topological_sort()
        for id in missing:
            _log.warning("Could not find package " + id)

    # Step 6: check if operating in launch mode
        self._search_launch_files()
Ejemplo n.º 5
0
 def refresh_package_cache(repo_path=None):
     if repo_path:
         rp = RosPack.get_instance([repo_path])
     else:
         rp = RosPack.get_instance()
     rp._location_cache = None