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

Unified Diff: tools/usb_gadget/package.py

Issue 412243002: [usb_gadget p09] Software updates over HTTP. (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/__main__.py ('k') | tools/usb_gadget/server.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/usb_gadget/package.py
diff --git a/tools/usb_gadget/package.py b/tools/usb_gadget/package.py
index d1a2f2d0bd8e3c830cfd81547b497e54825f9938..069bb1477d7738e8d6a3f3152c430aed5c37c089 100755
--- a/tools/usb_gadget/package.py
+++ b/tools/usb_gadget/package.py
@@ -3,13 +3,14 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Utility to package the USB gadget framework.
+"""Utility to package and upload the USB gadget framework.
"""
import argparse
import hashlib
import os
import StringIO
+import urllib2
import zipfile
@@ -37,6 +38,27 @@ def MakeZip(directory=None, files=None):
return content, md5
+def EncodeBody(filename, buf):
+ return '\r\n'.join([
+ '--foo',
+ 'Content-Disposition: form-data; name="file"; filename="{}"'
+ .format(filename),
+ 'Content-Type: application/octet-stream',
+ '',
+ buf,
+ '--foo--',
+ ''
+ ])
+
+
+def UploadZip(content, md5, host):
+ filename = 'usb_gadget-{}.zip'.format(md5)
+ req = urllib2.Request(url='http://{}/update'.format(host),
+ data=EncodeBody(filename, content))
+ req.add_header('Content-Type', 'multipart/form-data; boundary=foo')
+ urllib2.urlopen(req)
+
+
def main():
parser = argparse.ArgumentParser(
description='Package (and upload) the USB gadget framework.')
@@ -50,6 +72,9 @@ def main():
'--hash-file', type=str, metavar='FILE',
help='save package hash as FILE')
parser.add_argument(
+ '--upload', type=str, metavar='HOST[:PORT]',
+ help='upload package to target system')
+ parser.add_argument(
'files', metavar='FILE', type=str, nargs='*',
help='source files')
@@ -62,6 +87,8 @@ def main():
if args.hash_file:
with open(args.hash_file, 'w') as hash_file:
hash_file.write(md5)
+ if args.upload:
+ UploadZip(content, md5, args.upload)
if __name__ == '__main__':
« no previous file with comments | « tools/usb_gadget/__main__.py ('k') | tools/usb_gadget/server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698