diff options
Diffstat (limited to 'bitbake/lib/bb/fetch/hg.py')
| -rw-r--r-- | bitbake/lib/bb/fetch/hg.py | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/bitbake/lib/bb/fetch/hg.py b/bitbake/lib/bb/fetch/hg.py deleted file mode 100644 index 2b3aec543b..0000000000 --- a/bitbake/lib/bb/fetch/hg.py +++ /dev/null | |||
| @@ -1,180 +0,0 @@ | |||
| 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' implementation for mercurial DRCS (hg). | ||
| 5 | |||
| 6 | """ | ||
| 7 | |||
| 8 | # Copyright (C) 2003, 2004 Chris Larson | ||
| 9 | # Copyright (C) 2004 Marcin Juszkiewicz | ||
| 10 | # Copyright (C) 2007 Robert Schuster | ||
| 11 | # | ||
| 12 | # This program is free software; you can redistribute it and/or modify | ||
| 13 | # it under the terms of the GNU General Public License version 2 as | ||
| 14 | # published by the Free Software Foundation. | ||
| 15 | # | ||
| 16 | # This program is distributed in the hope that it will be useful, | ||
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | # GNU General Public License for more details. | ||
| 20 | # | ||
| 21 | # You should have received a copy of the GNU General Public License along | ||
| 22 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 24 | # | ||
| 25 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
| 26 | |||
| 27 | import os | ||
| 28 | import sys | ||
| 29 | import logging | ||
| 30 | import bb | ||
| 31 | from bb import data | ||
| 32 | from bb.fetch import Fetch | ||
| 33 | from bb.fetch import FetchError | ||
| 34 | from bb.fetch import MissingParameterError | ||
| 35 | from bb.fetch import runfetchcmd | ||
| 36 | from bb.fetch import logger | ||
| 37 | |||
| 38 | class Hg(Fetch): | ||
| 39 | """Class to fetch from mercurial repositories""" | ||
| 40 | def supports(self, url, ud, d): | ||
| 41 | """ | ||
| 42 | Check to see if a given url can be fetched with mercurial. | ||
| 43 | """ | ||
| 44 | return ud.type in ['hg'] | ||
| 45 | |||
| 46 | def forcefetch(self, url, ud, d): | ||
| 47 | revTag = ud.parm.get('rev', 'tip') | ||
| 48 | return revTag == "tip" | ||
| 49 | |||
| 50 | def localpath(self, url, ud, d): | ||
| 51 | if not "module" in ud.parm: | ||
| 52 | raise MissingParameterError("hg method needs a 'module' parameter") | ||
| 53 | |||
| 54 | ud.module = ud.parm["module"] | ||
| 55 | |||
| 56 | # Create paths to mercurial checkouts | ||
| 57 | relpath = self._strip_leading_slashes(ud.path) | ||
| 58 | ud.pkgdir = os.path.join(data.expand('${HGDIR}', d), ud.host, relpath) | ||
| 59 | ud.moddir = os.path.join(ud.pkgdir, ud.module) | ||
| 60 | |||
| 61 | if 'rev' in ud.parm: | ||
| 62 | ud.revision = ud.parm['rev'] | ||
| 63 | else: | ||
| 64 | tag = Fetch.srcrev_internal_helper(ud, d) | ||
| 65 | if tag is True: | ||
| 66 | ud.revision = self.latest_revision(url, ud, d) | ||
| 67 | elif tag: | ||
| 68 | ud.revision = tag | ||
| 69 | else: | ||
| 70 | ud.revision = self.latest_revision(url, ud, d) | ||
| 71 | |||
| 72 | ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d) | ||
| 73 | |||
| 74 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
| 75 | |||
| 76 | def _buildhgcommand(self, ud, d, command): | ||
| 77 | """ | ||
| 78 | Build up an hg commandline based on ud | ||
| 79 | command is "fetch", "update", "info" | ||
| 80 | """ | ||
| 81 | |||
| 82 | basecmd = data.expand('${FETCHCMD_hg}', d) | ||
| 83 | |||
| 84 | proto = ud.parm.get('proto', 'http') | ||
| 85 | |||
| 86 | host = ud.host | ||
| 87 | if proto == "file": | ||
| 88 | host = "/" | ||
| 89 | ud.host = "localhost" | ||
| 90 | |||
| 91 | if not ud.user: | ||
| 92 | hgroot = host + ud.path | ||
| 93 | else: | ||
| 94 | hgroot = ud.user + "@" + host + ud.path | ||
| 95 | |||
| 96 | if command is "info": | ||
| 97 | return "%s identify -i %s://%s/%s" % (basecmd, proto, hgroot, ud.module) | ||
| 98 | |||
| 99 | options = []; | ||
| 100 | if ud.revision: | ||
| 101 | options.append("-r %s" % ud.revision) | ||
| 102 | |||
| 103 | if command is "fetch": | ||
| 104 | cmd = "%s clone %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, hgroot, ud.module, ud.module) | ||
| 105 | elif command is "pull": | ||
| 106 | # do not pass options list; limiting pull to rev causes the local | ||
| 107 | # repo not to contain it and immediately following "update" command | ||
| 108 | # will crash | ||
| 109 | cmd = "%s pull" % (basecmd) | ||
| 110 | elif command is "update": | ||
| 111 | cmd = "%s update -C %s" % (basecmd, " ".join(options)) | ||
| 112 | else: | ||
| 113 | raise FetchError("Invalid hg command %s" % command) | ||
| 114 | |||
| 115 | return cmd | ||
| 116 | |||
| 117 | def go(self, loc, ud, d): | ||
| 118 | """Fetch url""" | ||
| 119 | |||
| 120 | logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'") | ||
| 121 | |||
| 122 | if os.access(os.path.join(ud.moddir, '.hg'), os.R_OK): | ||
| 123 | updatecmd = self._buildhgcommand(ud, d, "pull") | ||
| 124 | logger.info("Update " + loc) | ||
| 125 | # update sources there | ||
| 126 | os.chdir(ud.moddir) | ||
| 127 | logger.debug(1, "Running %s", updatecmd) | ||
| 128 | runfetchcmd(updatecmd, d) | ||
| 129 | |||
| 130 | else: | ||
| 131 | fetchcmd = self._buildhgcommand(ud, d, "fetch") | ||
| 132 | logger.info("Fetch " + loc) | ||
| 133 | # check out sources there | ||
| 134 | bb.utils.mkdirhier(ud.pkgdir) | ||
| 135 | os.chdir(ud.pkgdir) | ||
| 136 | logger.debug(1, "Running %s", fetchcmd) | ||
| 137 | runfetchcmd(fetchcmd, d) | ||
| 138 | |||
| 139 | # Even when we clone (fetch), we still need to update as hg's clone | ||
| 140 | # won't checkout the specified revision if its on a branch | ||
| 141 | updatecmd = self._buildhgcommand(ud, d, "update") | ||
| 142 | os.chdir(ud.moddir) | ||
| 143 | logger.debug(1, "Running %s", updatecmd) | ||
| 144 | runfetchcmd(updatecmd, d) | ||
| 145 | |||
| 146 | scmdata = ud.parm.get("scmdata", "") | ||
| 147 | if scmdata == "keep": | ||
| 148 | tar_flags = "" | ||
| 149 | else: | ||
| 150 | tar_flags = "--exclude '.hg' --exclude '.hgrags'" | ||
| 151 | |||
| 152 | os.chdir(ud.pkgdir) | ||
| 153 | try: | ||
| 154 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d) | ||
| 155 | except: | ||
| 156 | t, v, tb = sys.exc_info() | ||
| 157 | try: | ||
| 158 | os.unlink(ud.localpath) | ||
| 159 | except OSError: | ||
| 160 | pass | ||
| 161 | raise t, v, tb | ||
| 162 | |||
| 163 | def supports_srcrev(self): | ||
| 164 | return True | ||
| 165 | |||
| 166 | def _latest_revision(self, url, ud, d): | ||
| 167 | """ | ||
| 168 | Compute tip revision for the url | ||
| 169 | """ | ||
| 170 | output = runfetchcmd(self._buildhgcommand(ud, d, "info"), d) | ||
| 171 | return output.strip() | ||
| 172 | |||
| 173 | def _build_revision(self, url, ud, d): | ||
| 174 | return ud.revision | ||
| 175 | |||
| 176 | def _revision_key(self, url, ud, d): | ||
| 177 | """ | ||
| 178 | Return a unique key for the url | ||
| 179 | """ | ||
| 180 | return "hg:" + ud.moddir | ||
