[PATCH] Fix the Device.id usage.

Anne Mulhern amulhern at redhat.com
Wed Jan 22 15:32:13 UTC 2014





----- Original Message -----
> From: "David Shea" <dshea at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Tuesday, January 21, 2014 3:42:15 PM
> Subject: Re: [PATCH] Fix the Device.id usage.
> 
> On 01/21/2014 03:36 PM, Anne Mulhern wrote:
> >
> >
> >
> > ----- Original Message -----
> >> From: "David Lehman" <dlehman at redhat.com>
> >> To: "anaconda patch review" <anaconda-patches at lists.fedorahosted.org>
> >> Sent: Tuesday, January 21, 2014 3:30:24 PM
> >> Subject: Re: [PATCH] Fix the Device.id usage.
> >>
> >> On Tue, 2014-01-21 at 15:22 -0500, David Shea wrote:
> >>> Set the id for subclasses of ObjectID during __new__ so that the id is
> >>> available to subclasses during __init__.
> >>> ---
> >>>   blivet/devices.py | 4 ++--
> >>>   blivet/util.py    | 9 ++++++---
> >>>   2 files changed, 8 insertions(+), 5 deletions(-)
> >> Looks good to me.
> >>
> >>> diff --git a/blivet/devices.py b/blivet/devices.py
> >>> index adfc786..e1fde38 100644
> >>> --- a/blivet/devices.py
> >>> +++ b/blivet/devices.py
> >>> @@ -3925,7 +3925,7 @@ class LoopDevice(StorageDevice):
> >>>   
> >>>           if not name:
> >>>               # set up a temporary name until we've activated the loop
> >>>               device
> >>> -            name = "tmploop%d" % Device.id
> >>> +            name = "tmploop%d" % self.id
> >>>   
> >>>           StorageDevice.__init__(self, name, format=format, size=size,
> >>>                                  exists=True, parents=parents)
> >>> @@ -4338,7 +4338,7 @@ class BTRFSDevice(StorageDevice):
> >>>       def __init__(self, *args, **kwargs):
> >>>           """ Passing None or no name means auto-generate one like
> >>>           btrfs.%d
> >>>           """
> >>>           if not args or not args[0]:
> >>> -            args = ("btrfs.%d" % Device.id,)
> >>> +            args = ("btrfs.%d" % self.id,)
> >>>   
> >>>           if kwargs.get("parents") is None:
> >>>               raise ValueError("BTRFSDevice must have at least one
> >>>               parent")
> >>> diff --git a/blivet/util.py b/blivet/util.py
> >>> index 3c236a6..aed4a25 100644
> >>> --- a/blivet/util.py
> >>> +++ b/blivet/util.py
> >>> @@ -345,10 +345,13 @@ class ObjectID(object):
> >>>   
> >>>          The name of the identifier property is id, its type is int.
> >>>   
> >>> -       The constructor always sets object_id to a new value which is
> >>> unique
> >>> -       for the object type.
> >>> +       The id is set during creation of the class instance to a new
> >>> value
> >>> +       which is unique for the object type. Subclasses can use self.id
> >>> during
> >>> +       __init__.
> >>>       """
> >>>       _newid_gen = itertools.count().next
> >>>   
> >>> -    def __init__(self):
> >>> +    def __new__(cls, *args, **kwargs):
> >>> +        self = super(ObjectID, cls).__new__(cls, *args, **kwargs)
> >>>           self.id = self._newid_gen()
> >>> +        return self
> >>
> >> _______________________________________________
> >> anaconda-patches mailing list
> >> anaconda-patches at lists.fedorahosted.org
> >> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> >>
> > I'm not an expert on semantics of __new__, but won't the ObjectID.__init__
> > calls have to go away now?
> 
> We're better off keeping them, so in case we do change ObjectID to
> override __init__ again we don't need to change how it's used. Since
> ObjectID doesn't override __init__ anymore, calls to ObjectID.__init__
> will just go to object.__init__, which does nothing.

Ok. Sounds good. Thanks.

- mulhern

> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 


More information about the anaconda-patches mailing list