[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH 5/6] Move all the important stuff out of the KickstartCommand.parse methods.



> > +    def add(self, obj):
> > +        if isinstance(obj, KickstartCommand):
> > +            # Commands can only be run once, and the latest one seen takes
> > +            # precedence over any earlier ones.
> > +            i = 0
> > +            while i < len(self._dataObjs):
> > +                if self._dataObjs[i].__class__ == obj.__class__:
> > +                    break
> > +
> > +                i += 1
> > +
> > +            if i == len(self._dataObjs):
> > +                self._dataObjs.append(obj)
> > +            else:
> > +                self._dataObjs[i] = obj
> 
> Shouldn't this instead remove the now-obsolete earlier command from the
> list and then append the new one to the end of the list? As it stands,
> you're not really preserving the ordering.

Yes, yes it should.  Good catch.  So, add should look more like this:

def add(self, obj):
    if isinstance(obj, KickstartCommand):
        # Commands can only be run once, and the latest one seen takes
        # precedence over any earlier ones.
        i = 0
        while i < len(self._dataObjs):
            if self._dataObjs[i].__class__ == obj.__class__:
                self._dataObjs.pop(i)
                break

            i += 1

        self._dataObjs.append(obj)
    ...


- Chris


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]