• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9import optparse
10import os
11import shutil
12import stat
13import subprocess
14import sys
15import tarfile
16import utils
17
18GMSCORE_DEPS = '/google/data/rw/teams/gmscore-size/deps'
19
20def parse_options():
21  return optparse.OptionParser().parse_args()
22
23def 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
29def 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
48if __name__ == '__main__':
49  sys.exit(Main())
50