def GetProjects(self, args, missing_ok=False, submodules_ok=False): """A list of projects that match the arguments. """ all_projects = self.manifest.projects result = [] mp = self.manifest.manifestProject groups = mp.config.GetString('manifest.groups') if not groups: groups = 'all,-notdefault,platform-' + platform.system().lower() groups = [x for x in re.split(r'[,\s]+', groups) if x] if not args: all_projects_list = all_projects.values() derived_projects = {} for project in all_projects_list: if submodules_ok or project.sync_s: derived_projects.update((p.name, p) for p in project.GetDerivedSubprojects()) all_projects_list.extend(derived_projects.values()) for project in all_projects_list: if ((missing_ok or project.Exists) and project.MatchesGroups(groups)): result.append(project) else: self._ResetPathToProjectMap(all_projects.values()) for arg in args: project = all_projects.get(arg) if not project: path = os.path.abspath(arg).replace('\\', '/') project = self._GetProjectByPath(path) # If it's not a derived project, update path->project mapping and # search again, as arg might actually point to a derived subproject. if (project and not project.Derived and (submodules_ok or project.sync_s)): search_again = False for subproject in project.GetDerivedSubprojects(): self._UpdatePathToProjectMap(subproject) search_again = True if search_again: project = self._GetProjectByPath(path) or project if not project: raise NoSuchProjectError(arg) if not missing_ok and not project.Exists: raise NoSuchProjectError(arg) if not project.MatchesGroups(groups): raise InvalidProjectGroupsError(arg) result.append(project) def _getpath(x): return x.relpath result.sort(key=_getpath) return result
def GetProjects(self, args, manifest=None, groups='', missing_ok=False, submodules_ok=False): """A list of projects that match the arguments. """ if not manifest: manifest = self.manifest all_projects_list = manifest.projects result = [] mp = manifest.manifestProject if not groups: groups = mp.config.GetString('manifest.groups') if not groups: groups = 'default,platform-' + platform.system().lower() groups = [x for x in re.split(r'[,\s]+', groups) if x] if not args: derived_projects = {} for project in all_projects_list: if submodules_ok or project.sync_s: derived_projects.update((p.name, p) for p in project.GetDerivedSubprojects()) all_projects_list.extend(derived_projects.values()) for project in all_projects_list: if (missing_ok or project.Exists) and project.MatchesGroups(groups): result.append(project) else: self._ResetPathToProjectMap(all_projects_list) for arg in args: # We have to filter by manifest groups in case the requested project is # checked out multiple times or differently based on them. projects = [project for project in manifest.GetProjectsWithName(arg) if project.MatchesGroups(groups)] if not projects: path = os.path.abspath(arg).replace('\\', '/') project = self._GetProjectByPath(manifest, path) # If it's not a derived project, update path->project mapping and # search again, as arg might actually point to a derived subproject. if (project and not project.Derived and (submodules_ok or project.sync_s)): search_again = False for subproject in project.GetDerivedSubprojects(): self._UpdatePathToProjectMap(subproject) search_again = True if search_again: project = self._GetProjectByPath(manifest, path) or project if project: projects = [project] if not projects: raise NoSuchProjectError(arg) for project in projects: if not missing_ok and not project.Exists: raise NoSuchProjectError('%s (%s)' % (arg, project.relpath)) if not project.MatchesGroups(groups): raise InvalidProjectGroupsError(arg) result.extend(projects) def _getpath(x): return x.relpath result.sort(key=_getpath) return result
def GetProjects(self, args, missing_ok=False): """A list of projects that match the arguments. """ all = self.manifest.projects result = [] mp = self.manifest.manifestProject groups = mp.config.GetString('manifest.groups') if not groups: groups = 'default,platform-' + platform.system().lower() groups = [x for x in re.split('[,\s]+', groups) if x] if not args: for project in all.values(): if ((missing_ok or project.Exists) and project.MatchesGroups(groups)): result.append(project) else: by_path = None for arg in args: project = all.get(arg) if not project: path = os.path.abspath(arg).replace('\\', '/') if not by_path: by_path = dict() for p in all.values(): by_path[p.worktree] = p if os.path.exists(path): oldpath = None while path \ and path != oldpath \ and path != self.manifest.topdir: try: project = by_path[path] break except KeyError: oldpath = path path = os.path.dirname(path) else: try: project = by_path[path] except KeyError: pass if not project: raise NoSuchProjectError(arg) if not missing_ok and not project.Exists: raise NoSuchProjectError(arg) if not project.MatchesGroups(groups): raise InvalidProjectGroupsError(arg) result.append(project) def _getpath(x): return x.relpath result.sort(key=_getpath) return result