OLD | NEW |
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 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 for root, _, files in os.walk(starting): | 92 for root, _, files in os.walk(starting): |
93 if '__main__.py' in files: | 93 if '__main__.py' in files: |
94 infra_tools.append(root[len(starting)+1:].replace(os.path.sep, '.')) | 94 infra_tools.append(root[len(starting)+1:].replace(os.path.sep, '.')) |
95 cipd = os.path.join(TARGET_DIR, 'infra', 'cipd') | 95 cipd = os.path.join(TARGET_DIR, 'infra', 'cipd') |
96 for fn in os.listdir(cipd): | 96 for fn in os.listdir(cipd): |
97 if is_exe(os.path.join(cipd, fn)): | 97 if is_exe(os.path.join(cipd, fn)): |
98 cipd_tools.append(fn) | 98 cipd_tools.append(fn) |
99 return (sorted(infra_tools), sorted(cipd_tools)) | 99 return (sorted(infra_tools), sorted(cipd_tools)) |
100 | 100 |
101 | 101 |
102 def run(args): | 102 def usage(): |
103 if args: | |
104 tool_name = args[0] | |
105 # Check to see if it is a infra tool first. | |
106 infra_dir = os.path.join( | |
107 TARGET_DIR, 'infra', 'infra', 'tools', *tool_name.split('.')) | |
108 cipd_file = os.path.join(TARGET_DIR, 'infra', 'cipd', tool_name) | |
109 if sys.platform.startswith('win'): | |
110 cipd_file += '.exe' | |
111 if (os.path.isdir(infra_dir) | |
112 and os.path.isfile(os.path.join(infra_dir, '__main__.py'))): | |
113 cmd = [ | |
114 sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'), | |
115 'infra.tools.%s' % tool_name] | |
116 elif os.path.isfile(cipd_file) and is_exe(cipd_file): | |
117 cmd = [cipd_file] | |
118 | |
119 # Add the remaining arguments. | |
120 cmd.extend(args[1:]) | |
121 return subprocess.call(cmd) | |
122 | |
123 infra_tools, cipd_tools = get_available_tools() | 103 infra_tools, cipd_tools = get_available_tools() |
124 print """usage: cit.py <name of tool> [args for tool] | 104 print """usage: cit.py <name of tool> [args for tool] |
125 | 105 |
126 Wrapper for maintaining and calling tools in: | 106 Wrapper for maintaining and calling tools in: |
127 "infra.git/run.py infra.tools.*" | 107 "infra.git/run.py infra.tools.*" |
128 "infra.git/cipd/*" | 108 "infra.git/cipd/*" |
129 | 109 |
130 Available infra tools are:""" | 110 Available infra tools are:""" |
131 for tool in infra_tools: | 111 for tool in infra_tools: |
132 print ' * %s' % tool | 112 print ' * %s' % tool |
133 | 113 |
134 print """ | 114 print """ |
135 Available cipd tools are:""" | 115 Available cipd tools are:""" |
136 for tool in cipd_tools: | 116 for tool in cipd_tools: |
137 print ' * %s' % tool | 117 print ' * %s' % tool |
138 | 118 |
139 | 119 |
| 120 def run(args): |
| 121 if not args: |
| 122 return usage() |
| 123 |
| 124 tool_name = args[0] |
| 125 # Check to see if it is a infra tool first. |
| 126 infra_dir = os.path.join( |
| 127 TARGET_DIR, 'infra', 'infra', 'tools', *tool_name.split('.')) |
| 128 cipd_file = os.path.join(TARGET_DIR, 'infra', 'cipd', tool_name) |
| 129 if sys.platform.startswith('win'): |
| 130 cipd_file += '.exe' |
| 131 if (os.path.isdir(infra_dir) |
| 132 and os.path.isfile(os.path.join(infra_dir, '__main__.py'))): |
| 133 cmd = [ |
| 134 sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'), |
| 135 'infra.tools.%s' % tool_name] |
| 136 elif os.path.isfile(cipd_file) and is_exe(cipd_file): |
| 137 cmd = [cipd_file] |
| 138 else: |
| 139 print >>sys.stderr, 'Unknown tool "%s"' % tool_name |
| 140 return usage() |
| 141 |
| 142 # Add the remaining arguments. |
| 143 cmd.extend(args[1:]) |
| 144 return subprocess.call(cmd) |
| 145 |
140 | 146 |
141 def main(): | 147 def main(): |
142 parser = argparse.ArgumentParser("Chrome Infrastructure CLI.") | 148 parser = argparse.ArgumentParser("Chrome Infrastructure CLI.") |
143 parser.add_argument('-b', '--infra-branch', default='deployed', | 149 parser.add_argument('-b', '--infra-branch', default='deployed', |
144 help="The name of the 'infra' branch to use (default is %(default)s).") | 150 help="The name of the 'infra' branch to use (default is %(default)s).") |
145 parser.add_argument('args', nargs=argparse.REMAINDER) | 151 parser.add_argument('args', nargs=argparse.REMAINDER) |
146 | 152 |
147 args, extras = parser.parse_known_args() | 153 args, extras = parser.parse_known_args() |
148 if args.args and args.args[0] == '--': | 154 if args.args and args.args[0] == '--': |
149 args.args.pop(0) | 155 args.args.pop(0) |
150 if extras: | 156 if extras: |
151 args.args = extras + args.args | 157 args.args = extras + args.args |
152 | 158 |
153 if need_to_update(args.infra_branch): | 159 if need_to_update(args.infra_branch): |
154 ensure_infra(args.infra_branch) | 160 ensure_infra(args.infra_branch) |
155 return run(args.args) | 161 return run(args.args) |
156 | 162 |
157 if __name__ == '__main__': | 163 if __name__ == '__main__': |
158 sys.exit(main()) | 164 sys.exit(main()) |
OLD | NEW |