You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

obj2data.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #! /usr/bin/env python
  2. import sys
  3. import json
  4. #stuff = json.loads(sys.argv[1])
  5. #data = json.load(sys.stdin)
  6. #print(json.dumps(sys.stdin, sort_keys=True, indent=4))
  7. ###print str(sys.argv[1])
  8. #print(stuff['foo'])
  9. #print(json.dumps(data, indent=4))
  10. #msg_id=int(str(sys.argv[1]),0)
  11. #msg_prio=msg_id>>26
  12. #msg_type=(msg_id>>24) & 0x03
  13. #msg_dst=(msg_id>>16) & 0xFF
  14. #msg_src=(msg_id>>8) & 0xFF
  15. #msg_cmd=msg_id & 0xFF
  16. #print "id:", hex(msg_id), bin(msg_id)
  17. #print "prio:", hex(msg_prio), bin(msg_prio)
  18. #print "type:", hex(msg_type), bin(msg_type)
  19. #print "dst:", hex(msg_dst), bin(msg_dst)
  20. #print "src:", hex(msg_src), bin(msg_src)
  21. #print "cmd:", hex(msg_cmd), bin(msg_cmd)
  22. import sys
  23. import simplejson as json
  24. def main(args):
  25. try:
  26. inputFile = open(args[1])
  27. input = json.load(inputFile)
  28. inputFile.close()
  29. except IndexError:
  30. usage()
  31. return False
  32. if len(args) < 3:
  33. print json.dumps(input, sort_keys = False, indent = 10)
  34. else:
  35. outputFile = open(args[2], "w")
  36. json.dump(input, outputFile, sort_keys = False, indent = 4)
  37. outputFile.close()
  38. return True
  39. def usage():
  40. print __doc__
  41. if __name__ == "__main__":
  42. sys.exit(not main(sys.argv))