Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Unified Diff: tools/usb_gadget/__main__.py

Issue 418773002: [usb_gadget p07] HTTP management server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/usb_gadget/__init__.py ('k') | tools/usb_gadget/default_gadget.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/usb_gadget/__main__.py
diff --git a/tools/usb_gadget/__main__.py b/tools/usb_gadget/__main__.py
new file mode 100644
index 0000000000000000000000000000000000000000..20998c5832d19d0bb8187b03c35f51dd4d9e9288
--- /dev/null
+++ b/tools/usb_gadget/__main__.py
@@ -0,0 +1,52 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Package entry-point."""
+
+import argparse
+
+import netifaces
+from tornado import ioloop
+
+import linux_gadgetfs
+import server
+
+
+def ParseArgs():
+ """Parse application arguments."""
+ parser = argparse.ArgumentParser(description='USB gadget server.')
+ parser.add_argument(
+ '-i', '--interface', default='lo',
+ help='Listen for HTTP connections on this interface.')
+ parser.add_argument(
+ '-p', '--port', default=8080,
+ help='Listen for HTTP connections on this port.')
+ parser.add_argument(
+ '--hardware', default='beaglebone-black',
+ help='Hardware configuration.')
+ return parser.parse_args()
+
+
+def main():
+ args = ParseArgs()
+
+ server.interface = args.interface
+ server.port = args.port
+ server.hardware = args.hardware
+
+ addrs = netifaces.ifaddresses(server.interface)
+ ip_address = addrs[netifaces.AF_INET][0]['addr']
+ server.address = '{}:{}'.format(ip_address, server.port)
+
+ server.chip = linux_gadgetfs.LinuxGadgetfs(server.hardware)
+ server.SwitchGadget(server.default)
+
+ server.http_server.listen(server.port)
+
+ ioloop.IOLoop.instance().start()
+ print 'Exiting...'
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « tools/usb_gadget/__init__.py ('k') | tools/usb_gadget/default_gadget.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698