PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/mysql_watcher/browse_queries

https://bitbucket.org/lindenlab/apiary/
Python | 85 lines | 61 code | 13 blank | 11 comment | 12 complexity | af452f4df98b17651337893e6f6db797 MD5 | raw file
  1. #!/usr/bin/python
  2. """
  3. Browse query result files, and view/edit metadata associated with queries
  4. """
  5. import os.path
  6. if os.path.exists("../setup-path.py"):
  7. execfile("../setup-path.py")
  8. import getopt, sys
  9. import curses
  10. import curses.textpad
  11. import curses.wrapper
  12. import string
  13. import sys
  14. import time
  15. from llbase import llsd
  16. from dblibs.dbbrowser import *
  17. def sort_by_field(d, field):
  18. "Returns the keys of dictionary d sorted by the value in the field"
  19. items=d.items()
  20. backitems=[ [v[1][field],v[0]] for v in items]
  21. backitems.sort()
  22. return [ backitems[i][1] for i in range(0,len(backitems))]
  23. LIST_HEIGHT = 20
  24. def dump_query_info(query_map, fn):
  25. #
  26. # Sort by the map key (so that there's some hope of merging
  27. #
  28. sorted_keys = query_map.keys()
  29. sorted_keys.sort()
  30. out = []
  31. for key in sorted_keys:
  32. row = query_map[key]
  33. out_row = {}
  34. out_row['query'] = row['query']
  35. out_row['host'] = row['host']
  36. out_row['notes'] = row['notes']
  37. out.append(out_row)
  38. f = open(fn, "w")
  39. f.write(str(llsd.LLSD(out)))
  40. f.close()
  41. def display_queries(stdscr, query_stats, query_metadata):
  42. # Create the query browser
  43. query_browser = LLQueryBrowser(stdscr, query_stats, query_metadata)
  44. query_browser.redraw()
  45. done = False
  46. while not done:
  47. c = stdscr.getch()
  48. if query_browser.handleKey(c):
  49. pass
  50. elif c == ord('q'):
  51. # Quit
  52. query_metadata.save("./query_info.llsd")
  53. done = True
  54. break
  55. if c == ord('w'):
  56. query_metadata.save("./query_info.llsd")
  57. pass
  58. elif c == ord('s'):
  59. query_browser.toggleSort()
  60. elif c == ord('n'):
  61. # Go forth and edit notes
  62. query_browser.editSelectedText('notes')
  63. else:
  64. print "Pressed key %s" % c
  65. query_browser.redraw()
  66. if __name__ == "__main__":
  67. path = sys.argv[1]
  68. # Read in metadata
  69. query_metadata = LLQueryMetadata("./query_info.llsd")
  70. query_stats = LLQueryStatMap(path, time.time())
  71. query_stats.load(path)
  72. curses.wrapper(display_queries, query_stats, query_metadata)