sort builtin

2 views
Skip to first unread message

Hamish

unread,
Apr 17, 2008, 2:56:58 PM4/17/08
to Hotwire Shell
Hello, trying to write a sort builtin, but having some trouble getting
it to work. Hope it's reasonable to discuss this here rather than in
the issues.

So we have it accepting input from the pipeline and passing it on.
And it does alter the order, but not as I expect ...

I've uploaded it to the files section of this group (put it in hotwire/
builtins/ and add a line to the end of hotwire/builtin.py). My test
commands tend to look like

proc -a | sort owner_name | newline

newline means that the default renderer does not just do it's own
sorting (on a quick tangent, is there a way to tell the renderer what
order the objects should be in (or more precisely what property to
sort by, and whether to sort forward or reverse), other than clicking
on the column headers ... Be nice to be able to do the equivalent of
ls -t, ls -tr ... )

Does hotwire re-sort objects after they've left my function? Are
there other side effects at work? Have I misunderstood how the
functions should be passed to the sort function?

If I sort it out myself, I'll report back here ...

Hamish

unread,
Apr 18, 2008, 1:32:56 PM4/18/08
to Hotwire Shell
Sorted out sort :-) A couple of simple errors and some more reading
about python, lists and sorting did it. I've deleted the old sort and
uploaded the new one. I'll stick it on the issues list as well. Prob
should have done some more work before filling this group with
messages ...

So sort takes -r as reverse, and names of properties. It can take
more than one, eg

proc -a | sort owner_name cmd

and no newline is required for the ProcessRenderer, it produces the
output in the order that comes out of sort. The FilePathRenderer is
not so nice though. So I can test it works by eg

ls | sort mimetype | prop mimetype | newline

but I just do

ls | sort mimetype

the renderer re-sorts it into filename order. Not sure what the
options are here.

Hamish

unread,
Apr 18, 2008, 3:26:09 PM4/18/08
to Hotwire Shell
After reading a little more, should we be implementing __cmp__ methods
for things like Process and File objects?

See http://wiki.python.org/moin/HowTo/Sorting#head-e14f7c85c8ba38eb451a659e6f8784eefe2f0b6b
for more details

Colin Walters

unread,
May 16, 2008, 8:03:11 PM5/16/08
to Hotwire Shell
On Apr 18, 3:26 pm, Hamish <dmi...@gmail.com> wrote:
> After reading a little more, should we be implementing __cmp__ methods
> for things like Process and File objects?

Makes sense, done:

Committed r1248
M hotwire/sysdep/fs.py
M hotwire/sysdep/proc.py
r1248 = 7553b4370410db9674647f0ab97e9b5c531e9b78 (git-svn)
Reply all
Reply to author
Forward
0 new messages