/apiary/main.py

https://bitbucket.org/lindenlab/apiary/ · Python · 81 lines · 36 code · 16 blank · 29 comment · 5 complexity · b00c4835f5d746e69c59cf62b5fe51b3 MD5 · raw file

  1. #!/usr/bin/env python
  2. #
  3. # $LicenseInfo:firstyear=2010&license=mit$
  4. #
  5. # Copyright (c) 2010, Linden Research, Inc.
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. # $/LicenseInfo$
  25. #
  26. '''
  27. This is the main script for apiary. It is responsible for all things
  28. related to configuration, option parsing, and process/thread management.
  29. '''
  30. import optparse
  31. import sys
  32. import os
  33. import multiprocessing
  34. import signal
  35. import time
  36. import apiary
  37. import apiary.tools.debug
  38. from apiary.tools.debug import *
  39. def main(args=sys.argv[1:]):
  40. options, arguments = parse_args(args)
  41. if options.debug:
  42. apiary.tools.debug.enable_debug()
  43. if options.clean:
  44. apiary.clean(options)
  45. if options.profile:
  46. from apiary.tools import lsprof
  47. profiler = lsprof.Profiler()
  48. profiler.enable(subcalls=True)
  49. beekeeper = apiary.BeeKeeper(options, arguments)
  50. beekeeper.start()
  51. if options.profile:
  52. profiler.disable()
  53. stats = lsprof.Stats(profiler.getstats())
  54. stats.sort()
  55. stats.pprint(top=10, file=sys.stderr, climit=5)
  56. def parse_args(args = []):
  57. parser = build_option_parser()
  58. options, args = parser.parse_args(args)
  59. return options, args
  60. def build_option_parser():
  61. parser = optparse.OptionParser()
  62. apiary.add_options(parser)
  63. return parser
  64. if __name__ == '__main__':
  65. main()