gw.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. # gw.py
  3. #
  4. # Greaseweazle control script.
  5. #
  6. # Written & released by Keir Fraser <keir.xen@gmail.com>
  7. #
  8. # This is free and unencumbered software released into the public domain.
  9. # See the file COPYING for more details, or visit <http://unlicense.org>.
  10. import sys
  11. import importlib
  12. missing_modules = []
  13. try:
  14. import bitarray
  15. except ModuleNotFoundError:
  16. missing_modules.append("bitarray")
  17. try:
  18. import crcmod
  19. except ModuleNotFoundError:
  20. missing_modules.append("crcmod")
  21. try:
  22. import serial.tools.list_ports
  23. except ModuleNotFoundError:
  24. missing_modules.append("pyserial")
  25. if missing_modules:
  26. print("""\
  27. ** Missing Python modules: %s
  28. For installation instructions please read the wiki:
  29. <https://github.com/keirf/Greaseweazle/wiki/Software-Installation>"""
  30. % ', '.join(missing_modules))
  31. sys.exit(1)
  32. actions = [ 'read', 'write', 'delays', 'update', 'pin', 'reset' ]
  33. argv = sys.argv
  34. if len(argv) < 2 or argv[1] not in actions:
  35. print("Usage: %s [action] ..." % (argv[0]))
  36. print("Actions: ", end="")
  37. print(", ".join(str(x) for x in actions))
  38. sys.exit(1)
  39. mod = importlib.import_module('greaseweazle.tools.' + argv[1])
  40. main = mod.__dict__['main']
  41. res = main(argv)
  42. if res is None:
  43. res = 0
  44. sys.exit(res)
  45. # Local variables:
  46. # python-indent: 4
  47. # End: