diff options
author | Gavin Mak <gavinmak@google.com> | 2023-03-11 06:46:20 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-22 17:46:28 +0000 |
commit | ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch) | |
tree | dc33ba0e56825b3e007d0589891756724725a465 /subcmds/list.py | |
parent | 1604cf255f8c1786a23388db6d5277ac7949a24a (diff) | |
download | git-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz |
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught
by flake8. Also check black formatting in run_tests (and CQ).
Bug: b/267675342
Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'subcmds/list.py')
-rw-r--r-- | subcmds/list.py | 158 |
1 files changed, 96 insertions, 62 deletions
diff --git a/subcmds/list.py b/subcmds/list.py index ad8036ee..24e3e1fc 100644 --- a/subcmds/list.py +++ b/subcmds/list.py | |||
@@ -18,13 +18,13 @@ from command import Command, MirrorSafeCommand | |||
18 | 18 | ||
19 | 19 | ||
20 | class List(Command, MirrorSafeCommand): | 20 | class List(Command, MirrorSafeCommand): |
21 | COMMON = True | 21 | COMMON = True |
22 | helpSummary = "List projects and their associated directories" | 22 | helpSummary = "List projects and their associated directories" |
23 | helpUsage = """ | 23 | helpUsage = """ |
24 | %prog [-f] [<project>...] | 24 | %prog [-f] [<project>...] |
25 | %prog [-f] -r str1 [str2]... | 25 | %prog [-f] -r str1 [str2]... |
26 | """ | 26 | """ |
27 | helpDescription = """ | 27 | helpDescription = """ |
28 | List all projects; pass '.' to list the project for the cwd. | 28 | List all projects; pass '.' to list the project for the cwd. |
29 | 29 | ||
30 | By default, only projects that currently exist in the checkout are shown. If | 30 | By default, only projects that currently exist in the checkout are shown. If |
@@ -35,69 +35,103 @@ groups, then also pass --groups all. | |||
35 | This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | 35 | This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. |
36 | """ | 36 | """ |
37 | 37 | ||
38 | def _Options(self, p): | 38 | def _Options(self, p): |
39 | p.add_option('-r', '--regex', | 39 | p.add_option( |
40 | dest='regex', action='store_true', | 40 | "-r", |
41 | help='filter the project list based on regex or wildcard matching of strings') | 41 | "--regex", |
42 | p.add_option('-g', '--groups', | 42 | dest="regex", |
43 | dest='groups', | 43 | action="store_true", |
44 | help='filter the project list based on the groups the project is in') | 44 | help="filter the project list based on regex or wildcard matching " |
45 | p.add_option('-a', '--all', | 45 | "of strings", |
46 | action='store_true', | 46 | ) |
47 | help='show projects regardless of checkout state') | 47 | p.add_option( |
48 | p.add_option('-n', '--name-only', | 48 | "-g", |
49 | dest='name_only', action='store_true', | 49 | "--groups", |
50 | help='display only the name of the repository') | 50 | dest="groups", |
51 | p.add_option('-p', '--path-only', | 51 | help="filter the project list based on the groups the project is " |
52 | dest='path_only', action='store_true', | 52 | "in", |
53 | help='display only the path of the repository') | 53 | ) |
54 | p.add_option('-f', '--fullpath', | 54 | p.add_option( |
55 | dest='fullpath', action='store_true', | 55 | "-a", |
56 | help='display the full work tree path instead of the relative path') | 56 | "--all", |
57 | p.add_option('--relative-to', metavar='PATH', | 57 | action="store_true", |
58 | help='display paths relative to this one (default: top of repo client checkout)') | 58 | help="show projects regardless of checkout state", |
59 | ) | ||
60 | p.add_option( | ||
61 | "-n", | ||
62 | "--name-only", | ||
63 | dest="name_only", | ||
64 | action="store_true", | ||
65 | help="display only the name of the repository", | ||
66 | ) | ||
67 | p.add_option( | ||
68 | "-p", | ||
69 | "--path-only", | ||
70 | dest="path_only", | ||
71 | action="store_true", | ||
72 | help="display only the path of the repository", | ||
73 | ) | ||
74 | p.add_option( | ||
75 | "-f", | ||
76 | "--fullpath", | ||
77 | dest="fullpath", | ||
78 | action="store_true", | ||
79 | help="display the full work tree path instead of the relative path", | ||
80 | ) | ||
81 | p.add_option( | ||
82 | "--relative-to", | ||
83 | metavar="PATH", | ||
84 | help="display paths relative to this one (default: top of repo " | ||
85 | "client checkout)", | ||
86 | ) | ||
59 | 87 | ||
60 | def ValidateOptions(self, opt, args): | 88 | def ValidateOptions(self, opt, args): |
61 | if opt.fullpath and opt.name_only: | 89 | if opt.fullpath and opt.name_only: |
62 | self.OptionParser.error('cannot combine -f and -n') | 90 | self.OptionParser.error("cannot combine -f and -n") |
63 | 91 | ||
64 | # Resolve any symlinks so the output is stable. | 92 | # Resolve any symlinks so the output is stable. |
65 | if opt.relative_to: | 93 | if opt.relative_to: |
66 | opt.relative_to = os.path.realpath(opt.relative_to) | 94 | opt.relative_to = os.path.realpath(opt.relative_to) |
67 | 95 | ||
68 | def Execute(self, opt, args): | 96 | def Execute(self, opt, args): |
69 | """List all projects and the associated directories. | 97 | """List all projects and the associated directories. |
70 | 98 | ||
71 | This may be possible to do with 'repo forall', but repo newbies have | 99 | This may be possible to do with 'repo forall', but repo newbies have |
72 | trouble figuring that out. The idea here is that it should be more | 100 | trouble figuring that out. The idea here is that it should be more |
73 | discoverable. | 101 | discoverable. |
74 | 102 | ||
75 | Args: | 103 | Args: |
76 | opt: The options. | 104 | opt: The options. |
77 | args: Positional args. Can be a list of projects to list, or empty. | 105 | args: Positional args. Can be a list of projects to list, or empty. |
78 | """ | 106 | """ |
79 | if not opt.regex: | 107 | if not opt.regex: |
80 | projects = self.GetProjects(args, groups=opt.groups, missing_ok=opt.all, | 108 | projects = self.GetProjects( |
81 | all_manifests=not opt.this_manifest_only) | 109 | args, |
82 | else: | 110 | groups=opt.groups, |
83 | projects = self.FindProjects(args, all_manifests=not opt.this_manifest_only) | 111 | missing_ok=opt.all, |
112 | all_manifests=not opt.this_manifest_only, | ||
113 | ) | ||
114 | else: | ||
115 | projects = self.FindProjects( | ||
116 | args, all_manifests=not opt.this_manifest_only | ||
117 | ) | ||
84 | 118 | ||
85 | def _getpath(x): | 119 | def _getpath(x): |
86 | if opt.fullpath: | 120 | if opt.fullpath: |
87 | return x.worktree | 121 | return x.worktree |
88 | if opt.relative_to: | 122 | if opt.relative_to: |
89 | return os.path.relpath(x.worktree, opt.relative_to) | 123 | return os.path.relpath(x.worktree, opt.relative_to) |
90 | return x.RelPath(local=opt.this_manifest_only) | 124 | return x.RelPath(local=opt.this_manifest_only) |
91 | 125 | ||
92 | lines = [] | 126 | lines = [] |
93 | for project in projects: | 127 | for project in projects: |
94 | if opt.name_only and not opt.path_only: | 128 | if opt.name_only and not opt.path_only: |
95 | lines.append("%s" % (project.name)) | 129 | lines.append("%s" % (project.name)) |
96 | elif opt.path_only and not opt.name_only: | 130 | elif opt.path_only and not opt.name_only: |
97 | lines.append("%s" % (_getpath(project))) | 131 | lines.append("%s" % (_getpath(project))) |
98 | else: | 132 | else: |
99 | lines.append("%s : %s" % (_getpath(project), project.name)) | 133 | lines.append("%s : %s" % (_getpath(project), project.name)) |
100 | 134 | ||
101 | if lines: | 135 | if lines: |
102 | lines.sort() | 136 | lines.sort() |
103 | print('\n'.join(lines)) | 137 | print("\n".join(lines)) |