abstractstep.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2010 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import sys
  29. from webkitpy.common.system.executive import ScriptError
  30. from webkitpy.tool.steps.options import Options
  31. class AbstractStep(object):
  32. def __init__(self, tool, options):
  33. self._tool = tool
  34. self._options = options
  35. def _exit(self, code):
  36. sys.exit(code)
  37. def _changed_files(self, state):
  38. return self.cached_lookup(state, "changed_files")
  39. _well_known_keys = {
  40. # FIXME: Should this use state.get('bug_id') or state.get('patch').bug_id() like UpdateChangeLogsWithReviewer does?
  41. "bug": lambda self, state: self._tool.bugs.fetch_bug(state["bug_id"]),
  42. # bug_title can either be a new title given by the user, or one from an existing bug.
  43. "bug_title": lambda self, state: self.cached_lookup(state, 'bug').title(),
  44. "changed_files": lambda self, state: self._tool.scm().changed_files(self._options.git_commit),
  45. "diff": lambda self, state: self._tool.scm().create_patch(self._options.git_commit, changed_files=self._changed_files(state)),
  46. # Absolute path to ChangeLog files.
  47. "changelogs": lambda self, state: self._tool.checkout().modified_changelogs(self._options.git_commit, changed_files=self._changed_files(state)),
  48. }
  49. def cached_lookup(self, state, key, promise=None):
  50. if state.get(key):
  51. return state[key]
  52. if not promise:
  53. promise = self._well_known_keys.get(key)
  54. state[key] = promise(self, state)
  55. return state[key]
  56. def did_modify_checkout(self, state):
  57. state["diff"] = None
  58. state["changelogs"] = None
  59. state["changed_files"] = None
  60. @classmethod
  61. def options(cls):
  62. return [
  63. # We need this option here because cached_lookup uses it. :(
  64. Options.git_commit,
  65. ]
  66. def run(self, state):
  67. raise NotImplementedError, "subclasses must implement"