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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import argparse
7 import hashlib
8 import os
9 import subprocess
10 import sys
11 import tempfile
12
13 BUCKET = 'gs://chrome-python-wheelhouse/sources/'
14
agable 2014/07/10 17:12:57 nit: two newlines
iannucci 2014/07/11 02:14:46 Done.
15 def main():
16 parser = argparse.ArgumentParser()
17 parser.add_argument('path', nargs=1, help='Location of the archive to upload')
18 o = parser.parse_args()
19
20 path = o.path[0]
21 fname = os.path.basename(path)
22
23 with open(path, 'rb') as f:
24 data = f.read()
25
26 sha = hashlib.sha1(data).hexdigest()
27 bits = []
28 for bit in reversed(fname.split('.')):
29 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.
30 bits.insert(0, bit)
31 else:
32 break
33 ext = '.' + '.'.join(bits)
34
35 # Need mktemp because windows won't let gsutil upload a TemporaryNamedFile.
36 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.
37 try:
38 with open(tempname, 'wb') as f:
39 f.write(data)
40
41 new_fname = sha + ext
42 subprocess.check_call(['gsutil', 'cp', tempname, BUCKET + new_fname])
43 print
44 finally:
45 os.unlink(tempname)
46
47 print new_fname
48
49
50 if __name__ == '__main__':
51 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698