gurgeh/selfspy — pull request #17 by dbaupp (2012-09-30 20:40:37+00:00)
Title: [pt]keys stats fail if any windows have no keystrokes.

As stated above, if a window has never been typed in, the `'keystrokes'` key doesn't exist in its process dictionary and so the sorting and printing (both of which used a straight `['keystrokes']` lookup) gave the following error:

~~~~
$ ./selfstats.py --pkeys
9755 keystrokes in 1116 key sequences, 18972 clicks (5227 excluding scroll), 638426 mouse movements

Processes sorted by keystrokes:
Traceback (most recent call last):
File "./selfstats.py", line 499, in
ss.do()
File "./selfstats.py", line 156, in do
self.show_summary()
File "./selfstats.py", line 361, in show_summary
pdata.sort(key=lambda x:x[1]['keystrokes'], reverse=True)
File "./selfstats.py", line 361, in
pdata.sort(key=lambda x:x[1]['keystrokes'], reverse=True)
KeyError: 'keystrokes'
~~~

(And similarly for `--tkeys`.)

This is the only place this occurs--everywhere else uses a `.get('keystrokes', 0)` call--so presumably the direct lookup is just a typo.