aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Eric Boren <borenet@google.com>2017-07-19 14:05:41 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-19 18:23:36 +0000
commitedfe4a5ca01858f47c4d12cc15ec36d606048704 (patch)
treeb9404ee1d624d419f3345b43192f697f5e9727b9
parentb7e8c3b52a306357ecd08d00170062137ec641d4 (diff)
[infra] Add protoc asset
This is actually just needed for the infra repo, but that doesn't have any of the mechanisms for creating assets, so it's simpler to do that here. NOTRY=true Bug: skia:6866 Change-Id: I5d9810fc7440703090b55b13d06b39f92e85f172 Reviewed-on: https://skia-review.googlesource.com/24680 Commit-Queue: Eric Boren <borenet@google.com> Reviewed-by: Ravi Mistry <rmistry@google.com>
-rw-r--r--infra/bots/assets/protoc/VERSION1
-rwxr-xr-xinfra/bots/assets/protoc/common.py26
-rwxr-xr-xinfra/bots/assets/protoc/create.py35
-rwxr-xr-xinfra/bots/assets/protoc/create_and_upload.py42
-rwxr-xr-xinfra/bots/assets/protoc/download.py16
-rwxr-xr-xinfra/bots/assets/protoc/upload.py16
6 files changed, 136 insertions, 0 deletions
diff --git a/infra/bots/assets/protoc/VERSION b/infra/bots/assets/protoc/VERSION
new file mode 100644
index 0000000000..c227083464
--- /dev/null
+++ b/infra/bots/assets/protoc/VERSION
@@ -0,0 +1 @@
+0 \ No newline at end of file
diff --git a/infra/bots/assets/protoc/common.py b/infra/bots/assets/protoc/common.py
new file mode 100755
index 0000000000..caa0ad899c
--- /dev/null
+++ b/infra/bots/assets/protoc/common.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Common vars used by scripts in this directory."""
+
+
+import os
+import sys
+
+FILE_DIR = os.path.dirname(os.path.abspath(__file__))
+INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
+
+sys.path.insert(0, INFRA_BOTS_DIR)
+from assets import assets
+
+ASSET_NAME = os.path.basename(FILE_DIR)
+
+
+def run(cmd):
+ """Run a command, eg. "upload" or "download". """
+ assets.main([cmd, ASSET_NAME] + sys.argv[1:])
diff --git a/infra/bots/assets/protoc/create.py b/infra/bots/assets/protoc/create.py
new file mode 100755
index 0000000000..e363cc5068
--- /dev/null
+++ b/infra/bots/assets/protoc/create.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset."""
+
+
+import argparse
+import subprocess
+
+
+ZIP_URL = ('https://github.com/google/protobuf/releases/download/v3.3.0/'
+ 'protoc-3.3.0-linux-x86_64.zip')
+
+
+def create_asset(target_dir):
+ """Create the asset."""
+ local_zip = '/tmp/protoc.zip'
+ subprocess.check_call(['curl', '-L', ZIP_URL, '-o', local_zip])
+ subprocess.check_call(['unzip', local_zip, '-d', target_dir])
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--target_dir', '-t', required=True)
+ args = parser.parse_args()
+ create_asset(args.target_dir)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/infra/bots/assets/protoc/create_and_upload.py b/infra/bots/assets/protoc/create_and_upload.py
new file mode 100755
index 0000000000..de56a80fa8
--- /dev/null
+++ b/infra/bots/assets/protoc/create_and_upload.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset and upload it."""
+
+
+import argparse
+import common
+import os
+import subprocess
+import sys
+import utils
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--gsutil')
+ args = parser.parse_args()
+
+ with utils.tmp_dir():
+ cwd = os.getcwd()
+ create_script = os.path.join(common.FILE_DIR, 'create.py')
+ upload_script = os.path.join(common.FILE_DIR, 'upload.py')
+
+ try:
+ subprocess.check_call(['python', create_script, '-t', cwd])
+ cmd = ['python', upload_script, '-t', cwd]
+ if args.gsutil:
+ cmd.extend(['--gsutil', args.gsutil])
+ subprocess.check_call(cmd)
+ except subprocess.CalledProcessError:
+ # Trap exceptions to avoid printing two stacktraces.
+ sys.exit(1)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/infra/bots/assets/protoc/download.py b/infra/bots/assets/protoc/download.py
new file mode 100755
index 0000000000..ca999e0378
--- /dev/null
+++ b/infra/bots/assets/protoc/download.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Download the current version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+ common.run('download')
diff --git a/infra/bots/assets/protoc/upload.py b/infra/bots/assets/protoc/upload.py
new file mode 100755
index 0000000000..bdfbda783e
--- /dev/null
+++ b/infra/bots/assets/protoc/upload.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Upload a new version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+ common.run('upload')