/tools/bugs/server/appengine/providers/datastore/pusher.py

https://code.google.com/ · Python · 71 lines · 31 code · 10 blank · 30 comment · 4 complexity · ec875e195c1c36035fcd0fa8b3776e9b MD5 · raw file

  1. # Copyright 2011 Google Inc. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Datastore indexer object."""
  15. __author__ = 'jason.stredwick@gmail.com (Jason Stredwick)'
  16. from google.appengine.api import users
  17. from bugs import kind
  18. from bugs.models.bugs import bug
  19. from bugs.providers import pusher_base
  20. class Error(pusher_base.Error):
  21. pass
  22. class Pusher(pusher_base.PusherBase):
  23. """Pusher base class.
  24. Pusher is responsible for filling the provider's database with the bug
  25. details. Normally, this may require a transformation of the metadata from
  26. the BITE bug details into data useful for the provider.
  27. """
  28. def __init__(self, bug, max_retries=3):
  29. pusher_base.PusherBase.__init__(self, bug, max_retries)
  30. def Push(self):
  31. """Updates the bug model with values set by providers such as bug_id.
  32. Raises:
  33. Error: Raised if there was an error creating an index.
  34. """
  35. try:
  36. current_user = users.get_current_user()
  37. user_email = None
  38. if current_user:
  39. user_email = current_user.email()
  40. provider_data = {
  41. 'kind': kind.Kind.BUG,
  42. 'id': self.bug.key().id(),
  43. 'bug_id': str(self.bug.key().id()), # bug_id
  44. 'author': user_email,
  45. 'author_id': user_email,
  46. 'reported_on': str(self.bug.added),
  47. 'last_update': str(self.bug.modified),
  48. 'last_updater': user_email,
  49. 'status': self.bug.state,
  50. 'project': 'none',
  51. 'priority': 'none',
  52. 'details_link': ''
  53. }
  54. bug.Update(self.bug, provider_data)
  55. except (bug.InvalidIdError, bug.UpdateError), e:
  56. raise Error(e)