[pymacadmin] Exception when monitoring sleep events

3 views
Skip to first unread message

Geoff Lee

unread,
Apr 23, 2010, 10:28:58 AM4/23/10
to pymac...@googlegroups.com

Hi folks,

I'm seeing a problem that I think had been reported before. Running the latest code from google code, trying to act on either of the sleep notifications results in the following:

INFO: NSWorkspace Notification NSWorkspaceWillSleepNotification: executing /bin/echo "The system is about to go to sleep!"
Traceback (most recent call last):
File "/usr/local/sbin/crankd.py", line 597, in <module>
main()
File "/usr/local/sbin/crankd.py", line 523, in main
AppHelper.runConsoleEventLoop(installInterrupt=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjCTools/AppHelper.py", line 178, in runConsoleEventLoop
File "/usr/local/sbin/crankd.py", line 110, in onNotification_
self.callable(user_info=user_info) # pylint: disable-msg=E1101
File "/usr/local/sbin/crankd.py", line 558, in do_shell
for k, v in kwargs['user_info'].items():
AttributeError: 'NoneType' object has no attribute 'items'

WARNING: I'm a total python n00b, but it seems the problem is here, in line 557:

if 'user_info' in kwargs:

because this returns true even if kwargs['user_info'] is the None object (which it seems to be in the case of sleep events), in which case the next line:

for k, v in kwargs['user_info'].items()

throws the AttributeError. Changing line 557 to the following:

if 'user_info' in kwargs and kwargs['user_info'] is not None

seems to work, but I bet there's a more idiomatic way of doing it :)

TIA for any advice....

-geoff
______________________________________
Geoff Lee <G....@ed.ac.uk>
Computing Support
School of Arts, Culture and Environment
University of Edinburgh
20 Chambers St,
Edinburgh, Scotland,
EH1 1JZ
Tel: +44 (0)131 650 2341
______________________________________

--
You received this message because you are subscribed to the Google Groups "PyMacAdmin" group.
To post to this group, send email to pymac...@googlegroups.com.
To unsubscribe from this group, send email to pymacadmin+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pymacadmin?hl=en.

Reply all
Reply to author
Forward
0 new messages