diff options
Diffstat (limited to 'subcmds/upload.py')
| -rw-r--r-- | subcmds/upload.py | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index 11f035d7..49d00187 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -25,11 +25,17 @@ def _die(fmt, *args): | |||
| 25 | print >>sys.stderr, 'error: %s' % msg | 25 | print >>sys.stderr, 'error: %s' % msg |
| 26 | sys.exit(1) | 26 | sys.exit(1) |
| 27 | 27 | ||
| 28 | def _SplitEmails(values): | ||
| 29 | result = [] | ||
| 30 | for str in values: | ||
| 31 | result.extend([s.strip() for s in str.split(',')]) | ||
| 32 | return result | ||
| 33 | |||
| 28 | class Upload(InteractiveCommand): | 34 | class Upload(InteractiveCommand): |
| 29 | common = True | 35 | common = True |
| 30 | helpSummary = "Upload changes for code review" | 36 | helpSummary = "Upload changes for code review" |
| 31 | helpUsage=""" | 37 | helpUsage=""" |
| 32 | %prog {[<project>]... | --replace <project>} | 38 | %prog [--re --cc] {[<project>]... | --replace <project>} |
| 33 | """ | 39 | """ |
| 34 | helpDescription = """ | 40 | helpDescription = """ |
| 35 | The '%prog' command is used to send changes to the Gerrit code | 41 | The '%prog' command is used to send changes to the Gerrit code |
| @@ -44,14 +50,25 @@ at the command line. Projects can be specified either by name, or | |||
| 44 | by a relative or absolute path to the project's local directory. If | 50 | by a relative or absolute path to the project's local directory. If |
| 45 | no projects are specified, '%prog' will search for uploadable | 51 | no projects are specified, '%prog' will search for uploadable |
| 46 | changes in all projects listed in the manifest. | 52 | changes in all projects listed in the manifest. |
| 53 | |||
| 54 | If the --reviewers or --cc options are passed, those emails are | ||
| 55 | added to the respective list of users, and emails are sent to any | ||
| 56 | new users. Users passed to --reviewers must be already registered | ||
| 57 | with the code review system, or the upload will fail. | ||
| 47 | """ | 58 | """ |
| 48 | 59 | ||
| 49 | def _Options(self, p): | 60 | def _Options(self, p): |
| 50 | p.add_option('--replace', | 61 | p.add_option('--replace', |
| 51 | dest='replace', action='store_true', | 62 | dest='replace', action='store_true', |
| 52 | help='Upload replacement patchesets from this branch') | 63 | help='Upload replacement patchesets from this branch') |
| 53 | 64 | p.add_option('--re', '--reviewers', | |
| 54 | def _SingleBranch(self, branch): | 65 | type='string', action='append', dest='reviewers', |
| 66 | help='Request reviews from these people.') | ||
| 67 | p.add_option('--cc', | ||
| 68 | type='string', action='append', dest='cc', | ||
| 69 | help='Also send email to these email addresses.') | ||
| 70 | |||
| 71 | def _SingleBranch(self, branch, people): | ||
| 55 | project = branch.project | 72 | project = branch.project |
| 56 | name = branch.name | 73 | name = branch.name |
| 57 | date = branch.date | 74 | date = branch.date |
| @@ -69,11 +86,11 @@ changes in all projects listed in the manifest. | |||
| 69 | sys.stdout.write('(y/n)? ') | 86 | sys.stdout.write('(y/n)? ') |
| 70 | answer = sys.stdin.readline().strip() | 87 | answer = sys.stdin.readline().strip() |
| 71 | if answer in ('y', 'Y', 'yes', '1', 'true', 't'): | 88 | if answer in ('y', 'Y', 'yes', '1', 'true', 't'): |
| 72 | self._UploadAndReport([branch]) | 89 | self._UploadAndReport([branch], people) |
| 73 | else: | 90 | else: |
| 74 | _die("upload aborted by user") | 91 | _die("upload aborted by user") |
| 75 | 92 | ||
| 76 | def _MultipleBranches(self, pending): | 93 | def _MultipleBranches(self, pending, people): |
| 77 | projects = {} | 94 | projects = {} |
| 78 | branches = {} | 95 | branches = {} |
| 79 | 96 | ||
| @@ -132,7 +149,7 @@ changes in all projects listed in the manifest. | |||
| 132 | todo.append(branch) | 149 | todo.append(branch) |
| 133 | if not todo: | 150 | if not todo: |
| 134 | _die("nothing uncommented for upload") | 151 | _die("nothing uncommented for upload") |
| 135 | self._UploadAndReport(todo) | 152 | self._UploadAndReport(todo, people) |
| 136 | 153 | ||
| 137 | def _ReplaceBranch(self, project): | 154 | def _ReplaceBranch(self, project): |
| 138 | branch = project.CurrentBranch | 155 | branch = project.CurrentBranch |
| @@ -176,13 +193,13 @@ changes in all projects listed in the manifest. | |||
| 176 | sys.exit(1) | 193 | sys.exit(1) |
| 177 | 194 | ||
| 178 | branch.replace_changes = to_replace | 195 | branch.replace_changes = to_replace |
| 179 | self._UploadAndReport([branch]) | 196 | self._UploadAndReport([branch], people) |
| 180 | 197 | ||
| 181 | def _UploadAndReport(self, todo): | 198 | def _UploadAndReport(self, todo, people): |
| 182 | have_errors = False | 199 | have_errors = False |
| 183 | for branch in todo: | 200 | for branch in todo: |
| 184 | try: | 201 | try: |
| 185 | branch.UploadForReview() | 202 | branch.UploadForReview(people) |
| 186 | branch.uploaded = True | 203 | branch.uploaded = True |
| 187 | except UploadError, e: | 204 | except UploadError, e: |
| 188 | branch.error = e | 205 | branch.error = e |
| @@ -216,6 +233,14 @@ changes in all projects listed in the manifest. | |||
| 216 | def Execute(self, opt, args): | 233 | def Execute(self, opt, args): |
| 217 | project_list = self.GetProjects(args) | 234 | project_list = self.GetProjects(args) |
| 218 | pending = [] | 235 | pending = [] |
| 236 | reviewers = [] | ||
| 237 | cc = [] | ||
| 238 | |||
| 239 | if opt.reviewers: | ||
| 240 | reviewers = _SplitEmails(opt.reviewers) | ||
| 241 | if opt.cc: | ||
| 242 | cc = _SplitEmails(opt.cc) | ||
| 243 | people = (reviewers,cc) | ||
| 219 | 244 | ||
| 220 | if opt.replace: | 245 | if opt.replace: |
| 221 | if len(project_list) != 1: | 246 | if len(project_list) != 1: |
| @@ -233,6 +258,6 @@ changes in all projects listed in the manifest. | |||
| 233 | if not pending: | 258 | if not pending: |
| 234 | print >>sys.stdout, "no branches ready for upload" | 259 | print >>sys.stdout, "no branches ready for upload" |
| 235 | elif len(pending) == 1 and len(pending[0][1]) == 1: | 260 | elif len(pending) == 1 and len(pending[0][1]) == 1: |
| 236 | self._SingleBranch(pending[0][1][0]) | 261 | self._SingleBranch(pending[0][1][0], people) |
| 237 | else: | 262 | else: |
| 238 | self._MultipleBranches(pending) | 263 | self._MultipleBranches(pending, people) |
