@@ -0,0 +1,2704 @@
+%22%22%22%0ACopyright 2011 Ryan Fobel and Christian Fobel%0A%0AThis file is part of Microdrop.%0A%0AMicrodrop is free software: you can redistribute it and/or modify%0Ait under the terms of the GNU General Public License as published by%0Athe Free Software Foundation, either version 3 of the License, or%0A(at your option) any later version.%0A%0AMicrodrop is distributed in the hope that it will be useful,%0Abut WITHOUT ANY WARRANTY; without even the implied warranty of%0AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0AGNU General Public License for more details.%0A%0AYou should have received a copy of the GNU General Public License%0Aalong with Microdrop.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A%22%22%22%0A%0Aimport os%0A%0Afrom subprocess import Popen, PIPE, CalledProcessError%0Afrom hardware.serial_device import SerialDevice, ConnectionError%0Afrom hardware import hardware_path%0Afrom utility import path%0A%0A%0Aclass FirmwareError(Exception):%0A    pass%0A%0A%0Aclass AvrDude(SerialDevice):%0A    def __init__(self):%0A        if os.name == 'nt':%0A            self.avrdude = hardware_path() / path('avr') / path('avrdude.exe')%0A        else:%0A            self.avrdude = hardware_path() / path('avr') / path('avrdude')%0A        if not self.avrdude.exists():%0A            raise FirmwareError('avrdude not installed')%0A        self.avrconf = hardware_path() / path('avr') / path('avrdude.conf')%0A        self.port = self.get_port()%0A        print 'avrdude successfully connected on port: ', self.port%0A%0A    def _run_command(self, flags, verbose=False):%0A        config = dict(avrdude=self.avrdude, avrconf=self.avrconf)%0A%0A        cmd = %5B'%25(avrdude)s'%5D + flags%0A        cmd = %5Bv %25 config for v in cmd%5D%0A        if verbose:%0A            print ' '.join(cmd)%0A        p = Popen(cmd, stdout=PIPE, stderr=PIPE)%0A        stdout, stderr = p.communicate()%0A        if p.returncode:%0A            raise ConnectionError(stderr)%0A        return stdout, stderr%0A%0A    def flash(self, hex_path):%0A        hex_path = path(hex_path)%0A        flags = %5B'-c', 'stk500v2', '-b', '115200', '-p', 'atmega2560',%0A                    '-P', self.port,%0A                    '-U', 'flash:w:%25s' %25 hex_path.name, %0A                    '-C', '%25(avrconf)s'%5D%0A%0A        try:%0A            cwd = os.getcwd()%0A            os.chdir(hex_path.parent)%0A            stdout, stderr = self._run_command(flags)%0A        finally:%0A            os.chdir(cwd)%0A        return stdout, stderr%0A%0A    def test_connection(self, port):%0A        flags = %5B'-c', 'stk500v2', '-b', '115200', '-p', 'atmega2560',%0A                    '-P', port,%0A                    '-C', '%25(avrconf)s', '-n'%5D%0A        try:%0A            self._run_command(flags)%0A        except (ConnectionError, CalledProcessError):%0A            return False%0A        return True

Add avrdude.py module