def __init__(self, *args, **kwargs): self.help_output = sys.stdout if kwargs.has_key("help_output"): self.help_output = kwargs["help_output"] del kwargs["help_output"] kwargs["option_class"] = FallBackOption OptionParser.__init__(self, *args, **kwargs) #IGNORE:W0142 self._create_command_list() Log.addDefaultLogger(self) Env.addEnvironment(self)
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 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 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 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 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 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]