api.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright 2016 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. from recipe_engine import recipe_api
  5. import string
  6. class GitClApi(recipe_api.RecipeApi):
  7. def __call__(self, subcmd, args, name=None, **kwargs):
  8. if not name:
  9. name = 'git_cl ' + subcmd
  10. if kwargs.get('suffix'):
  11. name = name + ' (%s)' % kwargs.pop('suffix')
  12. my_loc = self.c.repo_location if self.c else None
  13. with self.m.context(cwd=self.m.context.cwd or my_loc):
  14. return self.m.python(
  15. name, self.repo_resource('git_cl.py'), [subcmd] + args,
  16. **kwargs)
  17. def get_description(self, patch_url=None, codereview=None, **kwargs):
  18. """DEPRECATED. Consider using gerrit.get_change_description instead."""
  19. args = ['-d']
  20. if patch_url or codereview:
  21. assert patch_url and codereview, (
  22. 'Both patch_url and codereview must be provided')
  23. args.append('--%s' % codereview)
  24. args.append(patch_url)
  25. return self('description', args, stdout=self.m.raw_io.output(), **kwargs)
  26. def set_description(self, description, patch_url=None, codereview=None, **kwargs):
  27. args = ['-n', '-']
  28. if patch_url or codereview:
  29. assert patch_url and codereview, (
  30. 'Both patch_url and codereview must be provided')
  31. args.append(patch_url)
  32. args.append('--%s' % codereview)
  33. return self(
  34. 'description', args, stdout=self.m.raw_io.output(),
  35. stdin=self.m.raw_io.input_text(description),
  36. name='git_cl set description', **kwargs)
  37. def upload(self, message, upload_args=None, **kwargs):
  38. upload_args = upload_args or []
  39. upload_args.extend(['--message-file', self.m.raw_io.input_text(message)])
  40. return self('upload', upload_args, **kwargs)
  41. def issue(self, **kwargs):
  42. return self('issue', [], stdout=self.m.raw_io.output(), **kwargs)