Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: cros_mark_as_stable.py

Issue 6291013: Have the ability for the PFQ to both rev Chrome and other packages. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Nit Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/cros_mark_chrome_as_stable.py ('k') | cros_mark_as_stable_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """This module uprevs a given package's ebuild to the next revision.""" 7 """This module uprevs a given package's ebuild to the next revision."""
8 8
9 9
10 import fileinput 10 import fileinput
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 # Add stable ebuilds to overlays[overlay]. 159 # Add stable ebuilds to overlays[overlay].
160 paths = [os.path.join(package_dir, path) for path in files] 160 paths = [os.path.join(package_dir, path) for path in files]
161 ebuild = _FindUprevCandidates(paths) 161 ebuild = _FindUprevCandidates(paths)
162 162
163 # If the --all option isn't used, we only want to update packages that 163 # If the --all option isn't used, we only want to update packages that
164 # are in packages. 164 # are in packages.
165 if ebuild and (all or ebuild.package in packages): 165 if ebuild and (all or ebuild.package in packages):
166 overlays[overlay].append(ebuild) 166 overlays[overlay].append(ebuild)
167 167
168 168
169 def _CheckOnStabilizingBranch(stable_branch): 169 def _DoWeHaveLocalCommits(stable_branch, tracking_branch):
170 """Returns true if the git branch is on the stabilizing branch.""" 170 """Returns true if there are local commits."""
171 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1] 171 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1]
172 return current_branch == stable_branch 172 if current_branch == stable_branch:
173 current_commit_id = _SimpleRunCommand('git rev-parse HEAD')
174 tracking_commit_id = _SimpleRunCommand('git rev-parse %s' % tracking_branch)
175 return current_commit_id != tracking_commit_id
176 else:
177 return False
173 178
174 179
175 def _CheckSaneArguments(package_list, command): 180 def _CheckSaneArguments(package_list, command):
176 """Checks to make sure the flags are sane. Dies if arguments are not sane.""" 181 """Checks to make sure the flags are sane. Dies if arguments are not sane."""
177 if not command in COMMAND_DICTIONARY.keys(): 182 if not command in COMMAND_DICTIONARY.keys():
178 _PrintUsageAndDie('%s is not a valid command' % command) 183 _PrintUsageAndDie('%s is not a valid command' % command)
179 if not gflags.FLAGS.packages and command == 'commit' and not gflags.FLAGS.all: 184 if not gflags.FLAGS.packages and command == 'commit' and not gflags.FLAGS.all:
180 _PrintUsageAndDie('Please specify at least one package') 185 _PrintUsageAndDie('Please specify at least one package')
181 if not gflags.FLAGS.board and command == 'commit': 186 if not gflags.FLAGS.board and command == 'commit':
182 _PrintUsageAndDie('Please specify a board') 187 _PrintUsageAndDie('Please specify a board')
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 # ======================= End Global Helper Functions ======================== 221 # ======================= End Global Helper Functions ========================
217 222
218 223
219 def Clean(tracking_branch): 224 def Clean(tracking_branch):
220 """Cleans up uncommitted changes. 225 """Cleans up uncommitted changes.
221 226
222 Args: 227 Args:
223 tracking_branch: The tracking branch we want to return to after the call. 228 tracking_branch: The tracking branch we want to return to after the call.
224 """ 229 """
225 _SimpleRunCommand('git reset HEAD --hard') 230 _SimpleRunCommand('git reset HEAD --hard')
226 _SimpleRunCommand('git checkout %s' % tracking_branch) 231 branch = GitBranch(STABLE_BRANCH_NAME, tracking_branch)
232 if branch.Exists():
233 GitBranch.Checkout(branch)
234 branch.Delete()
227 235
228 236
229 def PushChange(stable_branch, tracking_branch): 237 def PushChange(stable_branch, tracking_branch):
230 """Pushes commits in the stable_branch to the remote git repository. 238 """Pushes commits in the stable_branch to the remote git repository.
231 239
232 Pushes locals commits from calls to CommitChange to the remote git 240 Pushes locals commits from calls to CommitChange to the remote git
233 repository specified by current working directory. 241 repository specified by current working directory.
234 242
235 Args: 243 Args:
236 stable_branch: The local branch with commits we want to push. 244 stable_branch: The local branch with commits we want to push.
237 tracking_branch: The tracking branch of the local branch. 245 tracking_branch: The tracking branch of the local branch.
238 Raises: 246 Raises:
239 OSError: Error occurred while pushing. 247 OSError: Error occurred while pushing.
240 """ 248 """
241 num_retries = 5 249 num_retries = 5
242 250
243 # Sanity check to make sure we're on a stabilizing branch before pushing. 251 # Sanity check to make sure we're on a stabilizing branch before pushing.
244 if not _CheckOnStabilizingBranch(stable_branch): 252 if not _DoWeHaveLocalCommits(stable_branch, tracking_branch):
245 Info('Not on branch %s so no work found to push. Exiting' % stable_branch) 253 Info('Not work found to push. Exiting')
246 return 254 return
247 255
248 description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' + 256 description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' +
249 tracking_branch + '..') 257 tracking_branch + '..')
250 description = 'Marking set of ebuilds as stable\n\n%s' % description 258 description = 'Marking set of ebuilds as stable\n\n%s' % description
251 Info('Using description %s' % description) 259 Info('Using description %s' % description)
252 merge_branch_name = 'merge_branch' 260 merge_branch_name = 'merge_branch'
253 for push_try in range(num_retries + 1): 261 for push_try in range(num_retries + 1):
254 try: 262 try:
255 _SimpleRunCommand('repo sync .') 263 _SimpleRunCommand('repo sync .')
256 merge_branch = GitBranch(merge_branch_name, tracking_branch) 264 merge_branch = GitBranch(merge_branch_name, tracking_branch)
265 if merge_branch.Exists():
266 merge_branch.Delete()
257 merge_branch.CreateBranch() 267 merge_branch.CreateBranch()
258 if not merge_branch.Exists(): 268 if not merge_branch.Exists():
259 Die('Unable to create merge branch.') 269 Die('Unable to create merge branch.')
260 _SimpleRunCommand('git merge --squash %s' % stable_branch) 270 _SimpleRunCommand('git merge --squash %s' % stable_branch)
261 _SimpleRunCommand('git commit -m "%s"' % description) 271 _SimpleRunCommand('git commit -m "%s"' % description)
262 _SimpleRunCommand('git config push.default tracking') 272 _SimpleRunCommand('git config push.default tracking')
263 if gflags.FLAGS.dryrun: 273 if gflags.FLAGS.dryrun:
264 _SimpleRunCommand('git push --dry-run') 274 _SimpleRunCommand('git push --dry-run')
265 else: 275 else:
266 _SimpleRunCommand('git push') 276 _SimpleRunCommand('git push')
267 277
268 break 278 break
269 except: 279 except:
270 if push_try < num_retries: 280 if push_try < num_retries:
271 Warning('Failed to push change, performing retry (%s/%s)' % ( 281 Warning('Failed to push change, performing retry (%s/%s)' % (
272 push_try + 1, num_retries)) 282 push_try + 1, num_retries))
273 else: 283 else:
274 raise 284 raise
275 285
276 286
277 class GitBranch(object): 287 class GitBranch(object):
278 """Wrapper class for a git branch.""" 288 """Wrapper class for a git branch."""
279 289
280 def __init__(self, branch_name, tracking_branch): 290 def __init__(self, branch_name, tracking_branch):
281 """Sets up variables but does not create the branch.""" 291 """Sets up variables but does not create the branch."""
282 self.branch_name = branch_name 292 self.branch_name = branch_name
283 self.tracking_branch = tracking_branch 293 self.tracking_branch = tracking_branch
284 294
285 def CreateBranch(self): 295 def CreateBranch(self):
286 """Creates a new git branch or replaces an existing one.""" 296 GitBranch.Checkout(self)
287 if self.Exists():
288 self.Delete()
289 self._Checkout(self.branch_name)
290 297
291 def _Checkout(self, target, create=True): 298 @classmethod
292 """Function used internally to create and move between branches.""" 299 def Checkout(cls, target):
293 if create: 300 """Function used to check out to another GitBranch."""
294 git_cmd = 'git checkout -b %s %s' % (target, self.tracking_branch) 301 if target.branch_name == target.tracking_branch or target.Exists():
302 git_cmd = 'git checkout %s' % target.branch_name
295 else: 303 else:
296 git_cmd = 'git checkout %s' % target 304 git_cmd = 'git checkout -b %s %s' % (target.branch_name,
305 target.tracking_branch)
297 _SimpleRunCommand(git_cmd) 306 _SimpleRunCommand(git_cmd)
298 307
299 def Exists(self): 308 def Exists(self):
300 """Returns True if the branch exists.""" 309 """Returns True if the branch exists."""
301 branch_cmd = 'git branch' 310 branch_cmd = 'git branch'
302 branches = _SimpleRunCommand(branch_cmd) 311 branches = _SimpleRunCommand(branch_cmd)
303 return self.branch_name in branches.split() 312 return self.branch_name in branches.split()
304 313
305 def Delete(self): 314 def Delete(self):
306 """Deletes the branch and returns the user to the master branch. 315 """Deletes the branch and returns the user to the master branch.
307 316
308 Returns True on success. 317 Returns True on success.
309 """ 318 """
310 self._Checkout(self.tracking_branch, create=False) 319 tracking_branch = GitBranch(self.tracking_branch, self.tracking_branch)
320 GitBranch.Checkout(tracking_branch)
311 delete_cmd = 'git branch -D %s' % self.branch_name 321 delete_cmd = 'git branch -D %s' % self.branch_name
312 _SimpleRunCommand(delete_cmd) 322 _SimpleRunCommand(delete_cmd)
313 323
314 324
315 class EBuild(object): 325 class EBuild(object):
316 """Wrapper class for information about an ebuild.""" 326 """Wrapper class for information about an ebuild."""
317 327
318 def __init__(self, path): 328 def __init__(self, path):
319 """Sets up data about an ebuild from its path.""" 329 """Sets up data about an ebuild from its path."""
320 from portage.versions import pkgsplit 330 from portage.versions import pkgsplit
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) 573 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id)
564 worker.CommitChange(message) 574 worker.CommitChange(message)
565 revved_packages.append(ebuild.package) 575 revved_packages.append(ebuild.package)
566 new_package_atoms.append('=%s' % new_package) 576 new_package_atoms.append('=%s' % new_package)
567 except (OSError, IOError): 577 except (OSError, IOError):
568 Warning('Cannot rev %s\n' % ebuild.package, 578 Warning('Cannot rev %s\n' % ebuild.package,
569 'Note you will have to go into %s ' 579 'Note you will have to go into %s '
570 'and reset the git repo yourself.' % overlay) 580 'and reset the git repo yourself.' % overlay)
571 raise 581 raise
572 582
573 if revved_packages: 583 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms)
574 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms) 584 if gflags.FLAGS.drop_file:
575 if gflags.FLAGS.drop_file: 585 fh = open(gflags.FLAGS.drop_file, 'w')
576 fh = open(gflags.FLAGS.drop_file, 'w') 586 fh.write(' '.join(revved_packages))
577 fh.write(' '.join(revved_packages)) 587 fh.close()
578 fh.close()
579 else:
580 work_branch.Delete()
581 588
582 589
583 if __name__ == '__main__': 590 if __name__ == '__main__':
584 main(sys.argv) 591 main(sys.argv)
OLDNEW
« no previous file with comments | « bin/cros_mark_chrome_as_stable.py ('k') | cros_mark_as_stable_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698