gitannex.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. BitBake 'Fetch' git annex implementation
  3. """
  4. # Copyright (C) 2014 Otavio Salvador
  5. # Copyright (C) 2014 O.S. Systems Software LTDA.
  6. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. import bb
  10. from bb.fetch2.git import Git
  11. from bb.fetch2 import runfetchcmd
  12. class GitANNEX(Git):
  13. def supports(self, ud, d):
  14. """
  15. Check to see if a given url can be fetched with git.
  16. """
  17. return ud.type in ['gitannex']
  18. def urldata_init(self, ud, d):
  19. super(GitANNEX, self).urldata_init(ud, d)
  20. if ud.shallow:
  21. ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*']
  22. def uses_annex(self, ud, d, wd):
  23. for name in ud.names:
  24. try:
  25. runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd)
  26. return True
  27. except bb.fetch.FetchError:
  28. pass
  29. return False
  30. def update_annex(self, ud, d, wd):
  31. try:
  32. runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd)
  33. except bb.fetch.FetchError:
  34. return False
  35. runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd)
  36. return True
  37. def download(self, ud, d):
  38. Git.download(self, ud, d)
  39. if not ud.shallow or ud.localpath != ud.fullshallow:
  40. if self.uses_annex(ud, d, ud.clonedir):
  41. self.update_annex(ud, d, ud.clonedir)
  42. def clone_shallow_local(self, ud, dest, d):
  43. super(GitANNEX, self).clone_shallow_local(ud, dest, d)
  44. try:
  45. runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest)
  46. except bb.fetch.FetchError:
  47. pass
  48. if self.uses_annex(ud, d, dest):
  49. runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest)
  50. runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest)
  51. def unpack(self, ud, destdir, d):
  52. Git.unpack(self, ud, destdir, d)
  53. try:
  54. runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir)
  55. except bb.fetch.FetchError:
  56. pass
  57. annex = self.uses_annex(ud, d, ud.destdir)
  58. if annex:
  59. runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir)
  60. runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir)