pristinetar.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # vim: set fileencoding=utf-8 :
  2. #
  3. # (C) 2012 Guido Günther <agx@sigxcpu.org>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, please see
  16. # <http://www.gnu.org/licenses/>
  17. """Handle checkin and checkout of archives from the pristine-tar branch"""
  18. import os
  19. import gbp.log
  20. from gbp.command_wrappers import Command
  21. class PristineTar(Command):
  22. """The pristine-tar branch in a git repository"""
  23. cmd='/usr/bin/pristine-tar'
  24. branch = 'pristine-tar'
  25. def __init__(self, repo):
  26. self.repo = repo
  27. super(PristineTar, self).__init__(self.cmd, cwd=repo.path, capture_stderr=True)
  28. def has_commit(self, archive_regexp):
  29. """
  30. Do we have a pristine-tar commit for a package matching I{archive_regexp}.
  31. @param archive_regexp: archive name to look for (regexp wildcards allowed)
  32. @type archive_regexp: C{str}
  33. """
  34. return True if self.get_commit(archive_regexp) else False
  35. def get_commit(self, archive_regexp):
  36. """
  37. Get the pristine-tar commit of a package matching I{archive_regexp}.
  38. @param archive_regexp: archive name to look for (regexp wildcards allowed)
  39. @type archive_regexp: C{str}
  40. """
  41. if not self.repo.has_pristine_tar_branch():
  42. return None
  43. regex = ('pristine-tar .* %s' % archive_regexp)
  44. commits = self.repo.grep_log(regex, self.branch)
  45. if commits:
  46. commit = commits[-1]
  47. gbp.log.debug("Found pristine-tar commit at '%s'" % commit)
  48. return commit
  49. return None
  50. def checkout(self, archive):
  51. """
  52. Checkout an orig archive from pristine-tar branch
  53. @param archive: the name of the orig archive
  54. @type archive: C{str}
  55. """
  56. self.run_error = 'Pristine-tar couldn\'t checkout "%s": {stderr}' % os.path.basename(archive)
  57. self.__call__(['checkout', archive])
  58. def commit(self, archive, upstream):
  59. """
  60. Commit an archive I{archive} to the pristine tar branch using upstream
  61. branch ${upstream}.
  62. @param archive: the archive to commit
  63. @type archive: C{str}
  64. @param upstream: the upstream branch to diff against
  65. @type upstream: C{str}
  66. """
  67. self.run_error = ("Couldn't commit to '%s' with upstream '%s': {stderr}" %
  68. (self.branch, upstream))
  69. self.__call__(['commit', archive, upstream])