PageRenderTime 73ms CodeModel.GetById 65ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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'''
28This is the main script for apiary.  It is responsible for all things
29related to configuration, option parsing, and process/thread management.
30'''
31
32import optparse
33import sys
34import os
35import multiprocessing
36import signal
37import time
38
39import apiary
40import apiary.tools.debug
41from apiary.tools.debug import *
42
43def main(args=sys.argv[1:]):
44    options, arguments = parse_args(args)
45    if options.debug:
46        apiary.tools.debug.enable_debug()
47
48    if options.clean:
49        apiary.clean(options)
50    
51    
52    if options.profile:
53        from apiary.tools import lsprof
54        profiler = lsprof.Profiler()
55        profiler.enable(subcalls=True)
56
57    
58    beekeeper = apiary.BeeKeeper(options, arguments)
59    beekeeper.start()
60    
61    if options.profile:
62        profiler.disable()
63        stats = lsprof.Stats(profiler.getstats())
64        stats.sort()
65        stats.pprint(top=10, file=sys.stderr, climit=5)
66
67    
68def parse_args(args = []):
69    parser = build_option_parser()
70    options, args = parser.parse_args(args)
71    
72    return options, args
73    
74
75def build_option_parser():
76    parser = optparse.OptionParser()
77    apiary.add_options(parser)
78    return parser
79
80if __name__ == '__main__':
81    main()