blob: 408243c32759e069bd921af9cd353fc295d9fd64 [file] [log] [blame]
[email protected]3bdfbeb2014-02-06 04:52:541#!/usr/bin/env python
[email protected]38b04f82010-07-13 23:03:342
3## repo default configuration
4##
[email protected]538283f2013-08-13 21:37:505REPO_URL='https://chromium.googlesource.com/external/repo'
[email protected]38b04f82010-07-13 23:03:346REPO_REV='stable'
7
8# Copyright (C) 2008 Google Inc.
9#
10# Licensed under the Apache License, Version 2.0 (the "License");
11# you may not use this file except in compliance with the License.
12# You may obtain a copy of the License at
13#
14# http://www.apache.org/licenses/LICENSE-2.0
15#
16# Unless required by applicable law or agreed to in writing, software
17# distributed under the License is distributed on an "AS IS" BASIS,
18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19# See the License for the specific language governing permissions and
20# limitations under the License.
21
[email protected]38b04f82010-07-13 23:03:3422# increment this whenever we make important changes to this script
[email protected]3bdfbeb2014-02-06 04:52:5423VERSION = (1, 21)
[email protected]38b04f82010-07-13 23:03:3424
25# increment this if the MAINTAINER_KEYS block is modified
[email protected]33c182b2014-09-08 17:50:4526KEYRING_VERSION = (1, 4)
[email protected]38b04f82010-07-13 23:03:3427MAINTAINER_KEYS = """
28
29 Repo Maintainer <[email protected]>
30-----BEGIN PGP PUBLIC KEY BLOCK-----
31Version: GnuPG v1.4.2.2 (GNU/Linux)
32
33mQGiBEj3ugERBACrLJh/ZPyVSKeClMuznFIrsQ+hpNnmJGw1a9GXKYKk8qHPhAZf
34WKtrBqAVMNRLhL85oSlekRz98u41H5si5zcuv+IXJDF5MJYcB8f22wAy15lUqPWi
35VCkk1l8qqLiuW0fo+ZkPY5qOgrvc0HW1SmdH649uNwqCbcKb6CxaTxzhOwCgj3AP
36xI1WfzLqdJjsm1Nq98L0cLcD/iNsILCuw44PRds3J75YP0pze7YF/6WFMB6QSFGu
37aUX1FsTTztKNXGms8i5b2l1B8JaLRWq/jOnZzyl1zrUJhkc0Jg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Iezw8T9vVzMY4ArCKFAVu2IVyBcahTfBS8q5EM63mONU6UVJEozfGljiMw
55xuQ7JwKcw0AUEKTKG7aBgBaTAgT8TOevpvlw91cAAwUP/jRkyVi/0WAb0qlEaq/S
56ouWxX1faR+vU3b+Y2/DGjtXQMzG0qpetaTHC/AxxHpgt/dCkWI6ljYDnxgPLwG0a
57Oasm94BjZc6vZwf1opFZUKsjOAAxRxNZyjUJKe4UZVuMTk6zo27Nt3LMnc0FO47v
58FcOjRyquvgNOS818irVHUf12waDx8gszKxQTTtFxU5/ePB2jZmhP6oXSe4K/LG5T
59+WBRPDrHiGPhCzJRzm9BP0lTnGCAj3o9W90STZa65RK7IaYpC8TB35JTBEbrrNCp
60w6lzd74LnNEp5eMlKDnXzUAgAH0yzCQeMl7t33QCdYx2hRs2wtTQSjGfAiNmj/WW
61Vl5Jn+2jCDnRLenKHwVRFsBX2e0BiRWt/i9Y8fjorLCXVj4z+7yW6DawdLkJorEo
62p3v5ILwfC7hVx4jHSnOgZ65L9s8EQdVr1ckN9243yta7rNgwfcqb60ILMFF1BRk/
630V7wCL+68UwwiQDvyMOQuqkysKLSDCLb7BFcyA7j6KG+5hpsREstFX2wK1yKeraz
645xGrFy8tfAaeBMIQ17gvFSp/suc9DYO0ICK2BISzq+F+ZiAKsjMYOBNdH/h0zobQ
65HTHs37+/QLMomGEGKZMWi0dShU2J5mNRQu3Hhxl3hHDVbt5CeJBb26aQcQrFz69W
66zE3GNvmJosh6leayjtI9P2A6iEkEGBECAAkFAkj3uiACGwwACgkQFlMNXpIPXGWp
67TACbBS+Up3RpfYVfd63c1cDdlru13pQAn3NQy/SN858MkxN+zym86UBgOad2
68=CMiZ
69-----END PGP PUBLIC KEY BLOCK-----
[email protected]8db6c882012-12-25 17:02:3770
71 Conley Owens <[email protected]>
72-----BEGIN PGP PUBLIC KEY BLOCK-----
73Version: GnuPG v1.4.11 (GNU/Linux)
74
[email protected]3bdfbeb2014-02-06 04:52:5475mQENBFHRvc8BCADFg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XLQF6+bfoJ6sjVYdwfmNQL
92Ixn8QVhoTDedcqClSWB17VDEFDFa7MmqXZz2qtM3X1R/MUMHqPtegQzBGNhRdnI2
93V45+1Nnx/uuCxDbeI4RbHzujnxDiq70AEQEAAYkBHwQYAQIACQUCUdG9zwIbDAAK
94CRBnt+RIaSs4LNVeB/0Y2pZ8I7gAAcEM0Xw8drr4omg2fUoK1J33ozlA/RxeA/lJ
95I3KnyCDTpXuIeBKPGkdL8uMATC9Z8DnBBajRlftNDVZS3Hz4G09G9QpMojvJkFJV
96By+01Flw/X+eeN8NpqSuLV4W+AjEO8at/VvgKr1AFvBRdZ7GkpI1o6DgPe7ZqX+1
97dzQZt3e13W0rVBb/bUgx9iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x
98JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv
99+H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY
100=AUp4
[email protected]8db6c882012-12-25 17:02:37101-----END PGP PUBLIC KEY BLOCK-----
[email protected]538283f2013-08-13 21:37:50102
103 Stefan Zager <[email protected]>
104-----BEGIN PGP PUBLIC KEY BLOCK-----
105Version: GnuPG v1.4.11 (GNU/Linux)
106
107mQINBFIJOcgBEADwZIq4GRGoO1RJFKlrtVK501cwT5H+Acbizc9N5RxTkFmqxDjb
1089ApUaPW6S1b8+nrzE9P1Ri5erfzipuStfaZ/Wl3mP1JjKulibddmgnPOEbAJ673k
109Vj85RUO4rt2oZAHnZN3D3gFJzVY8JVlZ47Enj9fTqzcW78FVsPCpIT9P2LpTLWeE
110jX9Cjxeimy6VvyJstIcDLYhlpUN5UWen79L4LFAkHf3luLuU4W3p9NriqUsy5UG2
1118vO6QdhKrCr5wsjDFFeVnpMtjlSeZJAWH+XhFFibMX1xP5R9BTuJfzw3kOVKvcE0
112e9ClxgoulepXPv2xnDkqO3pG2gQVzl8LA+Aol8/IXfa7KP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TN88FjtKQ/eTF29TUB6AefUeBS17e2e3WUMy4nc8tduuOFYfiHP40ScP
130wOoatwfzpiTIPGbocUEPL+pS0O/Xy8SINxFMCud3zA==
131=Vd2S
132-----END PGP PUBLIC KEY BLOCK-----
[email protected]33c182b2014-09-08 17:50:45133
134 David James <[email protected]>
135-----BEGIN PGP PUBLIC KEY BLOCK-----
136Version: GnuPG v1
137
138mQINBFQKWWsBEACjAxD8xLqNVFX/qOAKFW7R63J3KkkXQKyH5KmSWZnmdfTg4AeR
139h9sAUls16nHiOFp/MRLFFhax8dm33zfED+zHpISFUkMq2Q3UyP6Z6eSpJyYriEF1
140hP7PpwksEnh+hoQ36fhsY1vaQRgTCO8XkFVcChb1CoKUl104PornVlZ378RBUUnK
141FAPhRSTEJtK1QXv6JtQXFzEQbX3jgxsKvpw/Zg7V3FnaMRhHw84YvCAbWz9ayTov
142SBOIczOscD9T/F3NbSlgFwWlQ7JeixdOsCMaYh7gYcXqdq2jluHuKQlTGmGlFwGm
1435TOh6NwvVUV68JZfer2CGMQv4JImQfousy9V+KGddTBfjYkwtmG9oTkSWBLuO91/
144q+TFdHkzNxivPcC+iluJkzrJHcS6aUg8vkLZfT2wrGZUBFH7GsZiKht2env1HyVZ
14564md/auhee4ED3V0mtWSWYyjriAQUIE0LHVHP1zyEf5gVwDZyuE2HlFZr1eFJWiH
146jcxQnGi7IpxF2//NCTvO2dc3eTi4f1EexOyomu9AWk/iIDCgCpkU38XlWgVrvmM1
147Mw5pDm691L1Xn3v3yMRZZUCottUpUEnz5qAa0eQHWBU4PpXUCaWElwwuT+3Lcx1U
148Rdq74UPNb+hBGzrID/KmeU0NxGmhzRIwl+LKdCvnM2v4AvRHIjQPBqC5fQARAQAB
149tCNEYXZpZCBKYW1lcyA8ZGF2aWRqYW1lc0Bnb29nbGUuY29tPokCOAQTAQIAIgUC
150VApZawIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQSlDprdejN6zH5A//
151XRAytpjxTIHTtMW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2Ih3AF9mi4eguBK9/oGBe
16803LsNBsfoEI81rRuAl5NeFNa+YXf3w7olF2qbwZXcGmRBteUBBvfonW64nk8w+Ui
169x14gzHJXH6l9jsIavA1AMtFulmh6eEf8hsDUzq8s0Yg9PphVmknxPVW44EttOwCi
170OnlVelRSbABcCNNTv1vOC8ubvt191YRNwAgGMRmXfeEFce76ckVJei/tiENycMXl
171Ff3+km6WmswsDmKxz+DfNtf5SXM24EifO2Q6uX9pbg+AcIWI9Sc2WAfmqCooTU8g
172H2Ua0dskiAi9qq4DPYrwPO+OzAT10nn/TqmDABEBAAGJAh8EGAECAAkFAlQKWWsC
173GwwACgkQSlDprdejN6wHURAAncjYkIkSseO8lldTVu0qJi2vetc2Q6bR8Lw1hTAT
174TB2LcbFheTu6Q/sxDSC5slovFSgyDp8wNkDf88+fxV38LC00IeWz7a9EGPzLzA+D
175fNFdctnxXZGaYB3cQ17TkKFj4AMqbzKPkt4xYWU/WdSWPPd4feFJVjg7l8BIxafF
17658ZYbWN3DwAgKE9DDZ9praTNC/2ytWh21a2j8LR4GlYERW1pMGrMt37IGvZqbU6W
177a7HWaB7f0eXg5M5GTr7KP6TTGwY/500cI4fDme6bih/jXDS4vV53b1HHgvzQFXw/
178XURueobmqsbQQzDGsqPzkYJM4fxXu0TWNhW8CieZMMypPq3uSgvN3jTu2JB9NAEz
17921Pso0NzKm6wxhMzPA6KWILmR2KQn/t51NTE6u0+8e9RmQeg9Ce+IpPzPLsGuNca
180u+r4LcB98D8jIUXz9PPbIHiDLJjMWOG8olZz1zcHpt86b+bf8c9TxFAE8p3G/jpQ
181qanHjtbgNmkz+JpvJ9CTEEo69tkcbmOaCNwCWQL+Doqqi7tWMYUbAw0Rk+lOSu/N
1824cAccd41XU/GmIs9zKkbORWubhfFndc7AXnPUU2otjqMQq0f+QCQrHPdyARf2QCm
183j8zzwdwkRpt3SSvqzh3+L3Zq8xeb2M6u/QLz4aLFTR7yQJed0DJFUcISii9ccJr/
184IM4=
185=6VNc
186-----END PGP PUBLIC KEY BLOCK-----
[email protected]38b04f82010-07-13 23:03:34187"""
188
189GIT = 'git' # our git command
[email protected]3bdfbeb2014-02-06 04:52:54190MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version
[email protected]38b04f82010-07-13 23:03:34191repodir = '.repo' # name of repo's private directory
[email protected]8db6c882012-12-25 17:02:37192S_repo = 'repo' # special repo repository
[email protected]38b04f82010-07-13 23:03:34193S_manifests = 'manifests' # special manifest repository
194REPO_MAIN = S_repo + '/main.py' # main script
[email protected]3bdfbeb2014-02-06 04:52:54195MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
[email protected]38b04f82010-07-13 23:03:34196
197
[email protected]3bdfbeb2014-02-06 04:52:54198import errno
[email protected]38b04f82010-07-13 23:03:34199import optparse
200import os
201import re
[email protected]3bdfbeb2014-02-06 04:52:54202import stat
[email protected]38b04f82010-07-13 23:03:34203import subprocess
204import sys
[email protected]3bdfbeb2014-02-06 04:52:54205
206if sys.version_info[0] == 3:
207 import urllib.request
208 import urllib.error
209else:
210 import imp
211 import urllib2
212 urllib = imp.new_module('urllib')
213 urllib.request = urllib2
214 urllib.error = urllib2
215
216
217def _print(*objects, **kwargs):
218 sep = kwargs.get('sep', ' ')
219 end = kwargs.get('end', '\n')
220 out = kwargs.get('file', sys.stdout)
221 out.write(sep.join(objects) + end)
222
223
224# Python version check
225ver = sys.version_info
226if ver[0] == 3:
227 _print('warning: Python 3 support is currently experimental. YMMV.\n'
228 'Please use Python 2.6 - 2.7 instead.',
229 file=sys.stderr)
230if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
231 _print('error: Python version %s unsupported.\n'
232 'Please use Python 2.6 - 2.7 instead.'
233 % sys.version.split(' ')[0], file=sys.stderr)
234 sys.exit(1)
[email protected]38b04f82010-07-13 23:03:34235
236home_dot_repo = os.path.expanduser('~/.repoconfig')
237gpg_dir = os.path.join(home_dot_repo, 'gnupg')
238
239extra_args = []
240init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
241
242# Logging
243group = init_optparse.add_option_group('Logging options')
244group.add_option('-q', '--quiet',
245 dest="quiet", action="store_true", default=False,
246 help="be quiet")
247
248# Manifest
249group = init_optparse.add_option_group('Manifest options')
250group.add_option('-u', '--manifest-url',
251 dest='manifest_url',
252 help='manifest repository location', metavar='URL')
[email protected]38b04f82010-07-13 23:03:34253group.add_option('-b', '--manifest-branch',
254 dest='manifest_branch',
255 help='manifest branch or revision', metavar='REVISION')
256group.add_option('-m', '--manifest-name',
257 dest='manifest_name',
[email protected]b25b69b2011-06-16 17:41:05258 help='initial manifest file', metavar='NAME.xml')
[email protected]38b04f82010-07-13 23:03:34259group.add_option('--mirror',
260 dest='mirror', action='store_true',
[email protected]3bdfbeb2014-02-06 04:52:54261 help='create a replica of the remote repositories '
262 'rather than a client working directory')
[email protected]2c64b712011-01-11 22:57:47263group.add_option('--reference',
264 dest='reference',
265 help='location of mirror directory', metavar='DIR')
[email protected]b25b69b2011-06-16 17:41:05266group.add_option('--depth', type='int', default=None,
267 dest='depth',
268 help='create a shallow clone with given depth; see git clone')
[email protected]3bdfbeb2014-02-06 04:52:54269group.add_option('--archive',
270 dest='archive', action='store_true',
271 help='checkout an archive instead of a git repository for '
272 'each project. See git archive.')
[email protected]79245bf2012-06-14 21:22:01273group.add_option('-g', '--groups',
274 dest='groups', default='default',
[email protected]3bdfbeb2014-02-06 04:52:54275 help='restrict manifest projects to ones with specified '
276 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
[email protected]79245bf2012-06-14 21:22:01277 metavar='GROUP')
278group.add_option('-p', '--platform',
279 dest='platform', default="auto",
[email protected]8db6c882012-12-25 17:02:37280 help='restrict manifest projects to ones with a specified '
[email protected]79245bf2012-06-14 21:22:01281 'platform group [auto|all|none|linux|darwin|...]',
282 metavar='PLATFORM')
[email protected]b25b69b2011-06-16 17:41:05283
[email protected]38b04f82010-07-13 23:03:34284
285# Tool
286group = init_optparse.add_option_group('repo Version options')
287group.add_option('--repo-url',
288 dest='repo_url',
289 help='repo repository location', metavar='URL')
290group.add_option('--repo-branch',
291 dest='repo_branch',
292 help='repo branch or revision', metavar='REVISION')
293group.add_option('--no-repo-verify',
294 dest='no_repo_verify', action='store_true',
295 help='do not verify repo source code')
296
[email protected]79245bf2012-06-14 21:22:01297# Other
298group = init_optparse.add_option_group('Other options')
299group.add_option('--config-name',
300 dest='config_name', action="store_true", default=False,
301 help='Always prompt for name/e-mail')
[email protected]38b04f82010-07-13 23:03:34302
303class CloneFailure(Exception):
304 """Indicate the remote clone of repo itself failed.
305 """
306
307
308def _Init(args):
309 """Installs repo by cloning it over the network.
310 """
311 opt, args = init_optparse.parse_args(args)
[email protected]79245bf2012-06-14 21:22:01312 if args:
[email protected]38b04f82010-07-13 23:03:34313 init_optparse.print_usage()
314 sys.exit(1)
315
316 url = opt.repo_url
317 if not url:
318 url = REPO_URL
319 extra_args.append('--repo-url=%s' % url)
320
321 branch = opt.repo_branch
322 if not branch:
323 branch = REPO_REV
324 extra_args.append('--repo-branch=%s' % branch)
325
326 if branch.startswith('refs/heads/'):
327 branch = branch[len('refs/heads/'):]
328 if branch.startswith('refs/'):
[email protected]3bdfbeb2014-02-06 04:52:54329 _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34330 raise CloneFailure()
331
[email protected]3bdfbeb2014-02-06 04:52:54332 try:
333 os.mkdir(repodir)
334 except OSError as e:
335 if e.errno != errno.EEXIST:
336 _print('fatal: cannot make %s directory: %s'
337 % (repodir, e.strerror), file=sys.stderr)
338 # Don't raise CloneFailure; that would delete the
[email protected]38b04f82010-07-13 23:03:34339 # name. Instead exit immediately.
340 #
341 sys.exit(1)
342
343 _CheckGitVersion()
344 try:
[email protected]8db6c882012-12-25 17:02:37345 if NeedSetupGnuPG():
346 can_verify = SetupGnuPG(opt.quiet)
[email protected]38b04f82010-07-13 23:03:34347 else:
348 can_verify = True
349
[email protected]38b04f82010-07-13 23:03:34350 dst = os.path.abspath(os.path.join(repodir, S_repo))
351 _Clone(url, dst, opt.quiet)
352
353 if can_verify and not opt.no_repo_verify:
354 rev = _Verify(dst, branch, opt.quiet)
355 else:
356 rev = 'refs/remotes/origin/%s^0' % branch
357
358 _Checkout(dst, branch, rev, opt.quiet)
359 except CloneFailure:
360 if opt.quiet:
[email protected]3bdfbeb2014-02-06 04:52:54361 _print('fatal: repo init failed; run without --quiet to see why',
362 file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34363 raise
364
365
[email protected]3bdfbeb2014-02-06 04:52:54366def ParseGitVersion(ver_str):
367 if not ver_str.startswith('git version '):
368 return None
369
370 num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
371 to_tuple = []
372 for num_str in num_ver_str.split('.')[:3]:
373 if num_str.isdigit():
374 to_tuple.append(int(num_str))
375 else:
376 to_tuple.append(0)
377 return tuple(to_tuple)
378
379
[email protected]38b04f82010-07-13 23:03:34380def _CheckGitVersion():
381 cmd = [GIT, '--version']
[email protected]79245bf2012-06-14 21:22:01382 try:
383 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
[email protected]8db6c882012-12-25 17:02:37384 except OSError as e:
[email protected]3bdfbeb2014-02-06 04:52:54385 _print(file=sys.stderr)
386 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
387 _print('fatal: %s' % e, file=sys.stderr)
388 _print(file=sys.stderr)
389 _print('Please make sure %s is installed and in your path.' % GIT,
390 file=sys.stderr)
[email protected]79245bf2012-06-14 21:22:01391 raise CloneFailure()
392
[email protected]38b04f82010-07-13 23:03:34393 ver_str = proc.stdout.read().strip()
394 proc.stdout.close()
395 proc.wait()
396
[email protected]3bdfbeb2014-02-06 04:52:54397 ver_act = ParseGitVersion(ver_str)
398 if ver_act is None:
399 _print('error: "%s" unsupported' % ver_str, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34400 raise CloneFailure()
401
[email protected]38b04f82010-07-13 23:03:34402 if ver_act < MIN_GIT_VERSION:
[email protected]3bdfbeb2014-02-06 04:52:54403 need = '.'.join(map(str, MIN_GIT_VERSION))
404 _print('fatal: git %s or later required' % need, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34405 raise CloneFailure()
406
407
[email protected]8db6c882012-12-25 17:02:37408def NeedSetupGnuPG():
[email protected]38b04f82010-07-13 23:03:34409 if not os.path.isdir(home_dot_repo):
410 return True
411
412 kv = os.path.join(home_dot_repo, 'keyring-version')
413 if not os.path.exists(kv):
414 return True
415
416 kv = open(kv).read()
417 if not kv:
418 return True
419
[email protected]3bdfbeb2014-02-06 04:52:54420 kv = tuple(map(int, kv.split('.')))
[email protected]38b04f82010-07-13 23:03:34421 if kv < KEYRING_VERSION:
422 return True
423 return False
424
425
[email protected]8db6c882012-12-25 17:02:37426def SetupGnuPG(quiet):
[email protected]3bdfbeb2014-02-06 04:52:54427 try:
428 os.mkdir(home_dot_repo)
429 except OSError as e:
430 if e.errno != errno.EEXIST:
431 _print('fatal: cannot make %s directory: %s'
432 % (home_dot_repo, e.strerror), file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34433 sys.exit(1)
434
[email protected]3bdfbeb2014-02-06 04:52:54435 try:
436 os.mkdir(gpg_dir, stat.S_IRWXU)
437 except OSError as e:
438 if e.errno != errno.EEXIST:
439 _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
440 file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34441 sys.exit(1)
442
[email protected]2c64b712011-01-11 22:57:47443 env = os.environ.copy()
444 env['GNUPGHOME'] = gpg_dir.encode()
[email protected]38b04f82010-07-13 23:03:34445
446 cmd = ['gpg', '--import']
447 try:
448 proc = subprocess.Popen(cmd,
449 env = env,
450 stdin = subprocess.PIPE)
[email protected]8db6c882012-12-25 17:02:37451 except OSError as e:
[email protected]38b04f82010-07-13 23:03:34452 if not quiet:
[email protected]3bdfbeb2014-02-06 04:52:54453 _print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
454 _print('warning: Installing it is strongly encouraged.', file=sys.stderr)
455 _print(file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34456 return False
457
458 proc.stdin.write(MAINTAINER_KEYS)
459 proc.stdin.close()
460
461 if proc.wait() != 0:
[email protected]3bdfbeb2014-02-06 04:52:54462 _print('fatal: registering repo maintainer keys failed', file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34463 sys.exit(1)
[email protected]3bdfbeb2014-02-06 04:52:54464 _print()
[email protected]38b04f82010-07-13 23:03:34465
466 fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
[email protected]3bdfbeb2014-02-06 04:52:54467 fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
[email protected]38b04f82010-07-13 23:03:34468 fd.close()
469 return True
470
471
472def _SetConfig(local, name, value):
473 """Set a git configuration option to the specified value.
474 """
475 cmd = [GIT, 'config', name, value]
476 if subprocess.Popen(cmd, cwd = local).wait() != 0:
477 raise CloneFailure()
478
479
[email protected]ad390562011-11-12 00:37:07480def _InitHttp():
481 handlers = []
482
[email protected]3bdfbeb2014-02-06 04:52:54483 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
[email protected]ad390562011-11-12 00:37:07484 try:
485 import netrc
486 n = netrc.netrc()
487 for host in n.hosts:
488 p = n.hosts[host]
[email protected]79245bf2012-06-14 21:22:01489 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
490 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
[email protected]ad390562011-11-12 00:37:07491 except:
492 pass
[email protected]3bdfbeb2014-02-06 04:52:54493 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
494 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
[email protected]ad390562011-11-12 00:37:07495
496 if 'http_proxy' in os.environ:
497 url = os.environ['http_proxy']
[email protected]3bdfbeb2014-02-06 04:52:54498 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
[email protected]ad390562011-11-12 00:37:07499 if 'REPO_CURL_VERBOSE' in os.environ:
[email protected]3bdfbeb2014-02-06 04:52:54500 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
501 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
502 urllib.request.install_opener(urllib.request.build_opener(*handlers))
[email protected]ad390562011-11-12 00:37:07503
504def _Fetch(url, local, src, quiet):
505 if not quiet:
[email protected]3bdfbeb2014-02-06 04:52:54506 _print('Get %s' % url, file=sys.stderr)
[email protected]ad390562011-11-12 00:37:07507
[email protected]38b04f82010-07-13 23:03:34508 cmd = [GIT, 'fetch']
509 if quiet:
510 cmd.append('--quiet')
511 err = subprocess.PIPE
512 else:
513 err = None
[email protected]ad390562011-11-12 00:37:07514 cmd.append(src)
515 cmd.append('+refs/heads/*:refs/remotes/origin/*')
516 cmd.append('refs/tags/*:refs/tags/*')
[email protected]38b04f82010-07-13 23:03:34517
518 proc = subprocess.Popen(cmd, cwd = local, stderr = err)
519 if err:
520 proc.stderr.read()
521 proc.stderr.close()
522 if proc.wait() != 0:
523 raise CloneFailure()
524
[email protected]ad390562011-11-12 00:37:07525def _DownloadBundle(url, local, quiet):
526 if not url.endswith('/'):
527 url += '/'
528 url += 'clone.bundle'
529
530 proc = subprocess.Popen(
531 [GIT, 'config', '--get-regexp', 'url.*.insteadof'],
532 cwd = local,
533 stdout = subprocess.PIPE)
534 for line in proc.stdout:
535 m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
536 if m:
537 new_url = m.group(1)
538 old_url = m.group(2)
539 if url.startswith(old_url):
540 url = new_url + url[len(old_url):]
541 break
542 proc.stdout.close()
543 proc.wait()
544
545 if not url.startswith('http:') and not url.startswith('https:'):
546 return False
547
548 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
549 try:
550 try:
[email protected]3bdfbeb2014-02-06 04:52:54551 r = urllib.request.urlopen(url)
552 except urllib.error.HTTPError as e:
553 if e.code in [403, 404]:
[email protected]ad390562011-11-12 00:37:07554 return False
[email protected]3bdfbeb2014-02-06 04:52:54555 _print('fatal: Cannot get %s' % url, file=sys.stderr)
556 _print('fatal: HTTP error %s' % e.code, file=sys.stderr)
[email protected]ad390562011-11-12 00:37:07557 raise CloneFailure()
[email protected]3bdfbeb2014-02-06 04:52:54558 except urllib.error.URLError as e:
559 _print('fatal: Cannot get %s' % url, file=sys.stderr)
560 _print('fatal: error %s' % e.reason, file=sys.stderr)
[email protected]ad390562011-11-12 00:37:07561 raise CloneFailure()
562 try:
563 if not quiet:
[email protected]3bdfbeb2014-02-06 04:52:54564 _print('Get %s' % url, file=sys.stderr)
[email protected]ad390562011-11-12 00:37:07565 while True:
566 buf = r.read(8192)
567 if buf == '':
568 return True
569 dest.write(buf)
570 finally:
571 r.close()
572 finally:
573 dest.close()
574
575def _ImportBundle(local):
576 path = os.path.join(local, '.git', 'clone.bundle')
577 try:
578 _Fetch(local, local, path, True)
579 finally:
580 os.remove(path)
[email protected]38b04f82010-07-13 23:03:34581
582def _Clone(url, local, quiet):
583 """Clones a git repository to a new subdirectory of repodir
584 """
585 try:
586 os.mkdir(local)
[email protected]8db6c882012-12-25 17:02:37587 except OSError as e:
[email protected]3bdfbeb2014-02-06 04:52:54588 _print('fatal: cannot make %s directory: %s' % (local, e.strerror),
589 file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34590 raise CloneFailure()
591
592 cmd = [GIT, 'init', '--quiet']
593 try:
594 proc = subprocess.Popen(cmd, cwd = local)
[email protected]8db6c882012-12-25 17:02:37595 except OSError as e:
[email protected]3bdfbeb2014-02-06 04:52:54596 _print(file=sys.stderr)
597 _print("fatal: '%s' is not available" % GIT, file=sys.stderr)
598 _print('fatal: %s' % e, file=sys.stderr)
599 _print(file=sys.stderr)
600 _print('Please make sure %s is installed and in your path.' % GIT,
601 file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34602 raise CloneFailure()
603 if proc.wait() != 0:
[email protected]3bdfbeb2014-02-06 04:52:54604 _print('fatal: could not create %s' % local, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34605 raise CloneFailure()
606
[email protected]ad390562011-11-12 00:37:07607 _InitHttp()
[email protected]38b04f82010-07-13 23:03:34608 _SetConfig(local, 'remote.origin.url', url)
609 _SetConfig(local, 'remote.origin.fetch',
610 '+refs/heads/*:refs/remotes/origin/*')
[email protected]ad390562011-11-12 00:37:07611 if _DownloadBundle(url, local, quiet):
612 _ImportBundle(local)
613 else:
614 _Fetch(url, local, 'origin', quiet)
[email protected]38b04f82010-07-13 23:03:34615
616
617def _Verify(cwd, branch, quiet):
618 """Verify the branch has been signed by a tag.
619 """
620 cmd = [GIT, 'describe', 'origin/%s' % branch]
621 proc = subprocess.Popen(cmd,
622 stdout=subprocess.PIPE,
623 stderr=subprocess.PIPE,
624 cwd = cwd)
625 cur = proc.stdout.read().strip()
626 proc.stdout.close()
627
628 proc.stderr.read()
629 proc.stderr.close()
630
631 if proc.wait() != 0 or not cur:
[email protected]3bdfbeb2014-02-06 04:52:54632 _print(file=sys.stderr)
633 _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34634 raise CloneFailure()
635
636 m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
637 if m:
638 cur = m.group(1)
639 if not quiet:
[email protected]3bdfbeb2014-02-06 04:52:54640 _print(file=sys.stderr)
641 _print("info: Ignoring branch '%s'; using tagged release '%s'"
642 % (branch, cur), file=sys.stderr)
643 _print(file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34644
[email protected]2c64b712011-01-11 22:57:47645 env = os.environ.copy()
646 env['GNUPGHOME'] = gpg_dir.encode()
[email protected]38b04f82010-07-13 23:03:34647
648 cmd = [GIT, 'tag', '-v', cur]
649 proc = subprocess.Popen(cmd,
650 stdout = subprocess.PIPE,
651 stderr = subprocess.PIPE,
652 cwd = cwd,
653 env = env)
654 out = proc.stdout.read()
655 proc.stdout.close()
656
657 err = proc.stderr.read()
658 proc.stderr.close()
659
660 if proc.wait() != 0:
[email protected]3bdfbeb2014-02-06 04:52:54661 _print(file=sys.stderr)
662 _print(out, file=sys.stderr)
663 _print(err, file=sys.stderr)
664 _print(file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34665 raise CloneFailure()
666 return '%s^0' % cur
667
668
669def _Checkout(cwd, branch, rev, quiet):
670 """Checkout an upstream branch into the repository and track it.
671 """
672 cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
673 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
674 raise CloneFailure()
675
676 _SetConfig(cwd, 'branch.default.remote', 'origin')
677 _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
678
679 cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
680 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
681 raise CloneFailure()
682
683 cmd = [GIT, 'read-tree', '--reset', '-u']
684 if not quiet:
685 cmd.append('-v')
686 cmd.append('HEAD')
687 if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
688 raise CloneFailure()
689
690
691def _FindRepo():
692 """Look for a repo installation, starting at the current directory.
693 """
[email protected]8db6c882012-12-25 17:02:37694 curdir = os.getcwd()
[email protected]38b04f82010-07-13 23:03:34695 repo = None
696
[email protected]2c64b712011-01-11 22:57:47697 olddir = None
[email protected]8db6c882012-12-25 17:02:37698 while curdir != '/' \
699 and curdir != olddir \
[email protected]2c64b712011-01-11 22:57:47700 and not repo:
[email protected]8db6c882012-12-25 17:02:37701 repo = os.path.join(curdir, repodir, REPO_MAIN)
[email protected]38b04f82010-07-13 23:03:34702 if not os.path.isfile(repo):
703 repo = None
[email protected]8db6c882012-12-25 17:02:37704 olddir = curdir
705 curdir = os.path.dirname(curdir)
706 return (repo, os.path.join(curdir, repodir))
[email protected]38b04f82010-07-13 23:03:34707
708
709class _Options:
710 help = False
711
712
713def _ParseArguments(args):
714 cmd = None
715 opt = _Options()
716 arg = []
717
[email protected]3bdfbeb2014-02-06 04:52:54718 for i in range(len(args)):
[email protected]38b04f82010-07-13 23:03:34719 a = args[i]
720 if a == '-h' or a == '--help':
721 opt.help = True
722
723 elif not a.startswith('-'):
724 cmd = a
725 arg = args[i + 1:]
726 break
727 return cmd, opt, arg
728
729
730def _Usage():
[email protected]3bdfbeb2014-02-06 04:52:54731 _print(
[email protected]38b04f82010-07-13 23:03:34732"""usage: repo COMMAND [ARGS]
733
734repo is not yet installed. Use "repo init" to install it here.
735
736The most commonly used repo commands are:
737
738 init Install repo in the current working directory
739 help Display detailed help on a command
740
741For access to the full online help, install repo ("repo init").
[email protected]3bdfbeb2014-02-06 04:52:54742""", file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34743 sys.exit(1)
744
745
746def _Help(args):
747 if args:
748 if args[0] == 'init':
749 init_optparse.print_help()
[email protected]2c64b712011-01-11 22:57:47750 sys.exit(0)
[email protected]38b04f82010-07-13 23:03:34751 else:
[email protected]3bdfbeb2014-02-06 04:52:54752 _print("error: '%s' is not a bootstrap command.\n"
753 ' For access to online help, install repo ("repo init").'
754 % args[0], file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34755 else:
756 _Usage()
757 sys.exit(1)
758
759
760def _NotInstalled():
[email protected]3bdfbeb2014-02-06 04:52:54761 _print('error: repo is not installed. Use "repo init" to install it here.',
762 file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34763 sys.exit(1)
764
765
766def _NoCommands(cmd):
[email protected]3bdfbeb2014-02-06 04:52:54767 _print("""error: command '%s' requires repo to be installed first.
768 Use "repo init" to install it here.""" % cmd, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34769 sys.exit(1)
770
771
772def _RunSelf(wrapper_path):
773 my_dir = os.path.dirname(wrapper_path)
774 my_main = os.path.join(my_dir, 'main.py')
775 my_git = os.path.join(my_dir, '.git')
776
777 if os.path.isfile(my_main) and os.path.isdir(my_git):
778 for name in ['git_config.py',
779 'project.py',
780 'subcmds']:
781 if not os.path.exists(os.path.join(my_dir, name)):
782 return None, None
783 return my_main, my_git
784 return None, None
785
786
787def _SetDefaultsTo(gitdir):
788 global REPO_URL
789 global REPO_REV
790
791 REPO_URL = gitdir
792 proc = subprocess.Popen([GIT,
793 '--git-dir=%s' % gitdir,
794 'symbolic-ref',
795 'HEAD'],
796 stdout = subprocess.PIPE,
797 stderr = subprocess.PIPE)
798 REPO_REV = proc.stdout.read().strip()
799 proc.stdout.close()
800
801 proc.stderr.read()
802 proc.stderr.close()
803
804 if proc.wait() != 0:
[email protected]3bdfbeb2014-02-06 04:52:54805 _print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34806 sys.exit(1)
807
808
809def main(orig_args):
[email protected]8db6c882012-12-25 17:02:37810 repo_main, rel_repo_dir = _FindRepo()
[email protected]38b04f82010-07-13 23:03:34811 cmd, opt, args = _ParseArguments(orig_args)
812
813 wrapper_path = os.path.abspath(__file__)
814 my_main, my_git = _RunSelf(wrapper_path)
815
[email protected]8db6c882012-12-25 17:02:37816 if not repo_main:
[email protected]38b04f82010-07-13 23:03:34817 if opt.help:
818 _Usage()
819 if cmd == 'help':
820 _Help(args)
821 if not cmd:
822 _NotInstalled()
823 if cmd == 'init':
824 if my_git:
825 _SetDefaultsTo(my_git)
826 try:
827 _Init(args)
828 except CloneFailure:
829 for root, dirs, files in os.walk(repodir, topdown=False):
830 for name in files:
831 os.remove(os.path.join(root, name))
832 for name in dirs:
833 os.rmdir(os.path.join(root, name))
834 os.rmdir(repodir)
835 sys.exit(1)
[email protected]8db6c882012-12-25 17:02:37836 repo_main, rel_repo_dir = _FindRepo()
[email protected]38b04f82010-07-13 23:03:34837 else:
838 _NoCommands(cmd)
839
[email protected]538283f2013-08-13 21:37:50840 if cmd == 'sync' and NeedSetupGnuPG():
841 SetupGnuPG(False)
842
[email protected]38b04f82010-07-13 23:03:34843 if my_main:
[email protected]8db6c882012-12-25 17:02:37844 repo_main = my_main
[email protected]38b04f82010-07-13 23:03:34845
[email protected]3bdfbeb2014-02-06 04:52:54846 ver_str = '.'.join(map(str, VERSION))
847 me = [sys.executable, repo_main,
[email protected]8db6c882012-12-25 17:02:37848 '--repo-dir=%s' % rel_repo_dir,
[email protected]38b04f82010-07-13 23:03:34849 '--wrapper-version=%s' % ver_str,
850 '--wrapper-path=%s' % wrapper_path,
851 '--']
852 me.extend(orig_args)
853 me.extend(extra_args)
854 try:
[email protected]3bdfbeb2014-02-06 04:52:54855 os.execv(sys.executable, me)
[email protected]8db6c882012-12-25 17:02:37856 except OSError as e:
[email protected]3bdfbeb2014-02-06 04:52:54857 _print("fatal: unable to start %s" % repo_main, file=sys.stderr)
858 _print("fatal: %s" % e, file=sys.stderr)
[email protected]38b04f82010-07-13 23:03:34859 sys.exit(148)
860
861
862if __name__ == '__main__':
863 main(sys.argv[1:])