[Yum-devel] a lot of api breaking, I think

Tim Lauridsen tim at rasmil.dk
Fri Jan 27 17:55:24 UTC 2006


On Fri, 2006-01-27 at 09:29 -0500, Tim Lauridsen wrote:
> 
> I like 3. best, what about change po.repoid to return po.repo.id
> directly by adding a __get__ method to the package object, like it is
> done in the Option Classes.
> 
> I would be smart in the YumAvailablePackage class, where a __get__
> class
> could be used to return tag from the rpm header directly and don't
> have
> to have a local copy of fx. name,arch,ver,description etc.
> 
> Tim
> 

It is not a _get_ but a _getattr_ method.

Here is a example from yumex, here i no longer need to store copies of
attributes contained in the pkg object by using at __getattr__ method.

class yumexPackage( object ):
    """ This class contains a yumPackage and some extra features used by
    yumex """
    
    def __init__( self, pkg, recentlimit, avail=True ):
        self.pkg = pkg
        self.selected = False
        self.visible = True
        self.availible = avail
        #self.name = self.pkg.name
        self.ver = self.pkg.printVer()
        #self.arch = self.pkg.arch
        #self.repoid = self.pkg.repoid
        #self.description = self.pkg.returnSimple( 'description' )
        #self.summary = self.pkg.returnSimple( 'summary' )
        self.summaryFirst =
self._toUTF(self.pkg.returnSimple( 'summary' ).splitlines()[0])
        self.size = pkg.size()
        self.sizeKB = "%06d" % ( float( self.size )/ 1024.0 )
        self.time = self._get_time()
        if self.time > recentlimit:
            self.recent = True
        else:
            self.recent = False
 
    def __getattr__(self,attr):
	# Check for pkg object attributes.
        if attr in ('name','arch','repoid','description','summary'):
            return self.pkg.returnSimple(attr)
        # Check for local object attributes.
        elif attr in self.__dict__.keys():
            return self.__dict__.get(attr)
        else: raise AttributeError, attr

..
..
..

Tim




More information about the Yum-devel mailing list