On 06/03/11 11:29, Danek Duvall wrote:
Shawn Walker wrote:

http://cr.opensolaris.org/~swalker/pkg-fmt/

pkgfmt.py:

   - line 121: you're reindenting the last line here of a set of continued
     lines, but you didn't reindent any previous ones.

Fixed.

   - line 212ff: how does this put summary before description?

Because of the order of comparison of the attributes:

#!/usr/bin/python2.6

import pkg.actions as acts

alist = [
    acts.fromstr("set name=pkg.description value=bar"),
    acts.fromstr("set name=pkg.zoo value=zebra"),
    acts.fromstr("set name=pkg.summary value=foo"),
]

def cmpactions(a, b):
        for attr in ("pkg.summary", "pkg.description"):
                if (a.name == "set" and
                    a.attrs["name"] == attr and
                    not b.attrs["name"] == attr):
                        print "attr %s a < b (%s, %s)" % (attr, a, b)
                        return -1
                if (b.name == "set" and
                    b.attrs["name"] == attr and
                    not a.attrs["name"] == attr):
                        print "attr %s a > b (%s, %s)" % (attr, a, b)
                        return 1

print "unsorted"
print "\n".join(str(s) for s in alist)
print ""
print "sort [desc, zoo, summary]"
print "\n".join(str(s) for s in sorted(alist, cmp=cmpactions))
print ""
print "sort [summary, zoo, desc]"
print "\n".join(str(s) for s in sorted(reversed(alist), cmp=cmpactions))
print ""


$ python /tmp/my.py
unsorted
set name=pkg.description value=bar
set name=pkg.zoo value=zebra
set name=pkg.summary value=foo

sort [desc, zoo, summary]
attr pkg.description a > b (set name=pkg.zoo value=zebra, set name=pkg.description value=bar) attr pkg.summary a < b (set name=pkg.summary value=foo, set name=pkg.zoo value=zebra) attr pkg.summary a < b (set name=pkg.summary value=foo, set name=pkg.zoo value=zebra) attr pkg.summary a < b (set name=pkg.summary value=foo, set name=pkg.description value=bar)
set name=pkg.summary value=foo
set name=pkg.description value=bar
set name=pkg.zoo value=zebra

sort [summary, zoo, desc]
attr pkg.summary a > b (set name=pkg.zoo value=zebra, set name=pkg.summary value=foo) attr pkg.description a < b (set name=pkg.description value=bar, set name=pkg.zoo value=zebra) attr pkg.description a < b (set name=pkg.description value=bar, set name=pkg.zoo value=zebra) attr pkg.summary a > b (set name=pkg.description value=bar, set name=pkg.summary value=foo)
set name=pkg.summary value=foo
set name=pkg.description value=bar
set name=pkg.zoo value=zebra




If there's a simpler way to do this, I'm happy to change it.

...
   - line 377: why isn't the first comparison "<  2"?  If the first line has
     no attributes on it, which is a common occurrence, then we'll still
     wrap weirdly.

I don't believe that to be the case. In particular, with the new changes, no attributes on the first line should no longer be a common occurrence. However, since it expresses my intent just as well, I can change it.

     Also, what happens if we have a hash value; does that increment
     first_attr_count?  It should probably count as an attribute for these
     purposes.

Changed.

...
t_pkgfmt.py:

   - where is "needs_formatting" used?

Fixed.

http://cr.opensolaris.org/~swalker/pkg-fmt-1-2/

pkgfmt.py:

   - line 435: do you really want to run cmp_aliases on all attributes, not
     just alias attributes?

Fixed.

   - line 443-449, 452-458: aren't these two blocks identical?  Shouldn't
     there just be one instance after the if/else?

This has to be done for each value of an attribute, so needs to be done in both cases. However, since formatting doesn't have to be speedy, I've condensed this logic down to being the same for both single and multi-value attribute cases by forcing the attribute value to always be a list.

updated webrev (diff against 2nd):
  https://cr.opensolaris.org/action/browse/pkg/swalker/pkg-fmt-2-3/webrev/

-Shawn
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to