gitannex.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. # SPDX-License-Identifier: GPL-2.0-only
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License version 2 as
  13. # published by the Free Software Foundation.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. import os
  24. import bb
  25. from bb.fetch2.git import Git
  26. from bb.fetch2 import runfetchcmd
  27. from bb.fetch2 import logger
  28. class GitANNEX(Git):
  29. def supports(self, ud, d):
  30. """
  31. Check to see if a given url can be fetched with git.
  32. """
  33. return ud.type in ['gitannex']
  34. def urldata_init(self, ud, d):
  35. super(GitANNEX, self).urldata_init(ud, d)
  36. if ud.shallow:
  37. ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*']
  38. def uses_annex(self, ud, d, wd):
  39. for name in ud.names:
  40. try:
  41. runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd)
  42. return True
  43. except bb.fetch.FetchError:
  44. pass
  45. return False
  46. def update_annex(self, ud, d, wd):
  47. try:
  48. runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd)
  49. except bb.fetch.FetchError:
  50. return False
  51. runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd)
  52. return True
  53. def download(self, ud, d):
  54. Git.download(self, ud, d)
  55. if not ud.shallow or ud.localpath != ud.fullshallow:
  56. if self.uses_annex(ud, d, ud.clonedir):
  57. self.update_annex(ud, d, ud.clonedir)
  58. def clone_shallow_local(self, ud, dest, d):
  59. super(GitANNEX, self).clone_shallow_local(ud, dest, d)
  60. try:
  61. runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest)
  62. except bb.fetch.FetchError:
  63. pass
  64. if self.uses_annex(ud, d, dest):
  65. runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest)
  66. runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest)
  67. def unpack(self, ud, destdir, d):
  68. Git.unpack(self, ud, destdir, d)
  69. try:
  70. runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir)
  71. except bb.fetch.FetchError:
  72. pass
  73. annex = self.uses_annex(ud, d, ud.destdir)
  74. if annex:
  75. runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir)
  76. runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir)