def __init__(self, path, root='/', create=False, callback=None): NoopJobJournal.__init__(self) # normpath leaves a leading // (probably for windows?) self.path = path self.root = self._normpath(root) if root: self.rootLen = len(self.root) else: self.rootLen = 0 self.hSize = struct.calcsize("!H") self.hdrSize = struct.calcsize("!BH") if callback is None: self.callback = callbacks.UpdateCallback() else: self.callback = callback if create: self.immutable = False self.fd = os.open(path, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0600) os.write(self.fd, struct.pack("!H", JOURNAL_VERSION)) else: self.immutable = True self.fd = os.open(path, os.O_RDONLY) ver = struct.unpack("!H", os.read(self.fd, self.hSize))[0] assert (ver == JOURNAL_VERSION)
def doUpdate(cfg, changeSpecs, **kwargs): callback = kwargs.get('callback', None) if not callback: callback = callbacks.UpdateCallback(trustThreshold=cfg.trustThreshold) kwargs['callback'] = callback else: callback.setTrustThreshold(cfg.trustThreshold) syncChildren = kwargs.get('syncChildren', False) syncUpdate = kwargs.pop('syncUpdate', False) restartInfo = kwargs.get('restartInfo', None) if syncChildren or syncUpdate: installMissing = True else: installMissing = False kwargs['installMissing'] = installMissing fromChangesets = [] for path in kwargs.pop('fromFiles', []): cs = changeset.ChangeSetFromFile(path) fromChangesets.append(cs) kwargs['fromChangesets'] = fromChangesets # Look for items which look like files in the applyList and convert # them into fromChangesets w/ the primary sets for item in changeSpecs[:]: if os.access(item, os.R_OK): try: cs = changeset.ChangeSetFromFile(item) except: continue fromChangesets.append(cs) changeSpecs.remove(item) for troveTuple in cs.getPrimaryTroveList(): changeSpecs.append(trovetup.TroveTuple(*troveTuple).asString()) if kwargs.get('restartInfo', None): # We don't care about applyList, we will set it later applyList = None else: keepExisting = kwargs.get('keepExisting') updateByDefault = kwargs.get('updateByDefault', True) applyList = cmdline.parseChangeList(changeSpecs, keepExisting, updateByDefault, allowChangeSets=True) _updateTroves(cfg, applyList, **kwargs) # Clean up after ourselves if restartInfo: util.rmtree(restartInfo, ignore_errors=True)
def __init__(self, sysmod=None, callback=None): self.conaryClientFactory = ConaryClientFactory self._sysmodel = None self._client = None self._newSystemModel = None self._contents = sysmod if self._contents: self._newSystemModel = [x for x in self._contents.split('\n') if x] self._manifest = None self._cfg = conarycfg.ConaryConfiguration(True) self._callback = callback if not callback: self._callback = callbacks.UpdateCallback( trustThreshold=self._cfg.trustThreshold) else: self._callback.setTrustThreshold(self._cfg.trustThreshold)
def setUp(self): rephelp.RepositoryHelper.setUp(self) self.openRepository() self._conaryClient = self.getConaryClient() self._conaryClient.setUpdateCallback(conaryCallbacks.UpdateCallback()) # Create a Conary client that can talk to the testsuite repo class ConaryClientFactory(installation_service.ConaryClientFactory): def getClient(slf): return self._conaryClient installation_service.InstallationService.conaryClientFactory = ConaryClientFactory storagePath = os.path.join(self.workDir, "storage") self.mock(installation_service.UpdateSet, "storagePath", storagePath) self.mock(concrete_job.UpdateJob, "storagePath", storagePath) testbase.ProviderMixIn.setUp(self)
def testDefaultErrorWarning(self): cb = callbacks.UpdateCallback() msg = "message 1" tb = "Traceback: foo\n bar\n baz\n" logFilter = testcase.LogFilter() logFilter.add() cb.warning(msg) logFilter.compare('warning: ' + msg) logFilter.clear() logFilter.add() cb.error(msg) logFilter.compare('error: ' + msg) logFilter.clear() logFilter.add() cb.error(msg) logFilter.compare('error: ' + msg) logFilter.clear() # Tracebacks logFilter.add() cb.error(msg, exc_text=tb) logFilter.compare('error: ' + msg + '\n' + tb) logFilter.clear() # Errors with formatting msg1 = "Some text with %s, %s and %s" args = ("one", "two", "three") logFilter.add() cb.error(msg1, exc_text=tb, *args) logFilter.compare('error: ' + (msg1 % args) + '\n' + tb) logFilter.clear()
def _applyModel(self, modelList, addSearchLabel=True, apply=True, useCache=None): cachePath = os.path.join(self.workDir, 'modelcache') from conary import callbacks client = conaryclient.ConaryClient( self.cfg, updateCallback=callbacks.UpdateCallback()) model = cml.CML(self.cfg) cache = modelupdate.CMLTroveCache(client.getDatabase(), client.getRepos()) if useCache and os.path.exists(cachePath): cache.load(cachePath) if addSearchLabel: updatedModel = list(modelList) updatedModel.insert(0, 'search localhost@rpl:linux') else: updatedModel = modelList model.parse(updatedModel) updJob = client.newUpdateJob() ts = client.cmlGraph(model) suggMap = client._updateFromTroveSetGraph(updJob, ts, cache) if useCache: cache.save(cachePath) if not apply: return ts client.applyUpdateJob(updJob) return updJob, suggMap
def doModelUpdate(cfg, sysmodel, modelFile, otherArgs, **kwargs): kwargs['systemModel'] = sysmodel kwargs['systemModelFile'] = modelFile kwargs['loadTroveCache'] = True kwargs.setdefault('updateByDefault', True) # erase is not default case kwargs.setdefault('model', False) kwargs.setdefault('keepExisting', True) # prefer "install" to "update" restartInfo = kwargs.get('restartInfo', None) patchArgs = kwargs.pop('patchSpec', None) fromChangesets = [] applyList = [] callback = kwargs.get('callback', None) if not callback: callback = callbacks.UpdateCallback(trustThreshold=cfg.trustThreshold) kwargs['callback'] = callback else: callback.setTrustThreshold(cfg.trustThreshold) if restartInfo is None: addArgs = [x[1:] for x in otherArgs if x.startswith('+')] rmArgs = [x[1:] for x in otherArgs if x.startswith('-')] defArgs = [x for x in otherArgs if not (x.startswith('+') or x.startswith('-'))] # find any default arguments that represent changesets to # install/update for defArg in list(defArgs): if kwargs['updateByDefault'] and os.path.isfile(defArg): try: cs = changeset.ChangeSetFromFile(defArg) fromChangesets.append((cs, defArg)) defArgs.remove(defArg) except filecontainer.BadContainer: # not a changeset, must be a trove name pass if kwargs['updateByDefault']: addArgs += defArgs else: rmArgs += defArgs if rmArgs: sysmodel.appendOpByName('erase', text=rmArgs) updateName = { False: 'update', True: 'install' }[kwargs['keepExisting']] branchArgs = {} for index, spec in enumerate(addArgs): try: troveSpec = trovetup.TroveSpec(spec) version = versions.Label(troveSpec.version) branchArgs[troveSpec] = index except: # Any exception is a parse failure in one of the # two steps, and so we do not convert that argument pass if branchArgs: client = conaryclient.ConaryClient(cfg) repos = client.getRepos() foundTroves = repos.findTroves(cfg.installLabelPath, branchArgs.keys(), defaultFlavor = cfg.flavor) for troveSpec in foundTroves: index = branchArgs[troveSpec] foundTrove = foundTroves[troveSpec][0] addArgs[index] = addArgs[index].replace( troveSpec.version, '%s/%s' %(foundTrove[1].trailingLabel(), foundTrove[1].trailingRevision())) disallowedChangesets = [] for cs, argName in fromChangesets: for troveTuple in cs.getPrimaryTroveList(): # group and redirect changesets will break the model the # next time it is run, so prevent them from getting in # the model in the first place if troveTuple[1].isOnLocalHost(): if troveTuple[0].startswith('group-'): disallowedChangesets.append((argName, 'group', trovetup.TroveTuple(*troveTuple).asString())) continue trvCs = cs.getNewTroveVersion(*troveTuple) if trvCs.getType() == trove.TROVE_TYPE_REDIRECT: disallowedChangesets.append((argName, 'redirect', trovetup.TroveTuple(*troveTuple).asString())) continue addArgs.append( trovetup.TroveTuple(*troveTuple).asString()) if disallowedChangesets: raise errors.ConaryError( 'group and redirect changesets on a local label' ' cannot be installed:\n ' + '\n '.join( '%s contains local %s: %s' % x for x in disallowedChangesets)) if addArgs: sysmodel.appendOpByName(updateName, text=addArgs) if patchArgs: sysmodel.appendOpByName('patch', text=patchArgs) kwargs['fromChangesets'] = [x[0] for x in fromChangesets] if kwargs.pop('model'): sysmodel.write(sys.stdout) sys.stdout.flush() return None keepExisting = kwargs.get('keepExisting') updateByDefault = kwargs.get('updateByDefault', True) applyList = cmdline.parseChangeList([], keepExisting, updateByDefault, allowChangeSets=True) else: # In the restart case, applyList == [] which says "sync to model" pass _updateTroves(cfg, applyList, **kwargs) # Clean up after ourselves if restartInfo: util.rmtree(restartInfo, ignore_errors=True)