debug.py 666 B

123456789101112131415161718192021222324252627282930
  1. import struct
  2. DEBUG = False
  3. class bcolors:
  4. GREY = '\033[90m'
  5. ORANGE = '\033[91m'
  6. GREEN = '\033[92m'
  7. YELLOW = '\033[93m'
  8. BLUE = '\033[94m'
  9. PURPLE = '\033[95m'
  10. CYAN = '\033[96m'
  11. WHITE = '\033[97m'
  12. DEFAULT = '\033[99m'
  13. ENDC = '\033[0m'
  14. BOLD = '\033[1m'
  15. UNDERLINE = '\033[4m'
  16. def print_data(name, data, length = None, color = bcolors.DEFAULT):
  17. if not DEBUG: return
  18. if data == None or not len(data): return
  19. if length == None: length = len(data)
  20. print color + name,
  21. for c in data[:length]: print "0x%02X"%(ord(c)),
  22. print bcolors.ENDC
  23. def print_debug(str):
  24. if not DEBUG: return
  25. print str