Chromium Code Reviews| Index: bootstrap/ingest_source.py |
| diff --git a/bootstrap/ingest_source.py b/bootstrap/ingest_source.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..edc410f5a0843ff7427e4a6c507101aad65217a7 |
| --- /dev/null |
| +++ b/bootstrap/ingest_source.py |
| @@ -0,0 +1,51 @@ |
| +#!/usr/bin/env python |
| +# 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. |
| + |
| +import argparse |
| +import hashlib |
| +import os |
| +import subprocess |
| +import sys |
| +import tempfile |
| + |
| +BUCKET = 'gs://chrome-python-wheelhouse/sources/' |
| + |
|
agable
2014/07/10 17:12:57
nit: two newlines
iannucci
2014/07/11 02:14:46
Done.
|
| +def main(): |
| + parser = argparse.ArgumentParser() |
| + parser.add_argument('path', nargs=1, help='Location of the archive to upload') |
| + o = parser.parse_args() |
| + |
| + path = o.path[0] |
| + fname = os.path.basename(path) |
| + |
| + with open(path, 'rb') as f: |
| + data = f.read() |
| + |
| + sha = hashlib.sha1(data).hexdigest() |
| + bits = [] |
| + for bit in reversed(fname.split('.')): |
| + if bit in ('tar', 'gz', 'tgz', 'zip', 'bz2'): |
|
dnj
2014/07/10 16:06:18
Poor 'tbz2' :(
iannucci
2014/07/11 02:14:46
Acknowledged.
|
| + bits.insert(0, bit) |
| + else: |
| + break |
| + ext = '.' + '.'.join(bits) |
| + |
| + # Need mktemp because windows won't let gsutil upload a TemporaryNamedFile. |
| + tempname = tempfile.mktemp(suffix=ext) |
|
dnj
2014/07/10 16:06:18
Ugh Windows is stupid. With a streaming transfer,
iannucci
2014/07/11 02:14:46
Derp. Done.
|
| + try: |
| + with open(tempname, 'wb') as f: |
| + f.write(data) |
| + |
| + new_fname = sha + ext |
| + subprocess.check_call(['gsutil', 'cp', tempname, BUCKET + new_fname]) |
| + finally: |
| + os.unlink(tempname) |
| + |
| + print new_fname |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |