Support filtering by group on forall and list subcmd

Enable operating against groups of repositories. As it stands, it isn't
compatible with `-r/--regex`.

`repo forall -g groupname -c pwd` will  run `pwd` for all projects in
groupname.

`repo forall -g thisgroup,-butnotthisone -c pwd` will  run `pwd` for all
projects in `thisgroup` but not `butnotthisone`.

`repo list -g groupname -n` will list all the names of repos in
`groupname`.

Change-Id: Ia75c50ce52541d1c8cea2874b20a4db2e0e54960
This commit is contained in:
Graham Christensen 2015-07-29 17:02:54 -05:00
parent abaa7f312f
commit 0369a069ad
3 changed files with 11 additions and 4 deletions

View File

@ -126,7 +126,7 @@ class Command(object):
pass pass
return project return project
def GetProjects(self, args, missing_ok=False, submodules_ok=False): def GetProjects(self, args, groups='', missing_ok=False, submodules_ok=False):
"""A list of projects that match the arguments. """A list of projects that match the arguments.
""" """
all_projects_list = self.manifest.projects all_projects_list = self.manifest.projects
@ -134,6 +134,7 @@ class Command(object):
mp = self.manifest.manifestProject mp = self.manifest.manifestProject
if not groups:
groups = mp.config.GetString('manifest.groups') groups = mp.config.GetString('manifest.groups')
if not groups: if not groups:
groups = 'default,platform-' + platform.system().lower() groups = 'default,platform-' + platform.system().lower()

View File

@ -120,6 +120,9 @@ without iterating through the remaining projects.
p.add_option('-r', '--regex', p.add_option('-r', '--regex',
dest='regex', action='store_true', dest='regex', action='store_true',
help="Execute the command only on projects matching regex or wildcard expression") help="Execute the command only on projects matching regex or wildcard expression")
p.add_option('-g', '--groups',
dest='groups',
help="Execute the command only on projects matching the specified groups")
p.add_option('-c', '--command', p.add_option('-c', '--command',
help='Command (and arguments) to execute', help='Command (and arguments) to execute',
dest='command', dest='command',
@ -213,7 +216,7 @@ without iterating through the remaining projects.
self.manifest.Override(smart_sync_manifest_path) self.manifest.Override(smart_sync_manifest_path)
if not opt.regex: if not opt.regex:
projects = self.GetProjects(args) projects = self.GetProjects(args, groups=opt.groups)
else: else:
projects = self.FindProjects(args) projects = self.FindProjects(args)

View File

@ -35,6 +35,9 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
p.add_option('-r', '--regex', p.add_option('-r', '--regex',
dest='regex', action='store_true', dest='regex', action='store_true',
help="Filter the project list based on regex or wildcard matching of strings") help="Filter the project list based on regex or wildcard matching of strings")
p.add_option('-g', '--groups',
dest='groups',
help="Filter the project list based on the groups the project is in")
p.add_option('-f', '--fullpath', p.add_option('-f', '--fullpath',
dest='fullpath', action='store_true', dest='fullpath', action='store_true',
help="Display the full work tree path instead of the relative path") help="Display the full work tree path instead of the relative path")
@ -62,7 +65,7 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
sys.exit(1) sys.exit(1)
if not opt.regex: if not opt.regex:
projects = self.GetProjects(args) projects = self.GetProjects(args, groups=opt.groups)
else: else:
projects = self.FindProjects(args) projects = self.FindProjects(args)