Please find below a patch adding a clearcase fetcher to bitbake. Usage: see comments in clearcase.py
Review / comments are welcome Signed-off-by: Fabrice Aeschbacher <[email protected]> --- lib/bb/fetch/__init__.py | 2 ++ lib/bb/fetch/clearcase.py | 267 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+), 0 deletions(-) create mode 100644 lib/bb/fetch/clearcase.py diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py index f7b06f3..e034078 100644 --- a/lib/bb/fetch/__init__.py +++ b/lib/bb/fetch/__init__.py @@ -769,6 +769,7 @@ import bzr import hg import osc import repo +import clearcase methods.append(local.Local()) methods.append(wget.Wget()) @@ -782,3 +783,4 @@ methods.append(bzr.Bzr()) methods.append(hg.Hg()) methods.append(osc.Osc()) methods.append(repo.Repo()) +methods.append(clearcase.Clearcase()) diff --git a/lib/bb/fetch/clearcase.py b/lib/bb/fetch/clearcase.py new file mode 100644 index 0000000..486206c --- /dev/null +++ b/lib/bb/fetch/clearcase.py @@ -0,0 +1,267 @@ +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- + +""" +BitBake 'Fetch' implementation for clearcase. + + +The clearcase fetcher is used to retrieve files from a ClearCase repository + +Usage: + + SRC_URI="ccase://cc.server.org/trunk;vob=myvob;module=app/dir1;label=MYLABEL_1.0;proto=http" +or: + SRC_URI="ccrc://cc.server.org/trunk;vob=myvob;module=app/dir1;label=MYLABEL_1.0;proto=http" + +The fetcher uses following clearcase client: + - if SRC_URI="ccase://..." => use native client (cleartool) + - if SRC_URI="ccrc://..." => use remote client (rcleartool) + +Supported options: + + vob (required) The name of the clearcase VOB + Creates following load rule in the view config spec: + load /<vob> + + module Load only this sub-directory from the VOB by + creating following load rule in the view config spec: + load /<vob>/<module> + + label Download this label (default: LATEST) + + proto http or https + + file single file (value ignored) + + +Related variables: + + CCASE_USERNAME The username to access the ClearCase server (ccrc only) + CCASE_PASSWORD The password to access the ClearCase server (ccrc only) + + +Note (ccrc only): CCASE_USERNAME and CCASE_PASSWORD must be exported and added +to BB_ENV_EXTRAWHITE, or bitbake will ignore them + + +""" + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +import os, sys, shutil +import bb +from bb import data +from bb.fetch import Fetch +from bb.fetch import FetchError +from bb.fetch import MissingParameterError +from bb.fetch import runfetchcmd + + +class Clearcase(Fetch): + def supports(self, url, ud, d): + """ + Check to see if a given url can be fetched with Clearcase. + """ + return ud.type in ['ccase', 'ccrc'] + + def debug(self, msg): + bb.msg.debug(1, bb.msg.domain.Fetcher, msg) + + def note(self, msg): + bb.msg.note(1, bb.msg.domain.Fetcher, msg) + + def warn(self, msg): + bb.msg.warn(1, msg) + + def error(self, msg): + bb.msg.error(1, bb.msg.domain.Fetcher, msg) + + + def localpath(self, url, ud, d): + + if ud.type == 'ccrc': + self.username = data.getVar("CCASE_USERNAME", d, True) + self.password = data.getVar("CCASE_PASSWORD", d, True) + self.ccrccli = data.getVar("CCRCCLI", d, True) + + if not self.username: + raise MissingParameterError("CCASE_USERNAME environment variable not defined") + + if not self.password: + self.warn("CCASE_PASSWORD environment variable not defined") + + if not self.ccrccli: + self.ccrccli = "/opt/rational/ccrccli" + self.warn("CCRCCLI environment variable not defined, using default (%s)" % self.ccrccli) + + ud.proto = "http" + if 'proto' in ud.parm: + ud.proto = ud.parm['proto'] + + ud.vob = "" + if 'vob' in ud.parm: + ud.vob = ud.parm['vob'] + + ud.module = "" + if 'module' in ud.parm: + ud.module = ud.parm['module'] + + ud.label = "LATEST" + if 'label' in ud.parm: + ud.label = ud.parm['label'] + + ud.file = False + if 'file' in ud.parm: + ud.file = True + + ud.server = "%s://%s%s" % (ud.proto, ud.host, ud.path) + ud.viewname = "bitbake_%s_%s" % (ud.type, str(os.getpid())) + ud.csname = "config_spec_%s" % str(os.getpid()) + + ud.ccasedir = os.path.join(data.getVar("DL_DIR", d, True), ud.type) + ud.viewdir = os.path.join(ud.ccasedir, ud.viewname) + ud.configspec = os.path.join(data.expand('${WORKDIR}', d), ud.csname) + + if ud.file: + ud.localfile = "ccase_" + ud.label + "_" + os.path.basename(ud.module) + else: + ud.localfile = ud.vob + "_" + ud.label + ".tar.gz" + + self.debug("username = %s" % self.username) +# self.debug("password = %s" % self.password) + self.debug("host = %s" % ud.host) + self.debug("path = %s" % ud.path) + self.debug("server = %s" % ud.server) + self.debug("proto = %s" % ud.proto) + self.debug("type = %s" % ud.type) + self.debug("vob = %s" % ud.vob) + self.debug("module = %s" % ud.module) + self.debug("label = %s" % ud.label) + self.debug("ccasedir = %s" % ud.ccasedir) + self.debug("viewdir = %s" % ud.viewdir) + self.debug("viewname = %s" % ud.viewname) + self.debug("configspec = %s" % ud.configspec) + self.debug("localfile = %s" % ud.localfile) + + return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) + + + def _build_ccase_command(self, ud, command): + """ + Build up a commandline based on ud + command is: mkview, edcs, rmview + """ + + if ud.type == 'ccrc': + basecmd = "CCRCCLI=%s rcleartool %s" % (self.ccrccli, command) + elif ud.type == 'ccase': + basecmd = "cleartool %s" % (command) + else: + raise FetchError("Invalid client type: %s" % ud.type) + + options = [] + + if ud.type == 'ccrc': + options.append("-username '%s'" % self.username) + options.append("-password '%s'" % self.password) + options.append("-server '%s'" % ud.server) + + if command is 'mkview': + if ud.type == 'ccrc': + options.append("-tag %s" % ud.viewname) + options.append(ud.viewdir) + elif ud.type == 'ccase': + options.append("-snapshot -tag %s -colocated_server %s" % (ud.viewname, ud.viewdir)) + + elif command is 'rmview': + options.append("-force") + if ud.type == 'ccrc': + options.append("-tag %s" % ud.viewname) + elif ud.type == 'ccase': + options.append("%s" % ud.viewdir) + + elif command is 'edcs': + basecmd = "export EDITOR='cp %s '; echo 'yes' | %s" % (ud.configspec, basecmd) + + else: + raise FetchError("Invalid ccase (rcleartool) command %s" % command) + + ccasecmd = "%s %s" % (basecmd, " ".join(options)) + self.debug("ccasecmd = %s" % ccasecmd) + return ccasecmd + + + def _create_configspec(self, ud): + """ + Create config spec file (ud.configspec) for ccase view + """ + try: + f = open(ud.configspec, 'w') + f.write("element * CHECKEDOUT\n") + f.write("element /%s /main/LATEST\n" % ud.vob) + f.write("element * %s\n" % ud.label) + f.write("load /%s\n" % os.path.join(ud.vob, ud.module)) + f.close() + except: + self.error("error creating %s" % ud.configspec) + pass + + def go(self, loc, ud, d): + """Fetch files""" + + # create directory $DL_DIR/ccase + bb.mkdirhier(ud.ccasedir) + # create directory $WORKDIR [ TODO: is this mandatory here? ] + bb.mkdirhier(data.expand('${WORKDIR}', d)) + + # Create config spec for clearcase view + self._create_configspec(ud) + + # Make view + cmd = self._build_ccase_command(ud, 'mkview'); + self.note("clearcase: creating view [VOB=%s label=%s view=%s]" % (ud.vob, ud.label, ud.viewname)) + runfetchcmd(cmd, d, True) + + try: + # edit config spec => fetch files + os.chdir(ud.viewdir) + cmd = self._build_ccase_command(ud, 'edcs'); + self.note("clearcase: fetching data [VOB=%s label=%s view=%s]" % (ud.vob, ud.label, ud.viewname)) + runfetchcmd(cmd, d, True) + + if ud.file: + cmd = "cp %s %s" % (os.path.join(ud.vob, ud.module), ud.localpath) + else: + # create tarfile + cmd = "tar -zcf %s %s" % (ud.localpath, ud.vob) + + self.debug("clearcase: creating download file: %s" % cmd) + + runfetchcmd(cmd, d, True) + os.chdir(ud.ccasedir) + + finally: + try: + # Remove view + cmd = self._build_ccase_command(ud, 'rmview'); + self.note("clearcase: cleaning up [VOB=%s label=%s view=%s]" % (ud.vob, ud.label, ud.viewname)) + runfetchcmd(cmd, d, True) + + finally: + # Cleanup + cmd = "rm -rf %s" % ud.viewdir + runfetchcmd(cmd, d, True) + + return True -- 1.7.2.3 _______________________________________________ Bitbake-dev mailing list [email protected] https://lists.berlios.de/mailman/listinfo/bitbake-dev
