The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 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 | |
| 17 | magic='--calling-python-from-/bin/sh--' |
Shawn O. Pearce | 7542d66 | 2008-10-21 07:11:36 -0700 | [diff] [blame] | 18 | """exec" python -E "$0" "$@" """#$magic" |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | if __name__ == '__main__': |
| 20 | import sys |
| 21 | if sys.argv[-1] == '#%s' % magic: |
| 22 | del sys.argv[-1] |
| 23 | del magic |
| 24 | |
Shawn O. Pearce | bd0312a | 2011-09-19 10:04:23 -0700 | [diff] [blame] | 25 | import netrc |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | import optparse |
| 27 | import os |
| 28 | import re |
| 29 | import sys |
Shawn O. Pearce | 3a0e782 | 2011-09-22 17:06:41 -0700 | [diff] [blame] | 30 | import time |
Shawn O. Pearce | 014d060 | 2011-09-11 12:57:15 -0700 | [diff] [blame] | 31 | import urllib2 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | |
Shawn O. Pearce | ad3193a | 2009-04-18 09:54:51 -0700 | [diff] [blame] | 33 | from trace import SetTrace |
Shawn O. Pearce | 334851e | 2011-09-19 08:05:31 -0700 | [diff] [blame] | 34 | from git_command import git, GitCommand |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 35 | from git_config import init_ssh, close_ssh |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 36 | from command import InteractiveCommand |
| 37 | from command import MirrorSafeCommand |
Shawn O. Pearce | ecff4f1 | 2011-11-29 15:01:33 -0800 | [diff] [blame] | 38 | from subcmds.version import Version |
Shawn O. Pearce | 7965f9f | 2008-10-29 15:20:02 -0700 | [diff] [blame] | 39 | from editor import Editor |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 40 | from error import DownloadError |
Shawn O. Pearce | 559b846 | 2009-03-02 12:56:08 -0800 | [diff] [blame] | 41 | from error import ManifestInvalidRevisionError |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | from error import NoSuchProjectError |
| 43 | from error import RepoChangedException |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 44 | from manifest_xml import XmlManifest |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 45 | from pager import RunPager |
| 46 | |
| 47 | from subcmds import all as all_commands |
| 48 | |
| 49 | global_options = optparse.OptionParser( |
| 50 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" |
| 51 | ) |
| 52 | global_options.add_option('-p', '--paginate', |
| 53 | dest='pager', action='store_true', |
| 54 | help='display command output in the pager') |
| 55 | global_options.add_option('--no-pager', |
| 56 | dest='no_pager', action='store_true', |
| 57 | help='disable the pager') |
Shawn O. Pearce | 0ed2bd1 | 2009-03-09 18:26:31 -0700 | [diff] [blame] | 58 | global_options.add_option('--trace', |
| 59 | dest='trace', action='store_true', |
| 60 | help='trace git command execution') |
Shawn O. Pearce | 3a0e782 | 2011-09-22 17:06:41 -0700 | [diff] [blame] | 61 | global_options.add_option('--time', |
| 62 | dest='time', action='store_true', |
| 63 | help='time repo command execution') |
Shawn O. Pearce | 47c1a63 | 2009-03-02 18:24:23 -0800 | [diff] [blame] | 64 | global_options.add_option('--version', |
| 65 | dest='show_version', action='store_true', |
| 66 | help='display this version of repo') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 67 | |
| 68 | class _Repo(object): |
| 69 | def __init__(self, repodir): |
| 70 | self.repodir = repodir |
| 71 | self.commands = all_commands |
Mike Lockwood | 2bf9db0 | 2009-07-14 15:23:39 -0400 | [diff] [blame] | 72 | # add 'branch' as an alias for 'branches' |
| 73 | all_commands['branch'] = all_commands['branches'] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 74 | |
| 75 | def _Run(self, argv): |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 76 | result = 0 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | name = None |
| 78 | glob = [] |
| 79 | |
| 80 | for i in xrange(0, len(argv)): |
| 81 | if not argv[i].startswith('-'): |
| 82 | name = argv[i] |
| 83 | if i > 0: |
| 84 | glob = argv[:i] |
| 85 | argv = argv[i + 1:] |
| 86 | break |
| 87 | if not name: |
| 88 | glob = argv |
| 89 | name = 'help' |
| 90 | argv = [] |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame^] | 91 | gopts, _gargs = global_options.parse_args(glob) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 92 | |
Shawn O. Pearce | 0ed2bd1 | 2009-03-09 18:26:31 -0700 | [diff] [blame] | 93 | if gopts.trace: |
Shawn O. Pearce | ad3193a | 2009-04-18 09:54:51 -0700 | [diff] [blame] | 94 | SetTrace() |
Shawn O. Pearce | 47c1a63 | 2009-03-02 18:24:23 -0800 | [diff] [blame] | 95 | if gopts.show_version: |
| 96 | if name == 'help': |
| 97 | name = 'version' |
| 98 | else: |
| 99 | print >>sys.stderr, 'fatal: invalid usage of --version' |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 100 | return 1 |
Shawn O. Pearce | 47c1a63 | 2009-03-02 18:24:23 -0800 | [diff] [blame] | 101 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 102 | try: |
| 103 | cmd = self.commands[name] |
| 104 | except KeyError: |
| 105 | print >>sys.stderr,\ |
| 106 | "repo: '%s' is not a repo command. See 'repo help'."\ |
| 107 | % name |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 108 | return 1 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 109 | |
| 110 | cmd.repodir = self.repodir |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 111 | cmd.manifest = XmlManifest(cmd.repodir) |
Shawn O. Pearce | 7965f9f | 2008-10-29 15:20:02 -0700 | [diff] [blame] | 112 | Editor.globalConfig = cmd.manifest.globalConfig |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 114 | if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: |
| 115 | print >>sys.stderr, \ |
| 116 | "fatal: '%s' requires a working directory"\ |
| 117 | % name |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 118 | return 1 |
Shawn O. Pearce | c95583b | 2009-03-03 17:47:06 -0800 | [diff] [blame] | 119 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 120 | copts, cargs = cmd.OptionParser.parse_args(argv) |
| 121 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | if not gopts.no_pager and not isinstance(cmd, InteractiveCommand): |
| 123 | config = cmd.manifest.globalConfig |
| 124 | if gopts.pager: |
| 125 | use_pager = True |
| 126 | else: |
| 127 | use_pager = config.GetBoolean('pager.%s' % name) |
| 128 | if use_pager is None: |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 129 | use_pager = cmd.WantPager(copts) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 130 | if use_pager: |
| 131 | RunPager(config) |
| 132 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 133 | try: |
Shawn O. Pearce | 3a0e782 | 2011-09-22 17:06:41 -0700 | [diff] [blame] | 134 | start = time.time() |
| 135 | try: |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 136 | result = cmd.Execute(copts, cargs) |
Shawn O. Pearce | 3a0e782 | 2011-09-22 17:06:41 -0700 | [diff] [blame] | 137 | finally: |
| 138 | elapsed = time.time() - start |
| 139 | hours, remainder = divmod(elapsed, 3600) |
| 140 | minutes, seconds = divmod(remainder, 60) |
| 141 | if gopts.time: |
| 142 | if hours == 0: |
| 143 | print >>sys.stderr, 'real\t%dm%.3fs' \ |
| 144 | % (minutes, seconds) |
| 145 | else: |
| 146 | print >>sys.stderr, 'real\t%dh%dm%.3fs' \ |
| 147 | % (hours, minutes, seconds) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 148 | except DownloadError, e: |
| 149 | print >>sys.stderr, 'error: %s' % str(e) |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 150 | return 1 |
Shawn O. Pearce | 559b846 | 2009-03-02 12:56:08 -0800 | [diff] [blame] | 151 | except ManifestInvalidRevisionError, e: |
| 152 | print >>sys.stderr, 'error: %s' % str(e) |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 153 | return 1 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | except NoSuchProjectError, e: |
| 155 | if e.name: |
| 156 | print >>sys.stderr, 'error: project %s not found' % e.name |
| 157 | else: |
| 158 | print >>sys.stderr, 'error: no project in current directory' |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 159 | return 1 |
| 160 | |
| 161 | return result |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 162 | |
Shawn O. Pearce | 334851e | 2011-09-19 08:05:31 -0700 | [diff] [blame] | 163 | def _MyRepoPath(): |
| 164 | return os.path.dirname(__file__) |
| 165 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 166 | def _MyWrapperPath(): |
| 167 | return os.path.join(os.path.dirname(__file__), 'repo') |
| 168 | |
| 169 | def _CurrentWrapperVersion(): |
| 170 | VERSION = None |
| 171 | pat = re.compile(r'^VERSION *=') |
| 172 | fd = open(_MyWrapperPath()) |
| 173 | for line in fd: |
| 174 | if pat.match(line): |
| 175 | fd.close() |
| 176 | exec line |
| 177 | return VERSION |
| 178 | raise NameError, 'No VERSION in repo script' |
| 179 | |
| 180 | def _CheckWrapperVersion(ver, repo_path): |
| 181 | if not repo_path: |
| 182 | repo_path = '~/bin/repo' |
| 183 | |
| 184 | if not ver: |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame^] | 185 | print >>sys.stderr, 'no --wrapper-version argument' |
| 186 | sys.exit(1) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 187 | |
| 188 | exp = _CurrentWrapperVersion() |
| 189 | ver = tuple(map(lambda x: int(x), ver.split('.'))) |
| 190 | if len(ver) == 1: |
| 191 | ver = (0, ver[0]) |
| 192 | |
| 193 | if exp[0] > ver[0] or ver < (0, 4): |
| 194 | exp_str = '.'.join(map(lambda x: str(x), exp)) |
| 195 | print >>sys.stderr, """ |
| 196 | !!! A new repo command (%5s) is available. !!! |
| 197 | !!! You must upgrade before you can continue: !!! |
| 198 | |
| 199 | cp %s %s |
| 200 | """ % (exp_str, _MyWrapperPath(), repo_path) |
| 201 | sys.exit(1) |
| 202 | |
| 203 | if exp > ver: |
| 204 | exp_str = '.'.join(map(lambda x: str(x), exp)) |
| 205 | print >>sys.stderr, """ |
| 206 | ... A new repo command (%5s) is available. |
| 207 | ... You should upgrade soon: |
| 208 | |
| 209 | cp %s %s |
| 210 | """ % (exp_str, _MyWrapperPath(), repo_path) |
| 211 | |
| 212 | def _CheckRepoDir(dir): |
| 213 | if not dir: |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame^] | 214 | print >>sys.stderr, 'no --repo-dir argument' |
| 215 | sys.exit(1) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 216 | |
| 217 | def _PruneOptions(argv, opt): |
| 218 | i = 0 |
| 219 | while i < len(argv): |
| 220 | a = argv[i] |
| 221 | if a == '--': |
| 222 | break |
| 223 | if a.startswith('--'): |
| 224 | eq = a.find('=') |
| 225 | if eq > 0: |
| 226 | a = a[0:eq] |
| 227 | if not opt.has_option(a): |
| 228 | del argv[i] |
| 229 | continue |
| 230 | i += 1 |
| 231 | |
Shawn O. Pearce | 334851e | 2011-09-19 08:05:31 -0700 | [diff] [blame] | 232 | _user_agent = None |
| 233 | |
| 234 | def _UserAgent(): |
| 235 | global _user_agent |
| 236 | |
| 237 | if _user_agent is None: |
| 238 | py_version = sys.version_info |
| 239 | |
| 240 | os_name = sys.platform |
| 241 | if os_name == 'linux2': |
| 242 | os_name = 'Linux' |
| 243 | elif os_name == 'win32': |
| 244 | os_name = 'Win32' |
| 245 | elif os_name == 'cygwin': |
| 246 | os_name = 'Cygwin' |
| 247 | elif os_name == 'darwin': |
| 248 | os_name = 'Darwin' |
| 249 | |
| 250 | p = GitCommand( |
| 251 | None, ['describe', 'HEAD'], |
| 252 | cwd = _MyRepoPath(), |
| 253 | capture_stdout = True) |
| 254 | if p.Wait() == 0: |
| 255 | repo_version = p.stdout |
| 256 | if len(repo_version) > 0 and repo_version[-1] == '\n': |
| 257 | repo_version = repo_version[0:-1] |
| 258 | if len(repo_version) > 0 and repo_version[0] == 'v': |
| 259 | repo_version = repo_version[1:] |
| 260 | else: |
| 261 | repo_version = 'unknown' |
| 262 | |
| 263 | _user_agent = 'git-repo/%s (%s) git/%s Python/%d.%d.%d' % ( |
| 264 | repo_version, |
| 265 | os_name, |
| 266 | '.'.join(map(lambda d: str(d), git.version_tuple())), |
| 267 | py_version[0], py_version[1], py_version[2]) |
| 268 | return _user_agent |
| 269 | |
| 270 | class _UserAgentHandler(urllib2.BaseHandler): |
| 271 | def http_request(self, req): |
| 272 | req.add_header('User-Agent', _UserAgent()) |
| 273 | return req |
| 274 | |
| 275 | def https_request(self, req): |
| 276 | req.add_header('User-Agent', _UserAgent()) |
| 277 | return req |
| 278 | |
Shawn O. Pearce | fab96c6 | 2011-10-11 12:00:38 -0700 | [diff] [blame] | 279 | class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): |
| 280 | def http_error_auth_reqed(self, authreq, host, req, headers): |
| 281 | try: |
Shawn O. Pearce | df5ee52 | 2011-10-11 14:05:21 -0700 | [diff] [blame] | 282 | old_add_header = req.add_header |
| 283 | def _add_header(name, val): |
| 284 | val = val.replace('\n', '') |
| 285 | old_add_header(name, val) |
| 286 | req.add_header = _add_header |
Shawn O. Pearce | fab96c6 | 2011-10-11 12:00:38 -0700 | [diff] [blame] | 287 | return urllib2.AbstractBasicAuthHandler.http_error_auth_reqed( |
| 288 | self, authreq, host, req, headers) |
| 289 | except: |
Shawn O. Pearce | df5ee52 | 2011-10-11 14:05:21 -0700 | [diff] [blame] | 290 | reset = getattr(self, 'reset_retry_count', None) |
| 291 | if reset is not None: |
| 292 | reset() |
Shawn O. Pearce | b660539 | 2011-10-11 15:58:07 -0700 | [diff] [blame] | 293 | elif getattr(self, 'retried', None): |
| 294 | self.retried = 0 |
Shawn O. Pearce | fab96c6 | 2011-10-11 12:00:38 -0700 | [diff] [blame] | 295 | raise |
| 296 | |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 297 | class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler): |
| 298 | def http_error_auth_reqed(self, auth_header, host, req, headers): |
| 299 | try: |
| 300 | old_add_header = req.add_header |
| 301 | def _add_header(name, val): |
| 302 | val = val.replace('\n', '') |
| 303 | old_add_header(name, val) |
| 304 | req.add_header = _add_header |
| 305 | return urllib2.AbstractDigestAuthHandler.http_error_auth_reqed( |
| 306 | self, auth_header, host, req, headers) |
| 307 | except: |
| 308 | reset = getattr(self, 'reset_retry_count', None) |
| 309 | if reset is not None: |
| 310 | reset() |
| 311 | elif getattr(self, 'retried', None): |
| 312 | self.retried = 0 |
| 313 | raise |
| 314 | |
Shawn O. Pearce | 014d060 | 2011-09-11 12:57:15 -0700 | [diff] [blame] | 315 | def init_http(): |
Shawn O. Pearce | 334851e | 2011-09-19 08:05:31 -0700 | [diff] [blame] | 316 | handlers = [_UserAgentHandler()] |
| 317 | |
Shawn O. Pearce | bd0312a | 2011-09-19 10:04:23 -0700 | [diff] [blame] | 318 | mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() |
| 319 | try: |
| 320 | n = netrc.netrc() |
| 321 | for host in n.hosts: |
| 322 | p = n.hosts[host] |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 323 | mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2]) |
| 324 | mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) |
Shawn O. Pearce | bd0312a | 2011-09-19 10:04:23 -0700 | [diff] [blame] | 325 | except netrc.NetrcParseError: |
| 326 | pass |
Shawn O. Pearce | 7b947de | 2011-09-23 11:50:31 -0700 | [diff] [blame] | 327 | except IOError: |
| 328 | pass |
Shawn O. Pearce | fab96c6 | 2011-10-11 12:00:38 -0700 | [diff] [blame] | 329 | handlers.append(_BasicAuthHandler(mgr)) |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 330 | handlers.append(_DigestAuthHandler(mgr)) |
Shawn O. Pearce | bd0312a | 2011-09-19 10:04:23 -0700 | [diff] [blame] | 331 | |
Shawn O. Pearce | 014d060 | 2011-09-11 12:57:15 -0700 | [diff] [blame] | 332 | if 'http_proxy' in os.environ: |
| 333 | url = os.environ['http_proxy'] |
Shawn O. Pearce | 334851e | 2011-09-19 08:05:31 -0700 | [diff] [blame] | 334 | handlers.append(urllib2.ProxyHandler({'http': url, 'https': url})) |
| 335 | if 'REPO_CURL_VERBOSE' in os.environ: |
| 336 | handlers.append(urllib2.HTTPHandler(debuglevel=1)) |
| 337 | handlers.append(urllib2.HTTPSHandler(debuglevel=1)) |
| 338 | urllib2.install_opener(urllib2.build_opener(*handlers)) |
Shawn O. Pearce | 014d060 | 2011-09-11 12:57:15 -0700 | [diff] [blame] | 339 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 340 | def _Main(argv): |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 341 | result = 0 |
| 342 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 343 | opt = optparse.OptionParser(usage="repo wrapperinfo -- ...") |
| 344 | opt.add_option("--repo-dir", dest="repodir", |
| 345 | help="path to .repo/") |
| 346 | opt.add_option("--wrapper-version", dest="wrapper_version", |
| 347 | help="version of the wrapper script") |
| 348 | opt.add_option("--wrapper-path", dest="wrapper_path", |
| 349 | help="location of the wrapper script") |
| 350 | _PruneOptions(argv, opt) |
| 351 | opt, argv = opt.parse_args(argv) |
| 352 | |
| 353 | _CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path) |
| 354 | _CheckRepoDir(opt.repodir) |
| 355 | |
Shawn O. Pearce | ecff4f1 | 2011-11-29 15:01:33 -0800 | [diff] [blame] | 356 | Version.wrapper_version = opt.wrapper_version |
| 357 | Version.wrapper_path = opt.wrapper_path |
| 358 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 359 | repo = _Repo(opt.repodir) |
| 360 | try: |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 361 | try: |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 362 | init_ssh() |
Shawn O. Pearce | 014d060 | 2011-09-11 12:57:15 -0700 | [diff] [blame] | 363 | init_http() |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 364 | result = repo._Run(argv) or 0 |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 365 | finally: |
| 366 | close_ssh() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 367 | except KeyboardInterrupt: |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 368 | result = 1 |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 369 | except RepoChangedException, rce: |
| 370 | # If repo changed, re-exec ourselves. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 371 | # |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 372 | argv = list(sys.argv) |
| 373 | argv.extend(rce.extra_args) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 374 | try: |
Shawn O. Pearce | c9ef744 | 2008-11-03 10:32:09 -0800 | [diff] [blame] | 375 | os.execv(__file__, argv) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 376 | except OSError, e: |
| 377 | print >>sys.stderr, 'fatal: cannot restart repo after upgrade' |
| 378 | print >>sys.stderr, 'fatal: %s' % e |
Daniel Sandler | 3ce2a6b | 2011-04-29 09:59:12 -0400 | [diff] [blame] | 379 | result = 128 |
| 380 | |
| 381 | sys.exit(result) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 382 | |
| 383 | if __name__ == '__main__': |
| 384 | _Main(sys.argv[1:]) |