gw.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. from greaseweazle import error
  13. missing_modules = []
  14. try:
  15. import bitarray
  16. except ImportError:
  17. missing_modules.append("bitarray")
  18. try:
  19. import crcmod
  20. except ImportError:
  21. missing_modules.append("crcmod")
  22. try:
  23. import serial.tools.list_ports
  24. except ImportError:
  25. missing_modules.append("pyserial")
  26. if missing_modules:
  27. print("""\
  28. ** Missing Python modules: %s
  29. For installation instructions please read the wiki:
  30. <https://github.com/keirf/Greaseweazle/wiki/Software-Installation>"""
  31. % ', '.join(missing_modules))
  32. sys.exit(1)
  33. actions = [ 'read',
  34. 'write',
  35. 'erase',
  36. 'delays',
  37. 'update',
  38. 'pin',
  39. 'reset',
  40. 'bandwidth' ]
  41. argv = sys.argv
  42. if len(argv) < 2 or argv[1] not in actions:
  43. print("Usage: %s [action] [-h] ..." % (argv[0]))
  44. print("Actions: ", end="")
  45. print(", ".join(str(x) for x in actions))
  46. print(" -h, --help Show help message for specified action")
  47. sys.exit(1)
  48. mod = importlib.import_module('greaseweazle.tools.' + argv[1])
  49. main = mod.__dict__['main']
  50. try:
  51. res = main(argv)
  52. if res is None:
  53. res = 0
  54. except error.Fatal as err:
  55. print("** FATAL ERROR:")
  56. print(err)
  57. res = 1
  58. sys.exit(res)
  59. # Local variables:
  60. # python-indent: 4
  61. # End: