Viewing file: headers.py (1.79 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python
# class defination for the HeaderList and maybe Header objects? # # Ideally, this will include it's own memory and disk caching, so # that the retrieveal classes can be made more generic # # $Id: headers.py,v 1.9 2003/10/08 02:35:22 alikins Exp $
import sys import rpcServer import repoDirector import rpmSource
# we do all the list to tuple munging here. I dont want # to have to force it at a higher level, and I dont want # headerCache to have to care class HeaderList: _cache = rpmSource.HeaderCache() def __init__(self): self.repos = repoDirector.initRepoDirector() pass
def cache(self): return id(self._cache)
# items are in the format of a tuple of format # (name, version, release, epoch, arch) def __getitem__(self,item): itemtuple = tuple(item[:5]) if self._cache.has_key(itemtuple): return self._cache[itemtuple] else: self.__retrievePackage(item) return self._cache[itemtuple]
def __retrievePackage(self,item): # need to make sure headerSource isnt populating the cache as well hdr, sourceType = rpcServer.doCall(self.repos.getHeader, item) # always populate the cache when we fetch a package self._cache[tuple(item[:5])] = hdr
def __setitem__(self,item,value): self._cache[tuple(item[:5])] = value
def getLite(self, item): return self._cache.getLite(tuple(item[:5]))
def keys(self): return self._cache.keys()
def values(self): return self._cache.values()
def __delitem__(self, item): del self._cache[tuple(item[:5])]
def initHeaderList(): global hdlist
try: hdlist = hdlist except NameError: hdlist = HeaderList()
return hdlist
|