def runCommand(self, thisCommand, cfg, argSet, args, debugAll=False): client = conaryclient.ConaryClient(cfg) repos = client.getRepos() callback = commit.CheckinCallback(cfg) if not cfg.buildLabel and cfg.installLabelPath: cfg.buildLabel = cfg.installLabelPath[0] sys.excepthook = util.genExcepthook(debug=cfg.debugExceptions, debugCtrlC=debugAll) if cfg.installLabelPath: cfg.installLabel = cfg.installLabelPath[0] else: cfg.installLabel = None cfg.initializeFlavors() log.setMinVerbosity(log.INFO) log.resetErrorOccurred() # set the build flavor here, just to set architecture information # which is used when initializing a recipe class use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, error=False) profile = False if argSet.has_key('lsprof'): import cProfile prof = cProfile.Profile() prof.enable() profile = 'lsprof' del argSet['lsprof'] keyCache = openpgpkey.getKeyCache() keyCache.setPublicPath(cfg.pubRing) repos = conaryclient.ConaryClient(cfg).getRepos() keyCacheCallback = openpgpkey.KeyCacheCallback(repos, cfg) keyCache.setCallback(keyCacheCallback) try: rv = options.MainHandler.runCommand(self, thisCommand, cfg, argSet, args, callback=callback, repos=client.getRepos(), profile=profile) finally: if profile == 'lsprof': prof.disable() prof.dump_stats('cvc.lsprof') prof.print_stats() elif profile: prof.stop() if log.errorOccurred(): sys.exit(2) return rv
def testLogWithObject(self): log.resetErrorOccurred() log.setVerbosity(2) foo = object() fooString = str(foo) self.logCheck(log.error, (foo,), "error: %s" % fooString) assert(log.errorOccurred()) self.logCheck(log.warning, (foo,), "warning: %s" % fooString) self.logCheck(log.debug, (foo,), "+ %s" % fooString) self.logCheck(log.info, (foo,), "+ %s" % fooString)
def testLogMinVerbosity(self): log.resetErrorOccurred() log.setVerbosity(log.ERROR) self.logCheck(log.warning, ("a warning",), []) assert(not log.setMinVerbosity(log.ERROR)) self.logCheck(log.warning, ("a warning",), []) assert(log.setMinVerbosity(log.WARNING) == log.ERROR) self.logCheck(log.warning, ("a warning",), ["warning: a warning"]) assert(not log.setMinVerbosity(log.ERROR)) self.logCheck(log.warning, ("a warning",), ["warning: a warning"])
def testLogWithObject(self): log.resetErrorOccurred() log.setVerbosity(2) foo = object() fooString = str(foo) self.logCheck(log.error, (foo, ), "error: %s" % fooString) assert (log.errorOccurred()) self.logCheck(log.warning, (foo, ), "warning: %s" % fooString) self.logCheck(log.debug, (foo, ), "+ %s" % fooString) self.logCheck(log.info, (foo, ), "+ %s" % fooString)
def testLogMinVerbosity(self): log.resetErrorOccurred() log.setVerbosity(log.ERROR) self.logCheck(log.warning, ("a warning", ), []) assert (not log.setMinVerbosity(log.ERROR)) self.logCheck(log.warning, ("a warning", ), []) assert (log.setMinVerbosity(log.WARNING) == log.ERROR) self.logCheck(log.warning, ("a warning", ), ["warning: a warning"]) assert (not log.setMinVerbosity(log.ERROR)) self.logCheck(log.warning, ("a warning", ), ["warning: a warning"])
def testLog(self): log.resetErrorOccurred() self.logCheck(log.warning, ("a warning",), "warning: a warning") self.logCheck(log.debug, ("a debug",), []) assert(not log.errorOccurred()) log.setVerbosity(2) self.logCheck(log.warning, ("a warning",), "warning: a warning") self.logCheck(log.debug, ("a debug",), "+ a debug") log.setVerbosity(0) self.logCheck(log.warning, ("a warning",), "warning: a warning") self.logCheck(log.debug, ("a debug",), []) assert(not log.errorOccurred()) self.logCheck(log.error, ("an error",), "error: an error") assert(log.errorOccurred())
def testLog(self): log.resetErrorOccurred() self.logCheck(log.warning, ("a warning", ), "warning: a warning") self.logCheck(log.debug, ("a debug", ), []) assert (not log.errorOccurred()) log.setVerbosity(2) self.logCheck(log.warning, ("a warning", ), "warning: a warning") self.logCheck(log.debug, ("a debug", ), "+ a debug") log.setVerbosity(0) self.logCheck(log.warning, ("a warning", ), "warning: a warning") self.logCheck(log.debug, ("a debug", ), []) assert (not log.errorOccurred()) self.logCheck(log.error, ("an error", ), "error: an error") assert (log.errorOccurred())
def testLogWithPercentChar(self): log.resetErrorOccurred() log.setVerbosity(2) fooString = "Some message with a %s char in it" self.logCheck(log.error, (fooString,), "error: %s" % fooString) assert(log.errorOccurred()) self.logCheck(log.warning, (fooString,), "warning: %s" % fooString) self.logCheck(log.debug, (fooString,), "+ %s" % fooString) self.logCheck(log.info, (fooString,), "+ %s" % fooString) fooString = "This %s work" arg1 = "does" efooString = fooString % arg1 self.logCheck(log.error, (fooString, arg1), "error: %s" % efooString) assert(log.errorOccurred()) self.logCheck(log.warning, (fooString, arg1), "warning: %s" % efooString) self.logCheck(log.debug, (fooString, arg1), "+ %s" % efooString) self.logCheck(log.info, (fooString, arg1), "+ %s" % efooString)
def testLogWithPercentChar(self): log.resetErrorOccurred() log.setVerbosity(2) fooString = "Some message with a %s char in it" self.logCheck(log.error, (fooString, ), "error: %s" % fooString) assert (log.errorOccurred()) self.logCheck(log.warning, (fooString, ), "warning: %s" % fooString) self.logCheck(log.debug, (fooString, ), "+ %s" % fooString) self.logCheck(log.info, (fooString, ), "+ %s" % fooString) fooString = "This %s work" arg1 = "does" efooString = fooString % arg1 self.logCheck(log.error, (fooString, arg1), "error: %s" % efooString) assert (log.errorOccurred()) self.logCheck(log.warning, (fooString, arg1), "warning: %s" % efooString) self.logCheck(log.debug, (fooString, arg1), "+ %s" % efooString) self.logCheck(log.info, (fooString, arg1), "+ %s" % efooString)
def _commitRecipe(conaryclient, cfg, recipePath, message, branch=None): repos = conaryclient.getRepos() conaryCompat = compat.ConaryVersion() recipeClass, pathList = _getPathList(repos, cfg, recipePath) sourceName = recipeClass.name + ':source' log.info("Creating a copy of %s in the rMake internal repository..." % recipeClass.name) cwd = os.getcwd() recipeDir = tempfile.mkdtemp() log.resetErrorOccurred() try: fileNames = [] # Create a source trove that matches the recipe we're trying to cook if not branch: branch = versions.Branch([cfg.buildLabel]) targetLabel = cfg.getTargetLabel(branch) if compat.ConaryVersion().supportsNewPkgBranch(): buildBranch = branch.createShadow(targetLabel) kw = dict(buildBranch=buildBranch) else: buildBranch = versions.Branch([targetLabel]) kw={} cfg.buildLabel = targetLabel if not repos.getTroveLeavesByBranch( { sourceName : { buildBranch : None } }).get(sourceName, None): # we pass it None for repos to avoid the label-based check for # existing packages. checkin.newTrove(None, cfg, recipeClass.name, dir=recipeDir, **kw) else: # see if this package exists on our build branch checkin.checkout(repos, cfg, recipeDir, ['%s=%s' % (sourceName, buildBranch)]) os.chdir(recipeDir) sourceState = state.ConaryStateFromFile(recipeDir + '/CONARY').getSourceState() fileNames = dict((os.path.basename(x), x) for x in pathList) for (pathId, baseName, fileId, version) in list(sourceState.iterFileList()): # update or remove any currently existing files if baseName not in fileNames: sourceState.removeFilePath(baseName) else: shutil.copyfile(fileNames[baseName], os.path.join(recipeDir, baseName)) del fileNames[baseName] for baseName, path in fileNames.iteritems(): shutil.copyfile(path, os.path.join(recipeDir, baseName)) if conaryCompat.stateFileVersion() > 0: # mark all the files as binary - this this version can # never be checked in, it doesn't really matter, but # conary likes us to give a value. for fileName in fileNames: isConfig = _getConfigInfo(fileName) checkin.addFiles([fileName], binary=not isConfig, text=isConfig) else: checkin.addFiles(fileNames) _doCommit(recipePath, repos, cfg, 'Temporary recipe build for rmake') newState = conaryCompat.ConaryStateFromFile(recipeDir + '/CONARY', repos=repos) return newState.getSourceState().getNameVersionFlavor() finally: os.chdir(cwd) shutil.rmtree(recipeDir)
def _shadowAndCommit(conaryclient, cfg, recipeDir, stateFile, message): repos = conaryclient.getRepos() conaryCompat = compat.ConaryVersion() oldSourceVersion = stateFile.getVersion() targetLabel = cfg.getTargetLabel(oldSourceVersion) if not targetLabel: raise errors.RmakeError( 'Cannot cook local recipes unless a target label is set') skipped, cs = conaryclient.createShadowChangeSet(str(targetLabel), [stateFile.getNameVersionFlavor()]) recipePath = recipeDir + '/' + stateFile.getName().split(':')[0] + '.recipe' recipeClass, pathList = _getPathList(repos, cfg, recipePath, relative=True) troveName = stateFile.getName() troveVersion = stateFile.getVersion() if not skipped: signAbsoluteChangeset(cs, None) repos.commitChangeSet(cs) log.info("Shadowing %s to internal repository..." % troveName) shadowBranch = troveVersion.createShadow(targetLabel).branch() shadowVersion = repos.findTrove(None, (troveName, str(shadowBranch), None), None)[0][1] cwd = os.getcwd() prefix = 'rmake-shadow-%s-' % troveName.split(':')[0] shadowSourceDir = tempfile.mkdtemp(prefix=prefix) try: log.info("Committing local changes to %s to the" " internal repository..." % troveName) log.resetErrorOccurred() checkin.checkout(repos, cfg, shadowSourceDir, ['%s=%s' % (troveName, shadowVersion)]) if compat.ConaryVersion().stateFileVersion() > 0: kw = dict(repos=repos) else: kw = {} # grab new and old state and make any modifications due to adding # or deleting of files (we assume files that don't exist are # autosource and can be ignored) oldState = conaryCompat.ConaryStateFromFile(recipeDir + '/CONARY', repos=repos).getSourceState() newConaryState = conaryCompat.ConaryStateFromFile( shadowSourceDir + '/CONARY', repos=repos) newState = newConaryState.getSourceState() neededFiles = set(x[1] for x in oldState.iterFileList() if os.path.exists(os.path.join(recipeDir, x[1]))) neededFiles.update(pathList) autoSourceFiles = set(x[1] for x in oldState.iterFileList() if oldState.fileIsAutoSource(x[0])) existingFiles = set(x[1] for x in newState.iterFileList() if os.path.exists(os.path.join(shadowSourceDir, x[1]))) toCopy = neededFiles & existingFiles toDel = existingFiles - neededFiles toAdd = neededFiles - existingFiles for sourceFile in (toCopy | toAdd): newPath = os.path.join(shadowSourceDir, sourceFile) if os.path.dirname(sourceFile): util.mkdirChain(os.path.dirname(newPath)) if os.path.isdir(sourceFile): util.mkdirChain(newPath) else: shutil.copyfile(os.path.join(recipeDir, sourceFile), newPath) os.chdir(shadowSourceDir) if hasattr(cfg.sourceSearchDir, '_getUnexpanded'): cfg.configKey('sourceSearchDir', cfg.sourceSearchDir._getUnexpanded()) for f in toDel: checkin.removeFile(f) if toDel: # toDel modifies the CONARY file on disk, so reload with the # changes made there. newState = conaryCompat.ConaryStateFromFile( shadowSourceDir + '/CONARY', repos=repos).getSourceState() if conaryCompat.stateFileVersion() == 0: checkin.addFiles(toAdd) else: oldPathIds = dict((x[1], x[0]) for x in oldState.iterFileList()) for path in toAdd: if path in oldPathIds: isConfig = oldState.fileIsConfig(oldPathIds[path]) else: isConfig = _getConfigInfo(path) checkin.addFiles([path], binary=not isConfig, text=isConfig) if toAdd: # get the new pathIDs for all the added troves, # since we can't set the refresh setting without the # needed pathIds newState = conaryCompat.ConaryStateFromFile( shadowSourceDir + '/CONARY', repos=repos).getSourceState() newPathIds = dict((x[1], x[0]) for x in newState.iterFileList()) for path in (toCopy | toAdd): if path in oldPathIds: isConfig = oldState.fileIsConfig(oldPathIds[path]) else: isConfig = _getConfigInfo(path) newState.fileIsConfig(newPathIds[path], isConfig) for path in autoSourceFiles: if path in newPathIds: needsRefresh = oldState.fileNeedsRefresh(oldPathIds[path]) newState.fileNeedsRefresh(newPathIds[path], needsRefresh) # if the factory changed, update it if newState.getFactory() != oldState.getFactory(): newState.setFactory(oldState.getFactory()) # we may have modified the state file. Write it back out to # disk so it will be picked up by the commit. newConaryState.setSourceState(newState) newConaryState.write(shadowSourceDir + '/CONARY') if message is None and compat.ConaryVersion().supportsCloneCallback(): message = 'Automated rMake commit' _doCommit('%s/%s' % (recipeDir, troveName), repos, cfg, message) newState = state.ConaryStateFromFile(shadowSourceDir + '/CONARY', **kw) return newState.getSourceState().getNameVersionFlavor() finally: os.chdir(cwd) if hasattr(cfg.sourceSearchDir, '_getUnexpanded'): cfg.configKey('sourceSearchDir', cfg.sourceSearchDir._getUnexpanded()) shutil.rmtree(shadowSourceDir)