def binaryConstituents(self, binary="default"): log = logging.getLogger() env = Env.getDefaultEnv() 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._constituents is None: self._constituents = dict() if self._allconstituents is None: self._allconstituents = Set() if not self._constituents.has_key(binary): self._constituents[binary] = Set() if not self._constituents[binary]: const_val = self.getMacroValue("all_constituents") for c in const_val.split(): if c in self._allconstituents: for a in self._allconstituents: if a == c: self._constituents[binary].add(a) break else: self._constituents[binary].add(c) self._allconstituents.add(c) log.debug("Found %s constituents in %s for binary %s" % (len(self._constituents[binary]), self.name(), binary)) return self._constituents[binary]
def binaryExternalPackages(self, cmtprojectpath=None, cmtpath=None, binary="default"): env = Env.getDefaultEnv() 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._extpaklist is None: self._extpaklist = dict() if self._allextpaklist is None: self._allextpaklist = Set() indx = cmtpath, cmtprojectpath, binary if not self._extpaklist.has_key(indx): self._extpaklist[indx] = Set() if not self._extpaklist[indx]: for p in self.binaryUsedPackages(cmtpath, cmtprojectpath, binary): if self.parentProjectPath() != p.parentProjectPath(): self._allextpaklist.add(p) self._extpaklist[indx].add(p) return self._extpaklist[indx]
def walk(top, topdown=True, toclients=False, onerror=None, alreadyfound=None, cmtpath=None, cmtprojectpath=None, light=False): if not alreadyfound: alreadyfound = Set() alreadyfound.add(top) proj = top if toclients: deps = proj.clients(cmtpath, cmtprojectpath) else: deps = proj.base(cmtpath, cmtprojectpath) if not light and proj.hasPackages(): packs = proj.packages() else: packs = Set() if topdown: yield (proj, deps, packs) for d in deps: if d not in alreadyfound: for w in walk(d, topdown, toclients, onerror, alreadyfound, cmtpath, cmtprojectpath): yield w if not topdown: yield (proj, deps, packs)
def getStartProjectsFromDir(self, directory=None, name=None, version=None, casesense=True, select=None): if self._startprojlist is None: self._startprojlist = Set() dirprojlist = Set() if directory is not None : dirprojlist.update(self.getProjectsFromDir(directory, name, version, casesense, select)) else : for d in self._projectpath.split(os.pathsep) : dirprojlist.update(self.getProjectsFromPath(d, name, version, casesense, select)) self._startprojlist.update(dirprojlist) return dirprojlist
def clients(self, cmtpath=None, cmtprojectpath=None): """ get all the client projects. Pretty slow. Use with care """ cmtprojectpath = self._setCMTPathEnv(cmtpath, cmtprojectpath) if self._clientlist is None: self._clientlist = Set() tmplist = Set() projectpath_list = cmtprojectpath.split(os.pathsep) for c in projectpath_list: tmplist |= getProjectsFromDir(directory=c, prjclass=self.__class__) for p in tmplist: for b in p.base(): if b == self: self._clientlist.add(p) return self._clientlist
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 getPackagesFromDir(directory, name=None, version=None, casesense=True, select=None, parentproject=None, pkgclass=Package): paklist = Set() log = logging.getLogger() try: for data in os.walk(directory): root, dirs = data[0], data[1] if isPackage(root): tobeadded = False if name is None: tobeadded = True elif Common.doesDirMatchNameAndVersion(root, name, version, casesense): tobeadded = True if select is not None and tobeadded: if Common.isDirSelected(root, select, casesense): tobeadded = True if tobeadded: tmpack = pkgclass(root, parentproject) paklist.add(tmpack) dirs[:] = [ ] # don't visit anything else: a CMT package cannot contains another one. else: if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories if '.svn' in dirs: dirs.remove('.svn') # don't visit .svn directories except OSError, msg: log.warning("Cannot open path %s" % msg)
def getAllProjects(cmtprojectpath, select=None): log = logging.getLogger() projlist = Set() pathcomponents = cmtprojectpath.split(os.pathsep) for p in pathcomponents: log.info("looking for projects in %s", p) pl = getProjectsFromPath(p, select=select) if pl: log.info("Found %s project in %s", len(pl), p) projlist |= pl return projlist
def getProjectsFromPath(self, directory, name=None, version=None, casesense=True, select=None): dirprojlist = getProjectsFromPath(directory, name=name, version=version, casesense=casesense, select=select, prjclass=self._prjclass) if self._projectlist is None : self._projectlist = Set() else : dirprojlist.override(self._projectlist) self._projectlist.update(dirprojlist) return dirprojlist
def binaryExternalPackages(self, cmtpath=None, cmtprojectpath=None, binary="default"): env = Env.getDefaultEnv() 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 self._extpaklist is None: self._extpaklist = dict() if self._allextpaklist is None: self._allextpaklist = Set() indx = cmtpath, cmtprojectpath, binary if not self._extpaklist.has_key(indx): self._extpaklist[indx] = Set() if not self._extpaklist[indx]: for p in self.binaryUsedPackages(cmtpath, cmtprojectpath, binary): if self.fullLocation() != p.parentProjectPath(): self._allextpaklist.add(p) self._extpaklist[indx].add(p) return self._extpaklist[indx]
def getProjectsFromPath(path, name=None, version=None, casesense=False, select=None, prjclass=Project): projlist = Set() log = logging.getLogger() try: lsdir = os.listdir(path) for f in lsdir: fullname = os.path.join(path, f) if isProject(fullname): tobeadded = False if Common.doesDirMatchNameAndVersion(fullname, name, version, casesense): tobeadded = True if select is not None and tobeadded: if Common.isDirSelected(fullname, select, casesense): tobeadded = True else: tobeadded = False if tobeadded: tmproj = prjclass(fullname) projlist.add(tmproj) log.debug("Found project at %s" % fullname) elif os.path.isdir(fullname): lsintdir = os.listdir(fullname) for ff in lsintdir: fn = os.path.join(fullname, ff) if isProject(fn): tobeadded = False if Common.doesDirMatchNameAndVersion( fn, name, version, casesense): tobeadded = True if select is not None and tobeadded: if Common.isDirSelected(fn, select, casesense): tobeadded = True else: tobeadded = False if tobeadded: tmproj = prjclass(fn) projlist.add(tmproj) log.debug("Found project at %s" % fn) except OSError, msg: log.warning("Cannot open path %s" % msg)
def FilterProjects(projlist, name=None, version=None, casesense=False): selected = Set() if not name and not version: return projlist # filter according to name and version if not casesense: name = name.upper() for p in projlist: if not casesense: prname = p.name().upper() else: prname = p.name() if prname == name: if not version: selected.add(p) else: if p.version() == version: selected.add(p) return selected
def binaryList(self): if self._binarylist is None: self._binarylist = Set() wdir = os.path.join(self.fullLocation(), "cmt") subfiles = os.listdir(wdir) # the "default" value is used when no CMTCONFIG is set tmplist = ["default"] for f in subfiles: if f.endswith(".make"): tmplist.append(f.replace(".make", "")) elif f == "NMake": tmplist.append("win32_") # verify that the binary directory exists for b in tmplist: topdirs = os.listdir(self.fullLocation()) if b in topdirs: self._binarylist.add(b) elif b == "win32_": for t in topdirs: if t.startswith(b): self._binarylist.add(t) return self._binarylist
def getProjectsFromDir(directory, name=None, version=None, casesense=True, select=None, prjclass=Project): projlist = Set() log = logging.getLogger() try: for data in os.walk(directory): root, dirs = data[0], data[1] log.debug("Entering directory %s" % root) if isProject(root): tobeadded = False tmproj = prjclass(root) if name is None: tobeadded = True elif Common.doesDirMatchNameAndVersion(root, name, version, casesense): tobeadded = True if select is not None and tobeadded: if Common.isDirSelected(root, select, casesense): tobeadded = True if tobeadded: projlist.add(tmproj) log.debug("Found project at %s" % root) dirs[:] = [ ] # don't visit anything else: a CMT package cannot contains another one. else: if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories if '.svn' in dirs: dirs.remove('.svn') for d in dirs: # don't visit hidden directories if d.startswith("."): dirs.remove(d) except OSError, msg: log.warning("Cannot open path %s" % msg)
def addPackage(self, pak): if self._packagelist is None: self._packagelist = Set() if pak.parentProjectPath() == self.fullLocation(): self._packagelist.add(pak)
def addUsedByBinary(self, binary): if self._usedbybinary is None: self._usedbybinary = Set() self._usedbybinary.add(binary)
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]
def updatePackages(self, paklist): if self._packagelist is None: self._packagelist = Set() for p in paklist: if p.parentProjectPath() == self.fullLocation(): self._packagelist.add(p)
def binaryList(self): if self._binarylist is None: self._binarylist = Set() for p in self.packages(): self._binarylist |= p.binaryList() return self._binarylist
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 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]: containedpackages = self.packages() if self.container() == "": log.warning("No container package found @ %s" % self.fullLocation()) log.warning("Parsing all packages for %s binary" % binary) for p in containedpackages: tmplist = p.binaryUsedPackages(cmtpath, cmtprojectpath, binary) # override the found packages by the one in the contained package list tmplist.override(containedpackages) # update the packages of the base projects for data in walk(top=self, cmtpath=cmtpath, cmtprojectpath=cmtprojectpath): deps = data[1] for b in deps: if b.hasPackages(): tmplist.override(b.packages()) b.updatePackages(tmplist) for t in tmplist: t.addUsedByBinary(binary) self._allusedpaklist |= tmplist self._usedpaklist[indx] |= tmplist else: log.info("Container package %s found @ %s" % (self.container(), self.fullLocation())) log.info("Extracting used packages for %s binary" % binary) for p in containedpackages: if p.name() == self.container(): tmplist = p.binaryUsedPackages(cmtpath, cmtprojectpath, binary) # override the found packages by the one in the contained package list tmplist.override(containedpackages) # update the packages of the base projects for data in walk(top=self, cmtpath=cmtpath, cmtprojectpath=cmtprojectpath): deps = data[1] for b in deps: if b.hasPackages(): tmplist.override(b.packages()) b.updatePackages(tmplist) for t in tmplist: t.addUsedByBinary(binary) self._allusedpaklist |= tmplist self._usedpaklist[indx] |= tmplist return self._usedpaklist[indx]