File: frameworkd

package info (click to toggle)
fso-frameworkd 0.9.5.9%2Bgit20110512-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,984 kB
  • sloc: python: 23,770; sh: 160; sql: 4; makefile: 2
file content (104 lines) | stat: -rwxr-xr-x 3,468 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
"""
The Open Device Daemon - Python Implementation

(C) 2008-2010 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
(C) 2008 Openmoko, Inc.

GPLv2 or later
"""

__version__ = "1.3.1"

import sys, os
from optparse import OptionParser

#----------------------------------------------------------------------------#
class TheOptionParser( OptionParser ):
#----------------------------------------------------------------------------#
    def __init__( self ):
        OptionParser.__init__( self )
        self.set_defaults( overrides=[] )
        self.add_option( "-o", "--override",
            dest = "overrides",
            help = "override configuration",
            metavar = "SECTION.KEY=VALUE",
            action = "append"
        )
        self.add_option( "-s", "--subsystems",
            metavar = "system1,system2,system3,...",
            dest = "subsystems",
            default = "",
            help = "launch only the following subsystems (default=all)",
            action = "store",
        )
        self.add_option( "-n", "--noframework",
            dest = "noframework",
            help = "do not launch the framework subsystem (use for multiple framework processes)",
            action = "store_true",
        )
        self.add_option( "-d", "--daemonize",
            dest = "daemonize",
            help = "launch as daemon",
            action = "store_true",
        )
        self.add_option( "-p", "--profile",
            metavar = "<filename>",
            dest = "profile",
            help = "launch in profile mode (needs python-profile)",
            action = "store",
        )
        self.add_option( "-l", "--loophole",
            dest = "loophole",
            help = "create loophole listening on port 8822 (needs python-netserver)",
            action = "store_true",
        )

#----------------------------------------------------------------------------#
if __name__ == "__main__":
#----------------------------------------------------------------------------#
    options = TheOptionParser()
    options.parse_args( sys.argv )

    if options.values.profile:
        try:
            import cProfile
        except ImportError:
            print "Can't import cProfile; python-profile not installed? Can't profile."
            sys.exit( -1 )
        else:
            print "WARNING: profiling mode. profiling to %s" % options.values.profile

    try:
        from framework import controller
    except ImportError:
        sys.path.append( os.path.dirname( os.path.abspath( os.path.curdir ) ) )
        from framework import controller
    c = controller.Controller( "%s/subsystems" % os.path.dirname( controller.__file__ ), options )

    if options.values.loophole:
        try:
            from patterns import loophole
        except ImportError, e:
            print "Can't launch loophole: %s", e
        else:
            l = loophole.LoopHole( dict( controller=c ) )
            print "LoopHole listening on port 8822"

    try:
        if options.values.profile:
            p = cProfile.Profile()
            p.run( "c.launch()" )
        else:
            c.launch()
    except KeyboardInterrupt:
        print >>sys.stderr, "ctrl-c: exiting."
        c.shutdown()
        del c

    if options.values.profile:
        import lsprofcalltree
        k = lsprofcalltree.KCacheGrind(p)
        data = open( options.values.profile, "w" )
        k.output( data )
        data.close()