#!/usr/bin/env python

import serial
import os.path
import argparse
from time import sleep

parser = argparse.ArgumentParser(description='Reset an Arduino')
parser.add_argument('resetport', nargs=1, help='Serial device e.g. /dev/ttyACM0')
parser.add_argument('port', nargs=1, help='Serial device e.g. /dev/ttyACM0')
args = parser.parse_args()


if not os.path.exists(args.resetport[0]):
    ser = serial.Serial("/dev/serial/by-id/usb-Arduino_LLC_Arduino_Leonardo-if00", 57600)
else:
    ser = serial.Serial(args.resetport[0], 57600)
ser.close()
ser.open()
ser.close()
ser.setBaudrate(1200)
ser.open()
ser.close()
sleep(1)

while not os.path.exists(args.port[0]):
    sleep(1)


