| OLD | NEW |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 _STABLE_BRANCH_NAME = 'stabilizing_branch' | 61 _STABLE_BRANCH_NAME = 'stabilizing_branch' |
| 62 | 62 |
| 63 # ======================= Global Helper Functions ======================== | 63 # ======================= Global Helper Functions ======================== |
| 64 | 64 |
| 65 | 65 |
| 66 def _Print(message): | 66 def _Print(message): |
| 67 """Verbose print function.""" | 67 """Verbose print function.""" |
| 68 if gflags.FLAGS.verbose: | 68 if gflags.FLAGS.verbose: |
| 69 Info(message) | 69 Info(message) |
| 70 | 70 |
| 71 |
| 72 def _BuildEBuildDictionary(overlays, package_list, commit_id_list): |
| 73 for index in range(len(package_list)): |
| 74 package = package_list[index] |
| 75 commit_id = '' |
| 76 if commit_id_list: |
| 77 commit_id = commit_id_list[index] |
| 78 ebuild = _EBuild(package, commit_id) |
| 79 if ebuild.ebuild_path: |
| 80 for overlay in overlays: |
| 81 if ebuild.ebuild_path.startswith(overlay): |
| 82 overlays[overlay].append(ebuild) |
| 83 break |
| 84 else: |
| 85 Die('No overlay found for %s' % ebuild.ebuild_path) |
| 86 else: |
| 87 Die('No ebuild found for %s' % package) |
| 88 |
| 89 |
| 71 def _CheckOnStabilizingBranch(): | 90 def _CheckOnStabilizingBranch(): |
| 72 """Returns true if the git branch is on the stabilizing branch.""" | 91 """Returns true if the git branch is on the stabilizing branch.""" |
| 73 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1] | 92 current_branch = _SimpleRunCommand('git branch | grep \*').split()[1] |
| 74 return current_branch == _STABLE_BRANCH_NAME | 93 return current_branch == _STABLE_BRANCH_NAME |
| 75 | 94 |
| 95 |
| 76 def _CheckSaneArguments(package_list, commit_id_list, command): | 96 def _CheckSaneArguments(package_list, commit_id_list, command): |
| 77 """Checks to make sure the flags are sane. Dies if arguments are not sane.""" | 97 """Checks to make sure the flags are sane. Dies if arguments are not sane.""" |
| 78 if not command in _COMMAND_DICTIONARY.keys(): | 98 if not command in _COMMAND_DICTIONARY.keys(): |
| 79 _PrintUsageAndDie('%s is not a valid command' % command) | 99 _PrintUsageAndDie('%s is not a valid command' % command) |
| 80 if not gflags.FLAGS.packages and command == 'commit': | 100 if not gflags.FLAGS.packages and command == 'commit': |
| 81 _PrintUsageAndDie('Please specify at least one package') | 101 _PrintUsageAndDie('Please specify at least one package') |
| 82 if not gflags.FLAGS.board and command == 'commit': | 102 if not gflags.FLAGS.board and command == 'commit': |
| 83 _PrintUsageAndDie('Please specify a board') | 103 _PrintUsageAndDie('Please specify a board') |
| 84 if not os.path.isdir(gflags.FLAGS.srcroot): | 104 if not os.path.isdir(gflags.FLAGS.srcroot): |
| 85 _PrintUsageAndDie('srcroot is not a valid path') | 105 _PrintUsageAndDie('srcroot is not a valid path') |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 @classmethod | 230 @classmethod |
| 211 def _FindEBuildPath(cls, package): | 231 def _FindEBuildPath(cls, package): |
| 212 """Static method that returns the full path of an ebuild.""" | 232 """Static method that returns the full path of an ebuild.""" |
| 213 _Print('Looking for unstable ebuild for %s' % package) | 233 _Print('Looking for unstable ebuild for %s' % package) |
| 214 equery_cmd = ( | 234 equery_cmd = ( |
| 215 'ACCEPT_KEYWORDS="x86 arm amd64" equery-%s which %s 2> /dev/null' | 235 'ACCEPT_KEYWORDS="x86 arm amd64" equery-%s which %s 2> /dev/null' |
| 216 % (gflags.FLAGS.board, package)) | 236 % (gflags.FLAGS.board, package)) |
| 217 path = _SimpleRunCommand(equery_cmd) | 237 path = _SimpleRunCommand(equery_cmd) |
| 218 if path: | 238 if path: |
| 219 _Print('Unstable ebuild found at %s' % path) | 239 _Print('Unstable ebuild found at %s' % path) |
| 220 return path | 240 return path.rstrip() |
| 221 | 241 |
| 222 @classmethod | 242 @classmethod |
| 223 def _ParseEBuildPath(cls, ebuild_path): | 243 def _ParseEBuildPath(cls, ebuild_path): |
| 224 """Static method that parses the path of an ebuild | 244 """Static method that parses the path of an ebuild |
| 225 | 245 |
| 226 Returns a tuple containing the (ebuild path without the revision | 246 Returns a tuple containing the (ebuild path without the revision |
| 227 string, without the version string, and the current revision number for | 247 string, without the version string, and the current revision number for |
| 228 the ebuild). | 248 the ebuild). |
| 229 """ | 249 """ |
| 230 # Get the ebuild name without the revision string. | 250 # Get the ebuild name without the revision string. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 IOError: Error occurred while writing to the new revved ebuild file. | 289 IOError: Error occurred while writing to the new revved ebuild file. |
| 270 """ | 290 """ |
| 271 # TODO(sosa): Change to a check. | 291 # TODO(sosa): Change to a check. |
| 272 if not self._ebuild: | 292 if not self._ebuild: |
| 273 Die('Invalid ebuild given to EBuildStableMarker') | 293 Die('Invalid ebuild given to EBuildStableMarker') |
| 274 | 294 |
| 275 new_ebuild_path = '%s-r%d.ebuild' % (self._ebuild.ebuild_path_no_revision, | 295 new_ebuild_path = '%s-r%d.ebuild' % (self._ebuild.ebuild_path_no_revision, |
| 276 self._ebuild.current_revision + 1) | 296 self._ebuild.current_revision + 1) |
| 277 | 297 |
| 278 _Print('Creating new stable ebuild %s' % new_ebuild_path) | 298 _Print('Creating new stable ebuild %s' % new_ebuild_path) |
| 279 shutil.copyfile('%s-9999.ebuild' % self._ebuild.ebuild_path_no_version, | 299 workon_ebuild = '%s-9999.ebuild' % self._ebuild.ebuild_path_no_version |
| 280 new_ebuild_path) | 300 if not os.path.exists(workon_ebuild): |
| 301 Die('Missing 9999 ebuild: %s' % workon_ebuild) |
| 302 shutil.copyfile(workon_ebuild, new_ebuild_path) |
| 281 | 303 |
| 282 for line in fileinput.input(new_ebuild_path, inplace=1): | 304 for line in fileinput.input(new_ebuild_path, inplace=1): |
| 283 # Has to be done here to get changes to sys.stdout from fileinput.input. | 305 # Has to be done here to get changes to sys.stdout from fileinput.input. |
| 284 if not redirect_file: | 306 if not redirect_file: |
| 285 redirect_file = sys.stdout | 307 redirect_file = sys.stdout |
| 286 if line.startswith('KEYWORDS'): | 308 if line.startswith('KEYWORDS'): |
| 287 # Actually mark this file as stable by removing ~'s. | 309 # Actually mark this file as stable by removing ~'s. |
| 288 redirect_file.write(line.replace("~", "")) | 310 redirect_file.write(line.replace("~", "")) |
| 289 elif line.startswith('EAPI'): | 311 elif line.startswith('EAPI'): |
| 290 # Always add new commit_id after EAPI definition. | 312 # Always add new commit_id after EAPI definition. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 except gflags.FlagsError, e : | 351 except gflags.FlagsError, e : |
| 330 _PrintUsageAndDie(str(e)) | 352 _PrintUsageAndDie(str(e)) |
| 331 | 353 |
| 332 package_list = gflags.FLAGS.packages.split() | 354 package_list = gflags.FLAGS.packages.split() |
| 333 if gflags.FLAGS.commit_ids: | 355 if gflags.FLAGS.commit_ids: |
| 334 commit_id_list = gflags.FLAGS.commit_ids.split() | 356 commit_id_list = gflags.FLAGS.commit_ids.split() |
| 335 else: | 357 else: |
| 336 commit_id_list = None | 358 commit_id_list = None |
| 337 _CheckSaneArguments(package_list, commit_id_list, command) | 359 _CheckSaneArguments(package_list, commit_id_list, command) |
| 338 | 360 |
| 339 overlay_directory = '%s/third_party/chromiumos-overlay' % gflags.FLAGS.srcroot | 361 overlays = { |
| 362 '%s/private-overlays/chromeos-overlay' % gflags.FLAGS.srcroot: [], |
| 363 '%s/third_party/chromiumos-overlay' % gflags.FLAGS.srcroot: [] |
| 364 } |
| 365 _BuildEBuildDictionary(overlays, package_list, commit_id_list) |
| 340 | 366 |
| 341 os.chdir(overlay_directory) | 367 for overlay, ebuilds in overlays.items(): |
| 368 if not os.path.exists(overlay): |
| 369 continue |
| 370 os.chdir(overlay) |
| 342 | 371 |
| 343 if command == 'clean': | 372 if command == 'clean': |
| 344 _Clean() | 373 _Clean() |
| 345 elif command == 'commit': | 374 elif command == 'push': |
| 346 work_branch = _GitBranch(_STABLE_BRANCH_NAME) | 375 _PushChange() |
| 347 work_branch.CreateBranch() | 376 elif command == 'commit' and ebuilds: |
| 348 if not work_branch.Exists(): | 377 work_branch = _GitBranch(_STABLE_BRANCH_NAME) |
| 349 Die('Unable to create stabilizing branch in %s' % | 378 work_branch.CreateBranch() |
| 350 overlay_directory) | 379 if not work_branch.Exists(): |
| 351 index = 0 | 380 Die('Unable to create stabilizing branch in %s' % overlay) |
| 352 try: | 381 for ebuild in ebuilds: |
| 353 for index in range(len(package_list)): | 382 try: |
| 354 # Gather the package and optional commit id to work on. | 383 _Print('Working on %s' % ebuild.package) |
| 355 package = package_list[index] | 384 worker = EBuildStableMarker(ebuild) |
| 356 commit_id = "" | 385 worker.RevEBuild(ebuild.commit_id) |
| 357 if commit_id_list: | 386 message = _GIT_COMMIT_MESSAGE % (ebuild.package, ebuild.commit_id) |
| 358 commit_id = commit_id_list[index] | 387 worker.CommitChange(message) |
| 359 | 388 except (OSError, IOError): |
| 360 _Print('Working on %s' % package) | 389 Warning('Cannot rev %s\n' % ebuild.package, |
| 361 worker = EBuildStableMarker(_EBuild(package, commit_id)) | 390 'Note you will have to go into %s ' |
| 362 worker.RevEBuild(commit_id) | 391 'and reset the git repo yourself.' % overlay) |
| 363 worker.CommitChange(_GIT_COMMIT_MESSAGE % (package, commit_id)) | 392 raise |
| 364 | |
| 365 except (OSError, IOError), e: | |
| 366 Warning('An exception occurred\n' | |
| 367 'Only the following packages were revved: %s\n' | |
| 368 'Note you will have to go into %s' | |
| 369 'and reset the git repo yourself.' % | |
| 370 (package_list[:index], overlay_directory)) | |
| 371 raise e | |
| 372 elif command == 'push': | |
| 373 _PushChange() | |
| 374 | 393 |
| 375 | 394 |
| 376 if __name__ == '__main__': | 395 if __name__ == '__main__': |
| 377 main(sys.argv) | 396 main(sys.argv) |
| 378 | 397 |
| OLD | NEW |