#!/usr/bin/env python import subprocess import sys def snarf_device(): cmd = "ls -lrt /dev" res = subprocess.check_output(cmd, shell=True).split("\n") res = [x for x in res if "tty.usbserial" in x] if not res: return return {"result" : True, "data": res } def snarf_kexts(): cmd = "kextstat -l | grep -i ftdi" try: res = subprocess.check_output(cmd, shell=True).split("\n") except: return res = [x for x in res if x != ''] if len(res) == 1: return {"result" : True, "data": res } else: return {"result" : True, "data": res } def snarf_serialosc(): cmd = "ps aux | grep serialosc | grep -v 'grep'" try: res = subprocess.check_output(cmd, shell=True) except Exception as e: print(e) return False return {"result" : True, "data": res } def format_report(report): if "snarf_device" in report: data = report["snarf_device"]["data"] data = [x.split()[-1] for x in data] fmt = "Connected device(s):\n\n\t%s\n\n" % "/t".join(data) report["snarf_device"]["report"] = fmt if "snarf_kexts" in report: data = report["snarf_kexts"]["data"] data = [" ".join(x.split()[5:7]) for x in data] fmt = "USB Driver(s)\n\n\t%s\n\n" % "/t".join(data) report["snarf_kexts"]["report"] = fmt if "snarf_serialosc" in report: data = report["snarf_serialosc"]["data"] data = data.split("\n") data = [x for x in data if x != ''] data = [" ".join(x.split()[10:]) for x in data] fmt = "Relevant processes:\n\n\t%s\n" % "\n\t".join(data) report["snarf_serialosc"]["report"] = fmt return report def diagnose_macos(): tests = [snarf_device , snarf_kexts, snarf_serialosc] res = {} num = len(tests) for i, t in enumerate(tests): r = t() if r: r["idx"] = i res[t.__name__] = r report = format_report(res) all_tests_passed = True for k in report: v = report[k] if v["result"]: all_tests_passed = False print all_tests_passed for k in report: v = report[k] if "report" in v: print(v["report"]) else: print("No report") def diagnose_linux(): print("Method not implemented yet!") checklist_mac = """\n\tDiagnosis unsuccessful!\n\n1 - is the device plugged in (directly, probably) 2 - is the FTDI driver installed? 3 - is the Apple provided driver installed? (pick one) 4 - is libmonome compiled / installed? 5 - is serialosc compiled / installed? 6 - is serialoscd running?\n""" def diagnose(): if "darwin" in sys.platform: res = diagnose_macos() #if not res : # print(checklist_mac) elif "linux" in sys.platform: res = diagnose_linux() if __name__ == "__main__": diagnose()