def base(self, cmtpath=None, cmtprojectpath=None): self._setCMTPathEnv(cmtpath, cmtprojectpath) if self._baselist is None: self._baselist = Set() wdir = os.path.join(self.fullLocation(), "cmt") if not os.path.exists(wdir): wdir = self.fullLocation() os.chdir(wdir) env = Env.getDefaultEnv() env["PWD"] = wdir parentlist = [] p = Popen(["cmt", "show", "projects"], stdout=PIPE, stderr=PIPE, close_fds=True) for line in p.stdout: if re.compile("^" + self.__name()).match(line): parmatch = re.compile("C=[a-zA-Z]+").findall(line) for w in parmatch: parentlist.append(w.replace("C=", "")) elif parentlist: for par in parentlist: if re.compile("\s+" + par).match(line): m = re.compile("\(in\s+(.+)\s*\)").search(line) if m: self._baselist.add(self.__class__(m.group(1))) for line in p.stderr: Common.CMTLog(line[:-1]) os.waitpid(p.pid, 0)[1] return self._baselist
def getSetValue(self, set_name): here = os.getcwd() log = logging.getLogger() wdir = os.path.join(self.fullLocation(), "cmt") env = Env.getDefaultEnv() env["PWD"] = wdir os.chdir(wdir) p = Popen(["cmt", "show", "set_value", set_name], stdout=PIPE, stderr=PIPE, close_fds=True) set_val = p.stdout.read()[:-1] for line in p.stderr: Common.CMTLog(line[:-1]) retcode = os.waitpid(p.pid, 0)[1] if retcode != 0: log.debug("return code of 'cmt show set_value %s' in %s is %s" % (set_name, wdir, retcode)) os.chdir(here) return set_val
def versionCMT(self): """ Get the version of the package given by "cmt show version" """ log = logging.getLogger() if self._version is None: wdir = os.path.join(self.fullLocation(), "cmt") os.chdir(wdir) env = Env.getDefaultEnv() env["PWD"] = wdir p = Popen(["cmt", "show", "version"], stdout=PIPE, stderr=PIPE, close_fds=True) for line in p.stdout: self._version = line[:-1] for line in p.stderr: Common.CMTLog(line[:-1]) retcode = os.waitpid(p.pid, 0)[1] if retcode != 0: log.warning("return code of 'cmt show version' in %s is %s", wdir, retcode) return self._version
def __name(self): # internal name, not to be overridden by subclasses log = logging.getLogger() if self._name is None: env = Env.getDefaultEnv() wdir = os.path.join(self.fullLocation(), "cmt") if not os.path.exists(wdir): # special case for CMTUSERCONTEXT wdir = self.fullLocation() os.chdir(wdir) env["PWD"] = wdir p = Popen(["cmt", "show", "projects"], stdout=PIPE, stderr=PIPE, close_fds=True) line = p.stdout.readline()[:-1] self._name = line.split()[0] for line in p.stderr: Common.CMTLog(line[:-1]) retcode = os.waitpid(p.pid, 0)[1] if retcode != 0: log.warning("return code of 'cmt show projects' in %s is %s", wdir, retcode) return self._name
def parentProjectPath(self): log = logging.getLogger() if self._parentprojectpath is None: if self._parentproject: self._parentprojectpath = self._parentproject.fullLocation() else: wdir = self.fullLocation() os.chdir(wdir) env = Env.getDefaultEnv() env["PWD"] = wdir p = Popen(["cmt", "show", "projects"], stdout=PIPE, stderr=PIPE, close_fds=True) for line in p.stdout: line = line[:-1] if line.find("(current)") != -1: m = re.compile(".+\(in\s+(.+)\s*\)\s*\(\s*current\s*\)" ).search(line) if m: self._parentprojectpath = os.path.realpath( m.group(1)) # words = line.split() # self._parentprojectpath = os.path.realpath(words[-2].replace(")","")) for line in p.stderr: Common.CMTLog(line[:-1]) retcode = os.waitpid(p.pid, 0)[1] if retcode != 0: log.warning( "return code of 'cmt show project' in %s is %s", wdir, retcode) return self._parentprojectpath
def binaryUsedPackages(self, cmtpath=None, cmtprojectpath=None, binary="default"): env = Env.getDefaultEnv() log = logging.getLogger() self._setCMTPathEnv(cmtpath, cmtprojectpath) if binary == "default": if env.has_key("CMTCONFIG"): del env["CMTCONFIG"] # ensures that no cmtconfig is set else: env["CMTCONFIG"] = binary if binary.find("win32") != -1 and sys.platform != "win32": Common.addCMTTag("WIN32", env) if self._usedpaklist is None: self._usedpaklist = dict() if self._allusedpaklist is None: self._allusedpaklist = Set() indx = cmtpath, cmtprojectpath, binary if not self._usedpaklist.has_key(indx): self._usedpaklist[indx] = Set() if not self._usedpaklist[indx]: packagelist = Set() wdir = os.path.join(self.fullLocation(), "cmt") os.chdir(wdir) env["PWD"] = wdir p = Popen(["cmt", "show", "uses"], stdout=PIPE, stderr=PIPE, close_fds=True) for line in p.stdout: if not line.startswith("#"): thepack = None line = line.replace("(no_auto_imports)", "").replace("(", "").replace(")", "") words = line[:-1].split() words = words[1:] if words[-1].endswith("/"): words[-1] = words[-1][:-1] pakpath = "" parentprojectpath = words[-1] if len(words) == 4: pakpath = os.path.join(words[3], words[2], words[0]) elif len(words) == 3: pakpath = os.path.join(words[2], words[0]) if isPackage(pakpath): thepack = pakpath else: pakpath = os.path.join(pakpath, words[1]) if isPackage(pakpath): thepack = pakpath if thepack: tmpack = self.__class__( thepack, parentprojectpath=parentprojectpath) if tmpack in self._allusedpaklist: for a in self._allusedpaklist: if a == tmpack: a.addUsedByBinary(binary) packagelist.add(a) break else: packagelist.add( self.__class__( thepack, parentprojectpath=parentprojectpath)) for line in p.stderr: Common.CMTLog(line[:-1]) retcode = os.waitpid(p.pid, 0)[1] if retcode != 0: log.warning("return code of 'cmt show uses' in %s is %s", wdir, retcode) for pak in packagelist: if binary == "default": self._usedpaklist[indx].add(pak) self._allusedpaklist.add(pak) else: # if pak.hasBinaryConstituents(binary): self._usedpaklist[indx].add(pak) self._allusedpaklist.add(pak) return self._usedpaklist[indx]