def runCommand(self, cfg, argSet, args, profile=False, callback=None, repos=None): args = args[1:] if len(args) < 2: return self.usage() for f in args[1:]: checkin.removeFile(f, repos=repos)
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)
def runCommand(self, cfg, argSet, args, profile = False, callback = None, repos = None): args = args[1:] if len(args) < 2: return self.usage() for f in args[1:]: checkin.removeFile(f, repos=repos)