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

Unified Diff: bootstrap/ingest_source.py

Issue 381043002: Add a virtualenv-based python bootstrapping service to infra. (Closed) Base URL: https://chromium.googlesource.com/infra/infra@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
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])
+ print
+ finally:
+ os.unlink(tempname)
+
+ print new_fname
+
+
+if __name__ == '__main__':
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698