summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/osc.py
diff options
context:
space:
mode:
authorYu Ke <ke.yu@intel.com>2011-01-10 14:23:36 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-01-10 14:23:36 +0000
commit4dccd92439f3b21056c53f2317249228067defe6 (patch)
treeb5507598213381b870f53b3f816102b0b2899b86 /bitbake/lib/bb/fetch2/osc.py
parentf46cdcbbae0ac3cbce423d262358e670add6065e (diff)
downloadpoky-4dccd92439f3b21056c53f2317249228067defe6.tar.gz
bitbake: copy bb.fetch to bb.fetch2 as initial code base for fetcher overhaul
Signed-off-by: Yu Ke <ke.yu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/osc.py')
-rw-r--r--bitbake/lib/bb/fetch2/osc.py143
1 files changed, 143 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/osc.py b/bitbake/lib/bb/fetch2/osc.py
new file mode 100644
index 0000000000..26820967a3
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/osc.py
@@ -0,0 +1,143 @@
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 osc (Opensuse build service client).
5Based on the svn "Fetch" implementation.
6
7"""
8
9import os
10import sys
11import logging
12import bb
13from bb import data
14from bb.fetch import Fetch
15from bb.fetch import FetchError
16from bb.fetch import MissingParameterError
17from bb.fetch import runfetchcmd
18
19class Osc(Fetch):
20 """Class to fetch a module or modules from Opensuse build server
21 repositories."""
22
23 def supports(self, url, ud, d):
24 """
25 Check to see if a given url can be fetched with osc.
26 """
27 return ud.type in ['osc']
28
29 def localpath(self, url, ud, d):
30 if not "module" in ud.parm:
31 raise MissingParameterError("osc method needs a 'module' parameter.")
32
33 ud.module = ud.parm["module"]
34
35 # Create paths to osc checkouts
36 relpath = self._strip_leading_slashes(ud.path)
37 ud.pkgdir = os.path.join(data.expand('${OSCDIR}', d), ud.host)
38 ud.moddir = os.path.join(ud.pkgdir, relpath, ud.module)
39
40 if 'rev' in ud.parm:
41 ud.revision = ud.parm['rev']
42 else:
43 pv = data.getVar("PV", d, 0)
44 rev = Fetch.srcrev_internal_helper(ud, d)
45 if rev and rev != True:
46 ud.revision = rev
47 else:
48 ud.revision = ""
49
50 ud.localfile = data.expand('%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.path.replace('/', '.'), ud.revision), d)
51
52 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
53
54 def _buildosccommand(self, ud, d, command):
55 """
56 Build up an ocs commandline based on ud
57 command is "fetch", "update", "info"
58 """
59
60 basecmd = data.expand('${FETCHCMD_osc}', d)
61
62 proto = ud.parm.get('proto', 'ocs')
63
64 options = []
65
66 config = "-c %s" % self.generate_config(ud, d)
67
68 if ud.revision:
69 options.append("-r %s" % ud.revision)
70
71 coroot = self._strip_leading_slashes(ud.path)
72
73 if command is "fetch":
74 osccmd = "%s %s co %s/%s %s" % (basecmd, config, coroot, ud.module, " ".join(options))
75 elif command is "update":
76 osccmd = "%s %s up %s" % (basecmd, config, " ".join(options))
77 else:
78 raise FetchError("Invalid osc command %s" % command)
79
80 return osccmd
81
82 def go(self, loc, ud, d):
83 """
84 Fetch url
85 """
86
87 logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'")
88
89 if os.access(os.path.join(data.expand('${OSCDIR}', d), ud.path, ud.module), os.R_OK):
90 oscupdatecmd = self._buildosccommand(ud, d, "update")
91 logger.info("Update "+ loc)
92 # update sources there
93 os.chdir(ud.moddir)
94 logger.debug(1, "Running %s", oscupdatecmd)
95 runfetchcmd(oscupdatecmd, d)
96 else:
97 oscfetchcmd = self._buildosccommand(ud, d, "fetch")
98 logger.info("Fetch " + loc)
99 # check out sources there
100 bb.mkdirhier(ud.pkgdir)
101 os.chdir(ud.pkgdir)
102 logger.debug(1, "Running %s", oscfetchcmd)
103 runfetchcmd(oscfetchcmd, d)
104
105 os.chdir(os.path.join(ud.pkgdir + ud.path))
106 # tar them up to a defined filename
107 try:
108 runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d)
109 except:
110 t, v, tb = sys.exc_info()
111 try:
112 os.unlink(ud.localpath)
113 except OSError:
114 pass
115 raise t, v, tb
116
117 def supports_srcrev(self):
118 return False
119
120 def generate_config(self, ud, d):
121 """
122 Generate a .oscrc to be used for this run.
123 """
124
125 config_path = os.path.join(data.expand('${OSCDIR}', d), "oscrc")
126 if (os.path.exists(config_path)):
127 os.remove(config_path)
128
129 f = open(config_path, 'w')
130 f.write("[general]\n")
131 f.write("apisrv = %s\n" % ud.host)
132 f.write("scheme = http\n")
133 f.write("su-wrapper = su -c\n")
134 f.write("build-root = %s\n" % data.expand('${WORKDIR}', d))
135 f.write("urllist = http://moblin-obs.jf.intel.com:8888/build/%(project)s/%(repository)s/%(buildarch)s/:full/%(name)s.rpm\n")
136 f.write("extra-pkgs = gzip\n")
137 f.write("\n")
138 f.write("[%s]\n" % ud.host)
139 f.write("user = %s\n" % ud.parm["user"])
140 f.write("pass = %s\n" % ud.parm["pswd"])
141 f.close()
142
143 return config_path