Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | # Script for uploading to x20 as a dependency in the same way we use cloud |
| 7 | # storage. |
| 8 | |
| 9 | import optparse |
| 10 | import os |
| 11 | import shutil |
| 12 | import stat |
| 13 | import subprocess |
| 14 | import sys |
| 15 | import tarfile |
| 16 | import utils |
| 17 | |
| 18 | GMSCORE_DEPS = '/google/data/rw/teams/gmscore-size/deps' |
| 19 | |
| 20 | def parse_options(): |
| 21 | return optparse.OptionParser().parse_args() |
| 22 | |
| 23 | def create_archive(name): |
| 24 | tarname = '%s.tar.gz' % name |
| 25 | with tarfile.open(tarname, 'w:gz') as tar: |
| 26 | tar.add(name) |
| 27 | return tarname |
| 28 | |
| 29 | def Main(): |
| 30 | (options, args) = parse_options() |
| 31 | assert len(args) == 1 |
| 32 | name = args[0] |
| 33 | print 'Creating archive for %s' % name |
| 34 | if not name in os.listdir('.'): |
| 35 | print 'You must be standing directly below the directory you are uploading' |
| 36 | return 1 |
| 37 | filename = create_archive(name) |
| 38 | sha1 = utils.get_sha1(filename) |
| 39 | dest = os.path.join(GMSCORE_DEPS, sha1) |
| 40 | print 'Uploading to %s' % dest |
| 41 | shutil.copyfile(filename, dest) |
| 42 | os.chmod(dest, stat.S_IRWXU | stat.S_IROTH | stat.S_IXOTH | stat.S_IRWXG) |
| 43 | sha1_file = '%s.sha1' % filename |
| 44 | with open(sha1_file, 'w') as output: |
| 45 | output.write(sha1) |
| 46 | print 'Sha (%s) written to: %s' % (sha1, sha1_file) |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | sys.exit(Main()) |