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

Side by Side Diff: infra/bots/assets/assets.py

Issue 2069543002: Add asset management scripts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add FYI prints for asset creation Created 4 years, 6 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
stephana 2016/06/15 13:57:30 Why not merge asset_utils in here? It looks like i
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Tool for managing assets."""
10
11
12 import argparse
13 import asset_utils
14 import os
15 import shutil
16 import subprocess
17 import sys
18
19 FILE_DIR = os.path.dirname(os.path.abspath(__file__))
20 INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir))
21
22 sys.path.insert(0, INFRA_BOTS_DIR)
23 import utils
24
25
26 ASSETS_DIR = os.path.join(INFRA_BOTS_DIR, 'assets')
27
28
29 def add(args):
30 """Add a new asset."""
31 # Ensure that the asset does not already exist.
32 asset_dir = os.path.join(ASSETS_DIR, args.asset_name)
33 if os.path.isdir(asset_dir):
34 raise Exception('Asset %s already exists!' % args.asset_name)
35
36 # Create upload and download scripts for the asset.
37 print 'Creating asset in %s' % asset_dir
38 os.mkdir(asset_dir)
39 def copy_script(script):
40 src = os.path.join(ASSETS_DIR, 'scripts', script)
41 dst = os.path.join(asset_dir, script)
42 print 'Creating %s' % dst
43 shutil.copyfile(src, dst)
44 subprocess.check_call([utils.GIT, 'add', dst])
45
46 for script in ('download.py', 'upload.py'):
47 copy_script(script)
48 resp = raw_input('Add script to automate creation of this asset? (y/n) ')
49 if resp == 'y':
50 copy_script('create.py')
51 copy_script('create_and_upload.py')
52 print 'You will need to add implementation to the creation script.'
53 print 'Successfully created asset %s.' % args.asset_name
54
55
56 def remove(args):
57 """Remove an asset."""
58 # Ensure that the asset exists.
59 asset_dir = os.path.join(ASSETS_DIR, args.asset_name)
60 if not os.path.isdir(asset_dir):
61 raise Exception('Asset %s does not exist!' % args.asset_name)
62
63 # Remove the asset.
64 subprocess.check_call([utils.GIT, 'rm', '-rf', asset_dir])
65
66 # We *could* remove all uploaded versions of the asset in Google Storage but
67 # we choose not to be that destructive.
68
69
70 def download(args):
71 """Download the current version of an asset."""
72 asset = asset_utils.Asset(
73 args.asset_name, asset_utils.DEFAULT_GS_BUCKET, gsutil=args.gsutil)
74 asset.download_current_version(args.target_dir)
75
76
77 def upload(args):
78 """Upload a new version of the asset."""
79 asset = asset_utils.Asset(
80 args.asset_name, asset_utils.DEFAULT_GS_BUCKET, gsutil=args.gsutil)
81 asset.upload_new_version(args.target_dir, commit=args.commit)
82
83
84 def main(argv):
85 parser = argparse.ArgumentParser(description='Tool for managing assets.')
86 subs = parser.add_subparsers(help='Commands:')
87
88 prs_add = subs.add_parser('add', help='Add a new asset.')
89 prs_add.set_defaults(func=add)
90 prs_add.add_argument('asset_name', help='Name of the asset.')
91
92 prs_remove = subs.add_parser('remove', help='Remove an asset.')
93 prs_remove.set_defaults(func=remove)
94 prs_remove.add_argument('asset_name', help='Name of the asset.')
95
96 prs_download = subs.add_parser(
97 'download', help='Download the current version of an asset.')
98 prs_download.set_defaults(func=download)
99 prs_download.add_argument('asset_name', help='Name of the asset.')
100 prs_download.add_argument('--target_dir', '-t', required=True)
101 prs_download.add_argument('--gsutil')
102
103 prs_upload = subs.add_parser(
104 'upload', help='Upload a new version of an asset.')
105 prs_upload.set_defaults(func=upload)
106 prs_upload.add_argument('asset_name', help='Name of the asset.')
107 prs_upload.add_argument('--target_dir', '-t', required=True)
108 prs_upload.add_argument('--gsutil')
109 prs_upload.add_argument('--commit', action='store_true')
110
111 args = parser.parse_args(argv)
112 args.func(args)
113
114
115 if __name__ == '__main__':
116 main(sys.argv[1:])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698