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

Side by Side Diff: cit.py

Issue 2117943002: Add cipd binary support to cit.py (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 6
7 """Wrapper for updating and calling infra.git tools. 7 """Wrapper for updating and calling infra.git tools.
8 8
9 This tool does a two things: 9 This tool does a two things:
10 * Maintains a infra.git checkout pinned at "deployed" in the home dir 10 * Maintains a infra.git checkout pinned at "deployed" in the home dir
11 * Acts as an alias to infra.tools.* 11 * Acts as an alias to infra.tools.*
12 * Acts as an alias to infra.git/cipd/<executable>
12 """ 13 """
13 14
14 # TODO(hinoka): Use cipd/glyco instead of git/gclient. 15 # TODO(hinoka): Use cipd/glyco instead of git/gclient.
15 16
16 import argparse 17 import argparse
17 import sys 18 import sys
18 import os 19 import os
19 import subprocess 20 import subprocess
20 import re 21 import re
21 22
(...skipping 27 matching lines...) Expand all
49 50
50 subprocess.check_call( 51 subprocess.check_call(
51 ['git', 'fetch', 'origin'], cwd=INFRA_DIR, 52 ['git', 'fetch', 'origin'], cwd=INFRA_DIR,
52 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 53 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
53 origin_rev = get_git_rev(INFRA_DIR, 'origin/%s' % (branch,)) 54 origin_rev = get_git_rev(INFRA_DIR, 'origin/%s' % (branch,))
54 return origin_rev != local_rev 55 return origin_rev != local_rev
55 56
56 57
57 def ensure_infra(branch): 58 def ensure_infra(branch):
58 """Ensures that infra.git is present in ~/.chrome-infra.""" 59 """Ensures that infra.git is present in ~/.chrome-infra."""
59 sys.stderr.write( 60 print 'Fetching infra@%s into %s, may take a couple of minutes...' % (
60 'Fetching infra@%s into %s, may take a couple of minutes...' % ( 61 branch, TARGET_DIR)
61 branch, TARGET_DIR))
62 sys.stderr.flush()
tandrii(chromium) 2016/07/14 12:59:26 you really don't like my stderr writing :( the pur
Ryan Tseng 2016/07/14 20:27:11 Oops I think this was a mistake, or I rebased badl
63 if not os.path.isdir(TARGET_DIR): 62 if not os.path.isdir(TARGET_DIR):
64 os.mkdir(TARGET_DIR) 63 os.mkdir(TARGET_DIR)
65 if not os.path.exists(os.path.join(TARGET_DIR, '.gclient')): 64 if not os.path.exists(os.path.join(TARGET_DIR, '.gclient')):
66 subprocess.check_call( 65 subprocess.check_call(
67 [sys.executable, os.path.join(SCRIPT_DIR, 'fetch.py'), 'infra'], 66 [sys.executable, os.path.join(SCRIPT_DIR, 'fetch.py'), 'infra'],
68 cwd=TARGET_DIR, 67 cwd=TARGET_DIR,
69 stdout=subprocess.PIPE) 68 stdout=subprocess.PIPE)
70 subprocess.check_call( 69 subprocess.check_call(
71 [sys.executable, GCLIENT, 'sync', '--revision', 'origin/%s' % (branch,)], 70 [sys.executable, GCLIENT, 'sync', '--revision', 'origin/%s' % (branch,)],
72 cwd=TARGET_DIR, 71 cwd=TARGET_DIR,
73 stdout=subprocess.PIPE) 72 stdout=subprocess.PIPE)
74 sys.stderr.write(' done.\n') 73
75 sys.stderr.flush() 74
75 def is_exe(filename):
76 """Given a full filepath, return true if the file is an executable."""
77 if sys.platform.startswith('win'):
78 return filename.endswith('.exe')
79 else:
80 return os.path.isfile(filename) and os.access(filename, os.X_OK)
76 81
77 82
78 def get_available_tools(): 83 def get_available_tools():
79 tools = [] 84 """Returns a tuple of (list of infra tools, list of cipd tools)"""
85 infra_tools = []
86 cipd_tools = []
80 starting = os.path.join(TARGET_DIR, 'infra', 'infra', 'tools') 87 starting = os.path.join(TARGET_DIR, 'infra', 'infra', 'tools')
81 for root, _, files in os.walk(starting): 88 for root, _, files in os.walk(starting):
82 if '__main__.py' in files: 89 if '__main__.py' in files:
83 tools.append(root[len(starting)+1:].replace(os.path.sep, '.')) 90 infra_tools.append(root[len(starting)+1:].replace(os.path.sep, '.'))
84 return sorted(tools) 91 cipd = os.path.join(TARGET_DIR, 'infra', 'cipd')
92 for fn in os.listdir(cipd):
93 if is_exe(os.path.join(cipd, fn)):
94 cipd_tools.append(fn)
95 return (sorted(infra_tools), sorted(cipd_tools))
85 96
86 97
87 def run(args): 98 def run(args):
88 if args: 99 if args:
89 tool_name = args[0] 100 tool_name = args[0]
90 cmd = [ 101 # Check to see if it is a infra tool first.
91 sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'), 102 infra_dir = os.path.join(
92 'infra.tools.%s' % tool_name] 103 TARGET_DIR, 'infra', 'infra', 'tools', *tool_name.split('.'))
104 cipd_file = os.path.join(TARGET_DIR, 'infra', 'cipd', tool_name)
105 if sys.platform.startswith('win'):
106 cipd_file += '.exe'
107 if (os.path.isdir(infra_dir)
108 and os.path.isfile(os.path.join(infra_dir, '__main__.py'))):
109 cmd = [
110 sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'),
111 'infra.tools.%s' % tool_name]
112 elif os.path.isfile(cipd_file) and is_exe(cipd_file):
113 cmd = [cipd_file]
114
115 # Add the remaining arguments.
93 cmd.extend(args[1:]) 116 cmd.extend(args[1:])
94 return subprocess.call(cmd) 117 return subprocess.call(cmd)
95 118
96 tools = get_available_tools() 119 infra_tools, cipd_tools = get_available_tools()
97 print """usage: cit.py <name of tool> [args for tool] 120 print """usage: cit.py <name of tool> [args for tool]
98 121
99 Wrapper for maintaining and calling tools in "infra.git/run.py infra.tools.*" 122 Wrapper for maintaining and calling tools in:
123 "infra.git/run.py infra.tools.*"
124 "infra.git/cipd/*"
100 125
101 Available tools are: 126 Available infra tools are:"""
102 """ 127 for tool in infra_tools:
103 for tool in tools:
104 print ' * %s' % tool 128 print ' * %s' % tool
105 129
130 print """
131 Available cipd tools are:"""
132 for tool in cipd_tools:
133 print ' * %s' % tool
134
135
106 136
107 def main(): 137 def main():
108 parser = argparse.ArgumentParser("Chrome Infrastructure CLI.") 138 parser = argparse.ArgumentParser("Chrome Infrastructure CLI.")
109 parser.add_argument('-b', '--infra-branch', default='deployed', 139 parser.add_argument('-b', '--infra-branch', default='deployed',
110 help="The name of the 'infra' branch to use (default is %(default)s).") 140 help="The name of the 'infra' branch to use (default is %(default)s).")
111 parser.add_argument('args', nargs=argparse.REMAINDER) 141 parser.add_argument('args', nargs=argparse.REMAINDER)
112 142
113 args, extras = parser.parse_known_args() 143 args, extras = parser.parse_known_args()
114 if args.args and args.args[0] == '--': 144 if args.args and args.args[0] == '--':
115 args.args.pop(0) 145 args.args.pop(0)
116 if extras: 146 if extras:
117 args.args = extras + args.args 147 args.args = extras + args.args
118 148
119 if need_to_update(args.infra_branch): 149 if need_to_update(args.infra_branch):
120 ensure_infra(args.infra_branch) 150 ensure_infra(args.infra_branch)
121 return run(args.args) 151 return run(args.args)
122 152
123 if __name__ == '__main__': 153 if __name__ == '__main__':
124 sys.exit(main()) 154 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698