gw.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. import platform
  13. try:
  14. import bitarray
  15. except ModuleNotFoundError:
  16. print("""\
  17. Please install module 'bitarray'. This may require a C compiler.""")
  18. if platform.system() == "Windows":
  19. print("""\
  20. Windows: Either install Visual Studio, or download a pre-built bitarray
  21. wheel from https://lfd.uci.edu/~gohlke/pythonlibs/#bitarray""")
  22. elif platform.system() == "Darwin":
  23. print("""\
  24. macOS: Install Xcode from App Store.""")
  25. else:
  26. print("""\
  27. Linux: Install GCC using your package manager (eg. apt install gcc)""")
  28. sys.exit()
  29. try:
  30. import crcmod
  31. except ModuleNotFoundError:
  32. print("Please install module 'crcmod'.")
  33. sys.exit()
  34. try:
  35. import serial.tools.list_ports
  36. except ModuleNotFoundError:
  37. print("Please install module 'pyserial'.")
  38. sys.exit()
  39. actions = [ 'read', 'write', 'delays', 'update', 'pin', 'reset' ]
  40. argv = sys.argv
  41. if len(argv) < 2 or argv[1] not in actions:
  42. print("Usage: %s [action] ..." % (argv[0]))
  43. print("Actions: ", end="")
  44. print(", ".join(str(x) for x in actions))
  45. sys.exit(1)
  46. mod = importlib.import_module('greaseweazle.tools.' + argv[1])
  47. main = mod.__dict__['main']
  48. res = main(argv)
  49. if res is None:
  50. res = 0
  51. sys.exit(res)
  52. # Local variables:
  53. # python-indent: 4
  54. # End: