Trees | Indices | Help |
|
---|
|
1 ### BITPIM 2 ### 3 ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 4 ### 5 ### This program is free software; you can redistribute it and/or modify 6 ### it under the terms of the BitPim license as detailed in the LICENSE file. 7 ### 8 ### $Id: comm_notify.py 4219 2007-05-09 02:15:50Z djpham $ 9 10 """Handle notification of comm ports availability using DNOTIFY""" 11 12 import fcntl 13 import os 14 import signal 15 import sys 16 17 import wx 18 19 bpCOMM_NOTIFICATION_EVENT = wx.NewEventType() 20 COMM_NOTIFICATION_EVENT = wx.PyEventBinder(bpCOMM_NOTIFICATION_EVENT, 0) 21 default_port=5002 2224 add=0 25 remove=13127 super(CommNotificationEvent, self).__init__() 28 self.SetEventType=bpCOMM_NOTIFICATION_EVENT 29 self.type=None 30 self.comm=None3660 61 NotificationPath='/var/bitpim' 62 NotificationFile='/var/bitpim/dnotify.log' 6338 # a new comm has just been added 39 self.evt.type=CommNotificationEvent.add 40 if comm.startswith('/proc/bus/usb/') or \ 41 comm.startswith('/dev/bus/usb/'): 42 # this is a Linux hotplug USB port, which may have many interfaces. 43 # can't figure which one so scan for all ports. 44 self.evt.comm=None 45 else: 46 self.evt.comm=comm 47 self.mw.OnCommNotification(self.evt) 48 return True4951 # a new comm has just been deleted 52 if comm.startswith('/proc/bus/usb/') or \ 53 comm.startswith('/dev/bus/usb/'): 54 # This is a Linux hotplug USB port, just ignore it 55 return False 56 self.evt.type=CommNotificationEvent.remove 57 self.evt.comm=comm 58 self.mw.OnCommNotification(self.evt) 59 return True65 # read the log file & process its content 66 # expecting a line: add|del <port> 67 global NotificationFile 68 try: 69 _s=file(NotificationFile, 'rt').read() 70 _tkns=_s.split(' ') 71 if len(_tkns)==2: 72 if _tkns[0]=='add': 73 commobj.add(_tkns[1]) 74 else: 75 commobj.remove(_tkns[1]) 76 except: 77 if __debug__: 78 raise79 80 _global_fd=None 81 _global_obj=None 82 8789 global NotificationPath, _global_fd, _global_obj 90 _global_obj=CommNotification(mainwindow) 91 try: 92 _global_fd=os.open(NotificationPath, os.O_RDONLY) 93 except OSError: 94 # Something's wrong with the dir, bail 95 mainwindow.log('Failed to open dir '+NotificationPath) 96 return False 97 except: 98 if __debug__: 99 raise 100 return False 101 fcntl.fcntl(_global_fd, fcntl.F_NOTIFY, 102 fcntl.DN_MODIFY|fcntl.DN_CREATE|fcntl.DN_MULTISHOT) 103 mainwindow.log('USB Comm Watch started') 104 return True105 109
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Jan 24 16:21:52 2010 | http://epydoc.sourceforge.net |