Remove APIPermission::kFileSystemWriteDirectory
[chromium-blink-merge.git] / tools / usb_gadget / __main__.py
blob03341ea85cdbe4c7fef1d1d9a54825f6f0b3b58d
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Package entry-point."""
7 import argparse
9 import netifaces
10 from tornado import ioloop
12 import composite_echo_gadget
13 import echo_gadget
14 import hid_echo_gadget
15 import keyboard_gadget
16 import linux_gadgetfs
17 import mouse_gadget
18 import server
21 def ParseArgs():
22 """Parse application arguments."""
23 parser = argparse.ArgumentParser(description='USB gadget server.')
24 parser.add_argument(
25 '-i', '--interface', default='lo',
26 help='Listen for HTTP connections on this interface.')
27 parser.add_argument(
28 '-p', '--port', default=8080,
29 help='Listen for HTTP connections on this port.')
30 parser.add_argument(
31 '--hardware', default='beaglebone-black',
32 help='Hardware configuration.')
33 parser.add_argument(
34 '--start-claimed',
35 help='Start with the device claimed by this client.')
36 return parser.parse_args()
39 def main():
40 args = ParseArgs()
42 server.interface = args.interface
43 server.port = args.port
44 server.hardware = args.hardware
45 server.claimed_by = args.start_claimed
47 addrs = netifaces.ifaddresses(server.interface)
48 ip_address = addrs[netifaces.AF_INET][0]['addr']
49 server.address = '{}:{}'.format(ip_address, server.port)
51 server.chip = linux_gadgetfs.LinuxGadgetfs(server.hardware)
52 server.SwitchGadget(server.default)
54 composite_echo_gadget.RegisterHandlers()
55 echo_gadget.RegisterHandlers()
56 hid_echo_gadget.RegisterHandlers()
57 keyboard_gadget.RegisterHandlers()
58 mouse_gadget.RegisterHandlers()
60 server.http_server.listen(server.port)
62 ioloop.IOLoop.instance().start()
63 print 'Exiting...'
66 if __name__ == '__main__':
67 main()