gitannex.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. import os
  12. import bb
  13. from bb.fetch2.git import Git
  14. from bb.fetch2 import runfetchcmd
  15. from bb.fetch2 import logger
  16. class GitANNEX(Git):
  17. def supports(self, ud, d):
  18. """
  19. Check to see if a given url can be fetched with git.
  20. """
  21. return ud.type in ['gitannex']
  22. def urldata_init(self, ud, d):
  23. super(GitANNEX, self).urldata_init(ud, d)
  24. if ud.shallow:
  25. ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*']
  26. def uses_annex(self, ud, d, wd):
  27. for name in ud.names:
  28. try:
  29. runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd)
  30. return True
  31. except bb.fetch.FetchError:
  32. pass
  33. return False
  34. def update_annex(self, ud, d, wd):
  35. try:
  36. runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd)
  37. except bb.fetch.FetchError:
  38. return False
  39. runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd)
  40. return True
  41. def download(self, ud, d):
  42. Git.download(self, ud, d)
  43. if not ud.shallow or ud.localpath != ud.fullshallow:
  44. if self.uses_annex(ud, d, ud.clonedir):
  45. self.update_annex(ud, d, ud.clonedir)
  46. def clone_shallow_local(self, ud, dest, d):
  47. super(GitANNEX, self).clone_shallow_local(ud, dest, d)
  48. try:
  49. runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest)
  50. except bb.fetch.FetchError:
  51. pass
  52. if self.uses_annex(ud, d, dest):
  53. runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest)
  54. runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest)
  55. def unpack(self, ud, destdir, d):
  56. Git.unpack(self, ud, destdir, d)
  57. try:
  58. runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir)
  59. except bb.fetch.FetchError:
  60. pass
  61. annex = self.uses_annex(ud, d, ud.destdir)
  62. if annex:
  63. runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir)
  64. runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir)