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