blob: e4cdeb0f39732a7a2fd812155e42c5e46120812d [file] [log] [blame]
David Pursehouse8898e2f2012-11-14 07:51:03 +09001#!/usr/bin/env python
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07002#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Sarah Owenscecd1d82012-11-01 22:59:27 -070017from __future__ import print_function
JoonCheol Parke9860722012-10-11 02:31:44 +090018import getpass
Conley Owensc9129d92012-10-01 16:12:28 -070019import imp
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -070020import netrc
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070021import optparse
22import os
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070023import sys
Shawn O. Pearce3a0e7822011-09-22 17:06:41 -070024import time
David Pursehouse59bbb582013-05-17 10:49:33 +090025
26from pyversion import is_python3
27if is_python3():
Sarah Owens1f7627f2012-10-31 09:21:55 -070028 import urllib.request
29else:
David Pursehouse59bbb582013-05-17 10:49:33 +090030 import urllib2
Sarah Owens1f7627f2012-10-31 09:21:55 -070031 urllib = imp.new_module('urllib')
32 urllib.request = urllib2
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070033
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070034from trace import SetTrace
Shawn O. Pearce334851e2011-09-19 08:05:31 -070035from git_command import git, GitCommand
Doug Anderson0048b692010-12-21 13:39:23 -080036from git_config import init_ssh, close_ssh
Shawn O. Pearcec95583b2009-03-03 17:47:06 -080037from command import InteractiveCommand
38from command import MirrorSafeCommand
Shawn O. Pearceecff4f12011-11-29 15:01:33 -080039from subcmds.version import Version
Shawn O. Pearce7965f9f2008-10-29 15:20:02 -070040from editor import Editor
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -070041from error import DownloadError
Shawn O. Pearce559b8462009-03-02 12:56:08 -080042from error import ManifestInvalidRevisionError
David Pursehouse0b8df7b2012-11-13 09:51:57 +090043from error import ManifestParseError
Conley Owens75ee0572012-11-15 17:33:11 -080044from error import NoManifestException
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070045from error import NoSuchProjectError
46from error import RepoChangedException
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -070047from manifest_xml import XmlManifest
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070048from pager import RunPager
49
David Pursehouse5c6eeac2012-10-11 16:44:48 +090050from subcmds import all_commands
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070051
David Pursehouse59bbb582013-05-17 10:49:33 +090052if not is_python3():
53 # pylint:disable=W0622
Chirayu Desai217ea7d2013-03-01 19:14:38 +053054 input = raw_input
David Pursehouse59bbb582013-05-17 10:49:33 +090055 # pylint:enable=W0622
Chirayu Desai217ea7d2013-03-01 19:14:38 +053056
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070057global_options = optparse.OptionParser(
58 usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]"
59 )
60global_options.add_option('-p', '--paginate',
61 dest='pager', action='store_true',
62 help='display command output in the pager')
63global_options.add_option('--no-pager',
64 dest='no_pager', action='store_true',
65 help='disable the pager')
Shawn O. Pearce0ed2bd12009-03-09 18:26:31 -070066global_options.add_option('--trace',
67 dest='trace', action='store_true',
68 help='trace git command execution')
Shawn O. Pearce3a0e7822011-09-22 17:06:41 -070069global_options.add_option('--time',
70 dest='time', action='store_true',
71 help='time repo command execution')
Shawn O. Pearce47c1a632009-03-02 18:24:23 -080072global_options.add_option('--version',
73 dest='show_version', action='store_true',
74 help='display this version of repo')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070075
76class _Repo(object):
77 def __init__(self, repodir):
78 self.repodir = repodir
79 self.commands = all_commands
Mike Lockwood2bf9db02009-07-14 15:23:39 -040080 # add 'branch' as an alias for 'branches'
81 all_commands['branch'] = all_commands['branches']
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070082
83 def _Run(self, argv):
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -040084 result = 0
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070085 name = None
86 glob = []
87
Sarah Owensa6053d52012-11-01 13:36:50 -070088 for i in range(len(argv)):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070089 if not argv[i].startswith('-'):
90 name = argv[i]
91 if i > 0:
92 glob = argv[:i]
93 argv = argv[i + 1:]
94 break
95 if not name:
96 glob = argv
97 name = 'help'
98 argv = []
David Pursehouse8a68ff92012-09-24 12:15:13 +090099 gopts, _gargs = global_options.parse_args(glob)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700100
Shawn O. Pearce0ed2bd12009-03-09 18:26:31 -0700101 if gopts.trace:
Shawn O. Pearcead3193a2009-04-18 09:54:51 -0700102 SetTrace()
Shawn O. Pearce47c1a632009-03-02 18:24:23 -0800103 if gopts.show_version:
104 if name == 'help':
105 name = 'version'
106 else:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700107 print('fatal: invalid usage of --version', file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400108 return 1
Shawn O. Pearce47c1a632009-03-02 18:24:23 -0800109
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700110 try:
111 cmd = self.commands[name]
112 except KeyError:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700113 print("repo: '%s' is not a repo command. See 'repo help'." % name,
114 file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400115 return 1
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700116
117 cmd.repodir = self.repodir
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700118 cmd.manifest = XmlManifest(cmd.repodir)
Shawn O. Pearce7965f9f2008-10-29 15:20:02 -0700119 Editor.globalConfig = cmd.manifest.globalConfig
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700120
Shawn O. Pearcec95583b2009-03-03 17:47:06 -0800121 if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700122 print("fatal: '%s' requires a working directory" % name,
123 file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400124 return 1
Shawn O. Pearcec95583b2009-03-03 17:47:06 -0800125
Shawn O. Pearcedb45da12009-04-18 13:49:13 -0700126 copts, cargs = cmd.OptionParser.parse_args(argv)
David Pursehouseb148ac92012-11-16 09:33:39 +0900127 copts = cmd.ReadEnvironmentOptions(copts)
Shawn O. Pearcedb45da12009-04-18 13:49:13 -0700128
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700129 if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
130 config = cmd.manifest.globalConfig
131 if gopts.pager:
132 use_pager = True
133 else:
134 use_pager = config.GetBoolean('pager.%s' % name)
135 if use_pager is None:
Shawn O. Pearcedb45da12009-04-18 13:49:13 -0700136 use_pager = cmd.WantPager(copts)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700137 if use_pager:
138 RunPager(config)
139
Conley Owens7ba25be2012-11-14 14:18:06 -0800140 start = time.time()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700141 try:
Conley Owens7ba25be2012-11-14 14:18:06 -0800142 result = cmd.Execute(copts, cargs)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700143 except DownloadError as e:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700144 print('error: %s' % str(e), file=sys.stderr)
Conley Owens7ba25be2012-11-14 14:18:06 -0800145 result = 1
Sarah Owensa5be53f2012-09-09 15:37:57 -0700146 except ManifestInvalidRevisionError as e:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700147 print('error: %s' % str(e), file=sys.stderr)
Conley Owens7ba25be2012-11-14 14:18:06 -0800148 result = 1
Conley Owens75ee0572012-11-15 17:33:11 -0800149 except NoManifestException as e:
150 print('error: manifest required for this command -- please run init',
151 file=sys.stderr)
152 result = 1
Sarah Owensa5be53f2012-09-09 15:37:57 -0700153 except NoSuchProjectError as e:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700154 if e.name:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700155 print('error: project %s not found' % e.name, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700156 else:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700157 print('error: no project in current directory', file=sys.stderr)
Conley Owens7ba25be2012-11-14 14:18:06 -0800158 result = 1
159 finally:
160 elapsed = time.time() - start
161 hours, remainder = divmod(elapsed, 3600)
162 minutes, seconds = divmod(remainder, 60)
163 if gopts.time:
164 if hours == 0:
165 print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr)
166 else:
167 print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
168 file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400169
170 return result
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700171
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700172def _MyRepoPath():
173 return os.path.dirname(__file__)
174
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700175def _MyWrapperPath():
176 return os.path.join(os.path.dirname(__file__), 'repo')
177
Conley Owensc9129d92012-10-01 16:12:28 -0700178_wrapper_module = None
179def WrapperModule():
180 global _wrapper_module
181 if not _wrapper_module:
182 _wrapper_module = imp.load_source('wrapper', _MyWrapperPath())
183 return _wrapper_module
184
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700185def _CurrentWrapperVersion():
Conley Owensc9129d92012-10-01 16:12:28 -0700186 return WrapperModule().VERSION
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700187
188def _CheckWrapperVersion(ver, repo_path):
189 if not repo_path:
190 repo_path = '~/bin/repo'
191
192 if not ver:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700193 print('no --wrapper-version argument', file=sys.stderr)
David Pursehouse8a68ff92012-09-24 12:15:13 +0900194 sys.exit(1)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700195
196 exp = _CurrentWrapperVersion()
David Pursehouse7e6dd2d2012-10-25 12:40:51 +0900197 ver = tuple(map(int, ver.split('.')))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700198 if len(ver) == 1:
199 ver = (0, ver[0])
200
David Pursehouse7e6dd2d2012-10-25 12:40:51 +0900201 exp_str = '.'.join(map(str, exp))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700202 if exp[0] > ver[0] or ver < (0, 4):
Sarah Owenscecd1d82012-11-01 22:59:27 -0700203 print("""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700204!!! A new repo command (%5s) is available. !!!
205!!! You must upgrade before you can continue: !!!
206
207 cp %s %s
Sarah Owenscecd1d82012-11-01 22:59:27 -0700208""" % (exp_str, _MyWrapperPath(), repo_path), file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700209 sys.exit(1)
210
211 if exp > ver:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700212 print("""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700213... A new repo command (%5s) is available.
214... You should upgrade soon:
215
216 cp %s %s
Sarah Owenscecd1d82012-11-01 22:59:27 -0700217""" % (exp_str, _MyWrapperPath(), repo_path), file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700218
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200219def _CheckRepoDir(repo_dir):
220 if not repo_dir:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700221 print('no --repo-dir argument', file=sys.stderr)
David Pursehouse8a68ff92012-09-24 12:15:13 +0900222 sys.exit(1)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700223
224def _PruneOptions(argv, opt):
225 i = 0
226 while i < len(argv):
227 a = argv[i]
228 if a == '--':
229 break
230 if a.startswith('--'):
231 eq = a.find('=')
232 if eq > 0:
233 a = a[0:eq]
234 if not opt.has_option(a):
235 del argv[i]
236 continue
237 i += 1
238
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700239_user_agent = None
240
241def _UserAgent():
242 global _user_agent
243
244 if _user_agent is None:
245 py_version = sys.version_info
246
247 os_name = sys.platform
248 if os_name == 'linux2':
249 os_name = 'Linux'
250 elif os_name == 'win32':
251 os_name = 'Win32'
252 elif os_name == 'cygwin':
253 os_name = 'Cygwin'
254 elif os_name == 'darwin':
255 os_name = 'Darwin'
256
257 p = GitCommand(
258 None, ['describe', 'HEAD'],
259 cwd = _MyRepoPath(),
260 capture_stdout = True)
261 if p.Wait() == 0:
262 repo_version = p.stdout
263 if len(repo_version) > 0 and repo_version[-1] == '\n':
264 repo_version = repo_version[0:-1]
265 if len(repo_version) > 0 and repo_version[0] == 'v':
266 repo_version = repo_version[1:]
267 else:
268 repo_version = 'unknown'
269
270 _user_agent = 'git-repo/%s (%s) git/%s Python/%d.%d.%d' % (
271 repo_version,
272 os_name,
David Pursehouse7e6dd2d2012-10-25 12:40:51 +0900273 '.'.join(map(str, git.version_tuple())),
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700274 py_version[0], py_version[1], py_version[2])
275 return _user_agent
276
Sarah Owens1f7627f2012-10-31 09:21:55 -0700277class _UserAgentHandler(urllib.request.BaseHandler):
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700278 def http_request(self, req):
279 req.add_header('User-Agent', _UserAgent())
280 return req
281
282 def https_request(self, req):
283 req.add_header('User-Agent', _UserAgent())
284 return req
285
JoonCheol Parke9860722012-10-11 02:31:44 +0900286def _AddPasswordFromUserInput(handler, msg, req):
David Pursehousec1b86a22012-11-14 11:36:51 +0900287 # If repo could not find auth info from netrc, try to get it from user input
288 url = req.get_full_url()
289 user, password = handler.passwd.find_user_password(None, url)
290 if user is None:
291 print(msg)
292 try:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530293 user = input('User: ')
David Pursehousec1b86a22012-11-14 11:36:51 +0900294 password = getpass.getpass()
295 except KeyboardInterrupt:
296 return
297 handler.passwd.add_password(None, url, user, password)
JoonCheol Parke9860722012-10-11 02:31:44 +0900298
Sarah Owens1f7627f2012-10-31 09:21:55 -0700299class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler):
JoonCheol Parke9860722012-10-11 02:31:44 +0900300 def http_error_401(self, req, fp, code, msg, headers):
301 _AddPasswordFromUserInput(self, msg, req)
Sarah Owens1f7627f2012-10-31 09:21:55 -0700302 return urllib.request.HTTPBasicAuthHandler.http_error_401(
JoonCheol Parke9860722012-10-11 02:31:44 +0900303 self, req, fp, code, msg, headers)
304
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700305 def http_error_auth_reqed(self, authreq, host, req, headers):
306 try:
Shawn O. Pearcedf5ee522011-10-11 14:05:21 -0700307 old_add_header = req.add_header
308 def _add_header(name, val):
309 val = val.replace('\n', '')
310 old_add_header(name, val)
311 req.add_header = _add_header
Sarah Owens1f7627f2012-10-31 09:21:55 -0700312 return urllib.request.AbstractBasicAuthHandler.http_error_auth_reqed(
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700313 self, authreq, host, req, headers)
314 except:
Shawn O. Pearcedf5ee522011-10-11 14:05:21 -0700315 reset = getattr(self, 'reset_retry_count', None)
316 if reset is not None:
317 reset()
Shawn O. Pearceb6605392011-10-11 15:58:07 -0700318 elif getattr(self, 'retried', None):
319 self.retried = 0
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700320 raise
321
Sarah Owens1f7627f2012-10-31 09:21:55 -0700322class _DigestAuthHandler(urllib.request.HTTPDigestAuthHandler):
JoonCheol Parke9860722012-10-11 02:31:44 +0900323 def http_error_401(self, req, fp, code, msg, headers):
324 _AddPasswordFromUserInput(self, msg, req)
Sarah Owens1f7627f2012-10-31 09:21:55 -0700325 return urllib.request.HTTPDigestAuthHandler.http_error_401(
JoonCheol Parke9860722012-10-11 02:31:44 +0900326 self, req, fp, code, msg, headers)
327
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800328 def http_error_auth_reqed(self, auth_header, host, req, headers):
329 try:
330 old_add_header = req.add_header
331 def _add_header(name, val):
332 val = val.replace('\n', '')
333 old_add_header(name, val)
334 req.add_header = _add_header
Sarah Owens1f7627f2012-10-31 09:21:55 -0700335 return urllib.request.AbstractDigestAuthHandler.http_error_auth_reqed(
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800336 self, auth_header, host, req, headers)
337 except:
338 reset = getattr(self, 'reset_retry_count', None)
339 if reset is not None:
340 reset()
341 elif getattr(self, 'retried', None):
342 self.retried = 0
343 raise
344
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700345def init_http():
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700346 handlers = [_UserAgentHandler()]
347
Sarah Owens1f7627f2012-10-31 09:21:55 -0700348 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -0700349 try:
350 n = netrc.netrc()
351 for host in n.hosts:
352 p = n.hosts[host]
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800353 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
354 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -0700355 except netrc.NetrcParseError:
356 pass
Shawn O. Pearce7b947de2011-09-23 11:50:31 -0700357 except IOError:
358 pass
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700359 handlers.append(_BasicAuthHandler(mgr))
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800360 handlers.append(_DigestAuthHandler(mgr))
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -0700361
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700362 if 'http_proxy' in os.environ:
363 url = os.environ['http_proxy']
Sarah Owens1f7627f2012-10-31 09:21:55 -0700364 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700365 if 'REPO_CURL_VERBOSE' in os.environ:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700366 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
367 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
368 urllib.request.install_opener(urllib.request.build_opener(*handlers))
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700369
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700370def _Main(argv):
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400371 result = 0
372
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700373 opt = optparse.OptionParser(usage="repo wrapperinfo -- ...")
374 opt.add_option("--repo-dir", dest="repodir",
375 help="path to .repo/")
376 opt.add_option("--wrapper-version", dest="wrapper_version",
377 help="version of the wrapper script")
378 opt.add_option("--wrapper-path", dest="wrapper_path",
379 help="location of the wrapper script")
380 _PruneOptions(argv, opt)
381 opt, argv = opt.parse_args(argv)
382
383 _CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path)
384 _CheckRepoDir(opt.repodir)
385
Shawn O. Pearceecff4f12011-11-29 15:01:33 -0800386 Version.wrapper_version = opt.wrapper_version
387 Version.wrapper_path = opt.wrapper_path
388
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700389 repo = _Repo(opt.repodir)
390 try:
Shawn O. Pearcefb231612009-04-10 18:53:46 -0700391 try:
Doug Anderson0048b692010-12-21 13:39:23 -0800392 init_ssh()
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700393 init_http()
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400394 result = repo._Run(argv) or 0
Shawn O. Pearcefb231612009-04-10 18:53:46 -0700395 finally:
396 close_ssh()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700397 except KeyboardInterrupt:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700398 print('aborted by user', file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400399 result = 1
David Pursehouse0b8df7b2012-11-13 09:51:57 +0900400 except ManifestParseError as mpe:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700401 print('fatal: %s' % mpe, file=sys.stderr)
David Pursehouse0b8df7b2012-11-13 09:51:57 +0900402 result = 1
Sarah Owensa5be53f2012-09-09 15:37:57 -0700403 except RepoChangedException as rce:
Shawn O. Pearcec9ef7442008-11-03 10:32:09 -0800404 # If repo changed, re-exec ourselves.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700405 #
Shawn O. Pearcec9ef7442008-11-03 10:32:09 -0800406 argv = list(sys.argv)
407 argv.extend(rce.extra_args)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700408 try:
Shawn O. Pearcec9ef7442008-11-03 10:32:09 -0800409 os.execv(__file__, argv)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700410 except OSError as e:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700411 print('fatal: cannot restart repo after upgrade', file=sys.stderr)
412 print('fatal: %s' % e, file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400413 result = 128
414
415 sys.exit(result)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700416
417if __name__ == '__main__':
418 _Main(sys.argv[1:])