#!/usr/bin/python # Copyright 2008 Jeff Epler # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import gobject import dbus import os import re model = "at90usb162" hexfile = "/home/jepler/at90/blink.hex" from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) r = re.compile("/org/freedesktop/Hal/devices/usb_device_3eb_2ffa_[\d_]+_if0") def handler(*args, **kw): if kw.get('member') != 'DeviceAdded': return if not r.match(args[0]): return print "handler", args, kw os.system("dfu-programmer %s erase" % (model,)) os.system("dfu-programmer %s flash %s" % (model, hexfile)) os.system("dfu-programmer %s start" % (model,)) bus = dbus.SystemBus() bus.add_signal_receiver(handler, interface_keyword='iface', member_keyword='member') loop = gobject.MainLoop() loop.run()