OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
7 | 7 |
8 Files | 8 Files |
9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1114 client = GClient.LoadCurrentConfig(options) | 1114 client = GClient.LoadCurrentConfig(options) |
1115 if not client: | 1115 if not client: |
1116 raise gclient_utils.Error('client not configured; see \'gclient config\'') | 1116 raise gclient_utils.Error('client not configured; see \'gclient config\'') |
1117 if options.verbose: | 1117 if options.verbose: |
1118 # Print out the .gclient file. This is longer than if we just printed the | 1118 # Print out the .gclient file. This is longer than if we just printed the |
1119 # client dict, but more legible, and it might contain helpful comments. | 1119 # client dict, but more legible, and it might contain helpful comments. |
1120 print(client.config_content) | 1120 print(client.config_content) |
1121 return client.RunOnDeps('cleanup', args) | 1121 return client.RunOnDeps('cleanup', args) |
1122 | 1122 |
1123 | 1123 |
1124 class Entry(gclient_utils.WorkItem): | |
M-A Ruel
2012/03/01 14:12:12
I'm a tad uncomfortable with this class. I'd rathe
| |
1125 """Object that represents a gclient entry.""" | |
1126 | |
1127 def __init__(self, name, scm, cwd, url): | |
1128 gclient_utils.WorkItem.__init__(self, name) | |
1129 self._scm = scm | |
1130 self._cwd = cwd | |
1131 self._url = url | |
1132 self.requirements = {} | |
1133 | |
1134 # Arguments number differs from overridden method | |
1135 # pylint: disable=W0221 | |
1136 def run(self, revision_overrides, command, args, work_queue, options): | |
1137 """Executes a command in a given module.""" | |
1138 assert command == 'exec' | |
1139 # Pass in the SCM type as an env variable | |
1140 env = os.environ.copy() | |
1141 if self._scm: | |
1142 env['GCLIENT_SCM'] = self._scm | |
1143 if self._url: | |
1144 env['GCLIENT_URL'] = self._url | |
1145 if os.path.isdir(self._cwd): | |
1146 subprocess2.call(args, cwd=self._cwd, env=env) | |
davidbarr
2012/03/01 05:33:15
Maybe this should be a wrapper method provided by
| |
1147 else: | |
1148 print >> sys.stderr, 'Skipped missing %s' % self._cwd | |
1149 | |
davidbarr
2012/03/01 05:33:15
Whitespace nit.
| |
1124 @attr('usage', '[command] [args ...]') | 1150 @attr('usage', '[command] [args ...]') |
1125 def CMDrecurse(parser, args): | 1151 def CMDrecurse(parser, args): |
1126 """Operates on all the entries. | 1152 """Operates on all the entries. |
1127 | 1153 |
1128 Runs a shell command on all entries. | 1154 Runs a shell command on all entries. |
1129 """ | 1155 """ |
1130 # Stop parsing at the first non-arg so that these go through to the command | 1156 # Stop parsing at the first non-arg so that these go through to the command |
1131 parser.disable_interspersed_args() | 1157 parser.disable_interspersed_args() |
1132 parser.add_option('-s', '--scm', action='append', default=[], | 1158 parser.add_option('-s', '--scm', action='append', default=[], |
1133 help='choose scm types to operate upon') | 1159 help='choose scm types to operate upon') |
1134 parser.remove_option('--jobs') | |
1135 options, args = parser.parse_args(args) | 1160 options, args = parser.parse_args(args) |
1136 if not args: | 1161 if not args: |
1137 print >> sys.stderr, 'Need to supply a command!' | 1162 print >> sys.stderr, 'Need to supply a command!' |
1138 return 1 | 1163 return 1 |
1139 root_and_entries = gclient_utils.GetGClientRootAndEntries() | 1164 root_and_entries = gclient_utils.GetGClientRootAndEntries() |
1140 if not root_and_entries: | 1165 if not root_and_entries: |
1141 print >> sys.stderr, ( | 1166 print >> sys.stderr, ( |
1142 'You need to run gclient sync at least once to use \'recurse\'.\n' | 1167 'You need to run gclient sync at least once to use \'recurse\'.\n' |
1143 'This is because .gclient_entries needs to exist and be up to date.') | 1168 'This is because .gclient_entries needs to exist and be up to date.') |
1144 return 1 | 1169 return 1 |
1145 root, entries = root_and_entries | 1170 root, entries = root_and_entries |
1146 scm_set = set() | 1171 scm_set = set() |
1147 for scm in options.scm: | 1172 for scm in options.scm: |
1148 scm_set.update(scm.split(',')) | 1173 scm_set.update(scm.split(',')) |
1149 | 1174 |
1150 # Pass in the SCM type as an env variable | 1175 pm = None |
1151 env = os.environ.copy() | 1176 # Disable progress for non-tty stdout. |
1152 | 1177 if (sys.stdout.isatty() and not options.verbose): |
1178 pm = Progress(' '.join(args), 1) | |
1179 work_queue = gclient_utils.ExecutionQueue(options.jobs, pm) | |
1153 for path, url in entries.iteritems(): | 1180 for path, url in entries.iteritems(): |
1154 scm = gclient_scm.GetScmName(url) | 1181 scm = gclient_scm.GetScmName(url) |
1155 if scm_set and scm not in scm_set: | 1182 if scm_set and scm not in scm_set: |
1156 continue | 1183 continue |
1157 cwd = os.path.normpath(os.path.join(root, path)) | 1184 cwd = os.path.normpath(os.path.join(root, path)) |
1158 if scm: | 1185 work_queue.enqueue(Entry(path, scm, cwd, url)) |
1159 env['GCLIENT_SCM'] = scm | 1186 work_queue.flush({}, 'exec', args, options=options) |
1160 if url: | |
1161 env['GCLIENT_URL'] = url | |
1162 if os.path.isdir(cwd): | |
1163 subprocess2.call(args, cwd=cwd, env=env) | |
1164 else: | |
1165 print >> sys.stderr, 'Skipped missing %s' % cwd | |
1166 return 0 | 1187 return 0 |
1167 | 1188 |
1168 | 1189 |
1169 @attr('usage', '[args ...]') | 1190 @attr('usage', '[args ...]') |
1170 def CMDfetch(parser, args): | 1191 def CMDfetch(parser, args): |
1171 """Fetches upstream commits for all modules. | 1192 """Fetches upstream commits for all modules. |
1172 | 1193 |
1173 Completely git-specific. Simply runs 'git fetch [args ...]' for each module. | 1194 Completely git-specific. Simply runs 'git fetch [args ...]' for each module. |
1174 """ | 1195 """ |
1175 (_, args) = parser.parse_args(args) | 1196 (options, args) = parser.parse_args(args) |
1176 args = ['-s', 'git', 'git', 'fetch'] + args | 1197 args = ['-j%d' % options.jobs, '-s', 'git', 'git', 'fetch'] + args |
davidbarr
2012/03/01 05:33:15
Is this necessary? Will the parser accumulate opti
| |
1177 return CMDrecurse(parser, args) | 1198 return CMDrecurse(parser, args) |
1178 | 1199 |
1179 | 1200 |
1180 @attr('usage', '[url] [safesync url]') | 1201 @attr('usage', '[url] [safesync url]') |
1181 def CMDconfig(parser, args): | 1202 def CMDconfig(parser, args): |
1182 """Create a .gclient file in the current directory. | 1203 """Create a .gclient file in the current directory. |
1183 | 1204 |
1184 This specifies the configuration for further commands. After update/sync, | 1205 This specifies the configuration for further commands. After update/sync, |
1185 top-level DEPS files in each module are read to determine dependent | 1206 top-level DEPS files in each module are read to determine dependent |
1186 modules to operate on as well. If optional [url] parameter is | 1207 modules to operate on as well. If optional [url] parameter is |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1549 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1570 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
1550 print >> sys.stderr, 'Error: %s' % str(e) | 1571 print >> sys.stderr, 'Error: %s' % str(e) |
1551 return 1 | 1572 return 1 |
1552 | 1573 |
1553 | 1574 |
1554 if '__main__' == __name__: | 1575 if '__main__' == __name__: |
1555 fix_encoding.fix_encoding() | 1576 fix_encoding.fix_encoding() |
1556 sys.exit(Main(sys.argv[1:])) | 1577 sys.exit(Main(sys.argv[1:])) |
1557 | 1578 |
1558 # vim: ts=2:sw=2:tw=80:et: | 1579 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |