PageRenderTime 20ms CodeModel.GetById 17ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/circuits.sniff

https://bitbucket.org/prologic/circuits/
Unknown | 77 lines | 55 code | 22 blank | 0 comment | 0 complexity | 4cd9428d7eecba0f2df4b207be6cc319 MD5 | raw file
 1#!/usr/bin/env python
 2
 3"""(Tool) Event Sniffer
 4
 5Event sniffing tool. This tool can be used to sniff and debug Events as they
 6occur in another system. As long as that system has an instnace of the Bridge
 7Component, events can be sniffed and printed.
 8"""
 9
10import optparse
11
12import circuits
13from circuits import Debugger, Bridge, Manager
14
15USAGE = "%prog [options] [host[:port]]"
16VERSION = "%prog v" + circuits.__version__
17
18###
19### Functions
20###
21
22def parse_options():
23    """parse_options() -> opts, args
24
25    Parse the command-line options given returning both
26    the parsed options and arguments.
27    """
28
29    parser = optparse.OptionParser(usage=USAGE, version=VERSION)
30
31    parser.add_option("-b", "--bind",
32            action="store", default="0.0.0.0:8000", dest="bind",
33            help="Bind to address:port")
34
35    opts, args = parser.parse_args()
36
37    return opts, args
38
39###
40### Main
41###
42
43def main():
44    opts, args = parse_options()
45
46    if ":" in opts.bind:
47        address, port = opts.bind.split(":")
48        port = int(port)
49    else:
50        address, port = opts.bind, 8000
51
52    if args:
53        x = args[0].split(":")
54        if len(x) > 1:
55            nodes = [(x[0], int(x[1]))]
56        else:
57            nodes = [(x[0], 8000)]
58    else:
59        nodes = []
60
61    manager = Manager()
62
63    debugger = Debugger()
64    debugger.IgnoreEvents.extend(["Read", "Write"])
65    manager += debugger
66
67    bridge = Bridge(port, address=address, nodes=nodes)
68    manager += bridge
69
70    manager.run()
71
72###
73### Entry Point
74###
75
76if __name__ == "__main__":
77    main()