gitannex.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. """
  4. BitBake 'Fetch' git annex implementation
  5. """
  6. # Copyright (C) 2014 Otavio Salvador
  7. # Copyright (C) 2014 O.S. Systems Software LTDA.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License version 2 as
  11. # published by the Free Software Foundation.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. import os
  22. import bb
  23. from bb import data
  24. from bb.fetch2.git import Git
  25. from bb.fetch2 import runfetchcmd
  26. from bb.fetch2 import logger
  27. class GitANNEX(Git):
  28. def supports(self, ud, d):
  29. """
  30. Check to see if a given url can be fetched with git.
  31. """
  32. return ud.type in ['gitannex']
  33. def uses_annex(self, ud, d):
  34. for name in ud.names:
  35. try:
  36. runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True)
  37. return True
  38. except bb.fetch.FetchError:
  39. pass
  40. return False
  41. def update_annex(self, ud, d):
  42. try:
  43. runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True)
  44. except bb.fetch.FetchError:
  45. return False
  46. runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True)
  47. return True
  48. def download(self, ud, d):
  49. Git.download(self, ud, d)
  50. os.chdir(ud.clonedir)
  51. annex = self.uses_annex(ud, d)
  52. if annex:
  53. self.update_annex(ud, d)
  54. def unpack(self, ud, destdir, d):
  55. Git.unpack(self, ud, destdir, d)
  56. os.chdir(ud.destdir)
  57. try:
  58. runfetchcmd("%s annex sync" % (ud.basecmd), d)
  59. except bb.fetch.FetchError:
  60. pass
  61. annex = self.uses_annex(ud, d)
  62. if annex:
  63. runfetchcmd("%s annex get" % (ud.basecmd), d)
  64. runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True)