Index: tools/usb_gadget/server.py |
diff --git a/tools/usb_gadget/server.py b/tools/usb_gadget/server.py |
index f9ccd9b372d7e7bc168a4dc19469bc1ef45b6e6c..9f237264213fdd5b04db69571f6bd12a5b2f48a0 100644 |
--- a/tools/usb_gadget/server.py |
+++ b/tools/usb_gadget/server.py |
@@ -5,11 +5,16 @@ |
"""WSGI application to manage a USB gadget. |
""" |
+import re |
+import sys |
+ |
from tornado import httpserver |
from tornado import web |
import default_gadget |
+VERSION_PATTERN = re.compile(r'.*usb_gadget-([a-z0-9]{32})\.zip') |
+ |
address = None |
chip = None |
claimed_by = None |
@@ -27,6 +32,19 @@ def SwitchGadget(new_gadget): |
chip.Create(gadget) |
+class VersionHandler(web.RequestHandler): |
+ |
+ def get(self): |
+ version = 'unpackaged' |
+ for path in sys.path: |
+ match = VERSION_PATTERN.match(path) |
+ if match: |
+ version = match.group(1) |
+ break |
+ |
+ self.write(version) |
+ |
+ |
class ClaimHandler(web.RequestHandler): |
def post(self): |
@@ -69,6 +87,7 @@ class ReconnectHandler(web.RequestHandler): |
app = web.Application([ |
+ (r'/version', VersionHandler), |
(r'/claim', ClaimHandler), |
(r'/unclaim', UnclaimHandler), |
(r'/unconfigure', UnconfigureHandler), |