summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/fetch/hg.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/hg.py')
-rw-r--r--bitbake-dev/lib/bb/fetch/hg.py141
1 files changed, 141 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/fetch/hg.py b/bitbake-dev/lib/bb/fetch/hg.py
new file mode 100644
index 0000000000..ee3bd2f7fe
--- /dev/null
+++ b/bitbake-dev/lib/bb/fetch/hg.py
@@ -0,0 +1,141 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake '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
27import os, re
28import sys
29import bb
30from bb import data
31from bb.fetch import Fetch
32from bb.fetch import FetchError
33from bb.fetch import MissingParameterError
34from bb.fetch import runfetchcmd
35
36class Hg(Fetch):
37 """Class to fetch a from mercurial repositories"""
38 def supports(self, url, ud, d):
39 """
40 Check to see if a given url can be fetched with mercurial.
41 """
42 return ud.type in ['hg']
43
44 def localpath(self, url, ud, d):
45 if not "module" in ud.parm:
46 raise MissingParameterError("hg method needs a 'module' parameter")
47
48 ud.module = ud.parm["module"]
49
50 # Create paths to mercurial checkouts
51 relpath = ud.path
52 if relpath.startswith('/'):
53 # Remove leading slash as os.path.join can't cope
54 relpath = relpath[1:]
55 ud.pkgdir = os.path.join(data.expand('${HGDIR}', d), ud.host, relpath)
56 ud.moddir = os.path.join(ud.pkgdir, ud.module)
57
58 if 'rev' in ud.parm:
59 ud.revision = ud.parm['rev']
60
61 ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d)
62
63 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
64
65 def _buildhgcommand(self, ud, d, command):
66 """
67 Build up an hg commandline based on ud
68 command is "fetch", "update", "info"
69 """
70
71 basecmd = data.expand('${FETCHCMD_hg}', d)
72
73 proto = "http"
74 if "proto" in ud.parm:
75 proto = ud.parm["proto"]
76
77 host = ud.host
78 if proto == "file":
79 host = "/"
80 ud.host = "localhost"
81
82 hgroot = host + ud.path
83
84 if command is "info":
85 return "%s identify -i %s://%s/%s" % (basecmd, proto, hgroot, ud.module)
86
87 options = [];
88 if ud.revision:
89 options.append("-r %s" % ud.revision)
90
91 if command is "fetch":
92 cmd = "%s clone %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, hgroot, ud.module, ud.module)
93 elif command is "pull":
94 cmd = "%s pull %s" % (basecmd, " ".join(options))
95 elif command is "update":
96 cmd = "%s update -C %s" % (basecmd, " ".join(options))
97 else:
98 raise FetchError("Invalid hg command %s" % command)
99
100 return cmd
101
102 def go(self, loc, ud, d):
103 """Fetch url"""
104
105 # try to use the tarball stash
106 if Fetch.try_mirror(d, ud.localfile):
107 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping hg checkout." % ud.localpath)
108 return
109
110 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + ud.moddir + "'")
111
112 if os.access(os.path.join(ud.moddir, '.hg'), os.R_OK):
113 updatecmd = self._buildhgcommand(ud, d, "pull")
114 bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc)
115 # update sources there
116 os.chdir(ud.moddir)
117 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % updatecmd)
118 runfetchcmd(updatecmd, d)
119
120 updatecmd = self._buildhgcommand(ud, d, "update")
121 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % updatecmd)
122 runfetchcmd(updatecmd, d)
123 else:
124 fetchcmd = self._buildhgcommand(ud, d, "fetch")
125 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
126 # check out sources there
127 bb.mkdirhier(ud.pkgdir)
128 os.chdir(ud.pkgdir)
129 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % fetchcmd)
130 runfetchcmd(fetchcmd, d)
131
132 os.chdir(ud.pkgdir)
133 try:
134 runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d)
135 except:
136 t, v, tb = sys.exc_info()
137 try:
138 os.unlink(ud.localpath)
139 except OSError:
140 pass
141 raise t, v, tb