diff options
Diffstat (limited to 'repo')
-rwxr-xr-x | repo | 126 |
1 files changed, 59 insertions, 67 deletions
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | ## repo default configuration | 3 | ## repo default configuration |
4 | ## | 4 | ## |
5 | from __future__ import print_function | ||
5 | REPO_URL='https://gerrit.googlesource.com/git-repo' | 6 | REPO_URL='https://gerrit.googlesource.com/git-repo' |
6 | REPO_REV='stable' | 7 | REPO_REV='stable' |
7 | 8 | ||
@@ -215,16 +216,15 @@ def _Init(args): | |||
215 | if branch.startswith('refs/heads/'): | 216 | if branch.startswith('refs/heads/'): |
216 | branch = branch[len('refs/heads/'):] | 217 | branch = branch[len('refs/heads/'):] |
217 | if branch.startswith('refs/'): | 218 | if branch.startswith('refs/'): |
218 | print >>sys.stderr, "fatal: invalid branch name '%s'" % branch | 219 | print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) |
219 | raise CloneFailure() | 220 | raise CloneFailure() |
220 | 221 | ||
221 | if not os.path.isdir(repodir): | 222 | if not os.path.isdir(repodir): |
222 | try: | 223 | try: |
223 | os.mkdir(repodir) | 224 | os.mkdir(repodir) |
224 | except OSError as e: | 225 | except OSError as e: |
225 | print >>sys.stderr, \ | 226 | print('fatal: cannot make %s directory: %s' |
226 | 'fatal: cannot make %s directory: %s' % ( | 227 | % (repodir, e.strerror), file=sys.stderr) |
227 | repodir, e.strerror) | ||
228 | # Don't faise CloneFailure; that would delete the | 228 | # Don't faise CloneFailure; that would delete the |
229 | # name. Instead exit immediately. | 229 | # name. Instead exit immediately. |
230 | # | 230 | # |
@@ -248,8 +248,8 @@ def _Init(args): | |||
248 | _Checkout(dst, branch, rev, opt.quiet) | 248 | _Checkout(dst, branch, rev, opt.quiet) |
249 | except CloneFailure: | 249 | except CloneFailure: |
250 | if opt.quiet: | 250 | if opt.quiet: |
251 | print >>sys.stderr, \ | 251 | print('fatal: repo init failed; run without --quiet to see why', |
252 | 'fatal: repo init failed; run without --quiet to see why' | 252 | file=sys.stderr) |
253 | raise | 253 | raise |
254 | 254 | ||
255 | 255 | ||
@@ -258,12 +258,12 @@ def _CheckGitVersion(): | |||
258 | try: | 258 | try: |
259 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 259 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
260 | except OSError as e: | 260 | except OSError as e: |
261 | print >>sys.stderr | 261 | print(file=sys.stderr) |
262 | print >>sys.stderr, "fatal: '%s' is not available" % GIT | 262 | print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
263 | print >>sys.stderr, 'fatal: %s' % e | 263 | print('fatal: %s' % e, file=sys.stderr) |
264 | print >>sys.stderr | 264 | print(file=sys.stderr) |
265 | print >>sys.stderr, 'Please make sure %s is installed'\ | 265 | print('Please make sure %s is installed and in your path.' % GIT, |
266 | ' and in your path.' % GIT | 266 | file=sys.stderr) |
267 | raise CloneFailure() | 267 | raise CloneFailure() |
268 | 268 | ||
269 | ver_str = proc.stdout.read().strip() | 269 | ver_str = proc.stdout.read().strip() |
@@ -271,14 +271,14 @@ def _CheckGitVersion(): | |||
271 | proc.wait() | 271 | proc.wait() |
272 | 272 | ||
273 | if not ver_str.startswith('git version '): | 273 | if not ver_str.startswith('git version '): |
274 | print >>sys.stderr, 'error: "%s" unsupported' % ver_str | 274 | print('error: "%s" unsupported' % ver_str, file=sys.stderr) |
275 | raise CloneFailure() | 275 | raise CloneFailure() |
276 | 276 | ||
277 | ver_str = ver_str[len('git version '):].strip() | 277 | ver_str = ver_str[len('git version '):].strip() |
278 | ver_act = tuple(map(int, ver_str.split('.')[0:3])) | 278 | ver_act = tuple(map(int, ver_str.split('.')[0:3])) |
279 | if ver_act < MIN_GIT_VERSION: | 279 | if ver_act < MIN_GIT_VERSION: |
280 | need = '.'.join(map(str, MIN_GIT_VERSION)) | 280 | need = '.'.join(map(str, MIN_GIT_VERSION)) |
281 | print >>sys.stderr, 'fatal: git %s or later required' % need | 281 | print('fatal: git %s or later required' % need, file=sys.stderr) |
282 | raise CloneFailure() | 282 | raise CloneFailure() |
283 | 283 | ||
284 | 284 | ||
@@ -305,18 +305,16 @@ def SetupGnuPG(quiet): | |||
305 | try: | 305 | try: |
306 | os.mkdir(home_dot_repo) | 306 | os.mkdir(home_dot_repo) |
307 | except OSError as e: | 307 | except OSError as e: |
308 | print >>sys.stderr, \ | 308 | print('fatal: cannot make %s directory: %s' |
309 | 'fatal: cannot make %s directory: %s' % ( | 309 | % (home_dot_repo, e.strerror), file=sys.stderr) |
310 | home_dot_repo, e.strerror) | ||
311 | sys.exit(1) | 310 | sys.exit(1) |
312 | 311 | ||
313 | if not os.path.isdir(gpg_dir): | 312 | if not os.path.isdir(gpg_dir): |
314 | try: | 313 | try: |
315 | os.mkdir(gpg_dir, stat.S_IRWXU) | 314 | os.mkdir(gpg_dir, stat.S_IRWXU) |
316 | except OSError as e: | 315 | except OSError as e: |
317 | print >>sys.stderr, \ | 316 | print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), |
318 | 'fatal: cannot make %s directory: %s' % ( | 317 | file=sys.stderr) |
319 | gpg_dir, e.strerror) | ||
320 | sys.exit(1) | 318 | sys.exit(1) |
321 | 319 | ||
322 | env = os.environ.copy() | 320 | env = os.environ.copy() |
@@ -329,16 +327,16 @@ def SetupGnuPG(quiet): | |||
329 | stdin = subprocess.PIPE) | 327 | stdin = subprocess.PIPE) |
330 | except OSError as e: | 328 | except OSError as e: |
331 | if not quiet: | 329 | if not quiet: |
332 | print >>sys.stderr, 'warning: gpg (GnuPG) is not available.' | 330 | print('warning: gpg (GnuPG) is not available.', file=sys.stderr) |
333 | print >>sys.stderr, 'warning: Installing it is strongly encouraged.' | 331 | print('warning: Installing it is strongly encouraged.', file=sys.stderr) |
334 | print >>sys.stderr | 332 | print(file=sys.stderr) |
335 | return False | 333 | return False |
336 | 334 | ||
337 | proc.stdin.write(MAINTAINER_KEYS) | 335 | proc.stdin.write(MAINTAINER_KEYS) |
338 | proc.stdin.close() | 336 | proc.stdin.close() |
339 | 337 | ||
340 | if proc.wait() != 0: | 338 | if proc.wait() != 0: |
341 | print >>sys.stderr, 'fatal: registering repo maintainer keys failed' | 339 | print('fatal: registering repo maintainer keys failed', file=sys.stderr) |
342 | sys.exit(1) | 340 | sys.exit(1) |
343 | 341 | ||
344 | 342 | ||
@@ -382,7 +380,7 @@ def _InitHttp(): | |||
382 | 380 | ||
383 | def _Fetch(url, local, src, quiet): | 381 | def _Fetch(url, local, src, quiet): |
384 | if not quiet: | 382 | if not quiet: |
385 | print >>sys.stderr, 'Get %s' % url | 383 | print('Get %s' % url, file=sys.stderr) |
386 | 384 | ||
387 | cmd = [GIT, 'fetch'] | 385 | cmd = [GIT, 'fetch'] |
388 | if quiet: | 386 | if quiet: |
@@ -431,16 +429,16 @@ def _DownloadBundle(url, local, quiet): | |||
431 | except urllib.error.HTTPError as e: | 429 | except urllib.error.HTTPError as e: |
432 | if e.code == 404: | 430 | if e.code == 404: |
433 | return False | 431 | return False |
434 | print >>sys.stderr, 'fatal: Cannot get %s' % url | 432 | print('fatal: Cannot get %s' % url, file=sys.stderr) |
435 | print >>sys.stderr, 'fatal: HTTP error %s' % e.code | 433 | print('fatal: HTTP error %s' % e.code, file=sys.stderr) |
436 | raise CloneFailure() | 434 | raise CloneFailure() |
437 | except urllib.error.URLError as e: | 435 | except urllib.error.URLError as e: |
438 | print >>sys.stderr, 'fatal: Cannot get %s' % url | 436 | print('fatal: Cannot get %s' % url, file=sys.stderr) |
439 | print >>sys.stderr, 'fatal: error %s' % e.reason | 437 | print('fatal: error %s' % e.reason, file=sys.stderr) |
440 | raise CloneFailure() | 438 | raise CloneFailure() |
441 | try: | 439 | try: |
442 | if not quiet: | 440 | if not quiet: |
443 | print >>sys.stderr, 'Get %s' % url | 441 | print('Get %s' % url, file=sys.stderr) |
444 | while True: | 442 | while True: |
445 | buf = r.read(8192) | 443 | buf = r.read(8192) |
446 | if buf == '': | 444 | if buf == '': |
@@ -464,24 +462,23 @@ def _Clone(url, local, quiet): | |||
464 | try: | 462 | try: |
465 | os.mkdir(local) | 463 | os.mkdir(local) |
466 | except OSError as e: | 464 | except OSError as e: |
467 | print >>sys.stderr, \ | 465 | print('fatal: cannot make %s directory: %s' % (local, e.strerror), |
468 | 'fatal: cannot make %s directory: %s' \ | 466 | file=sys.stderr) |
469 | % (local, e.strerror) | ||
470 | raise CloneFailure() | 467 | raise CloneFailure() |
471 | 468 | ||
472 | cmd = [GIT, 'init', '--quiet'] | 469 | cmd = [GIT, 'init', '--quiet'] |
473 | try: | 470 | try: |
474 | proc = subprocess.Popen(cmd, cwd = local) | 471 | proc = subprocess.Popen(cmd, cwd = local) |
475 | except OSError as e: | 472 | except OSError as e: |
476 | print >>sys.stderr | 473 | print(file=sys.stderr) |
477 | print >>sys.stderr, "fatal: '%s' is not available" % GIT | 474 | print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
478 | print >>sys.stderr, 'fatal: %s' % e | 475 | print('fatal: %s' % e, file=sys.stderr) |
479 | print >>sys.stderr | 476 | print(file=sys.stderr) |
480 | print >>sys.stderr, 'Please make sure %s is installed'\ | 477 | print('Please make sure %s is installed and in your path.' % GIT, |
481 | ' and in your path.' % GIT | 478 | file=sys.stderr) |
482 | raise CloneFailure() | 479 | raise CloneFailure() |
483 | if proc.wait() != 0: | 480 | if proc.wait() != 0: |
484 | print >>sys.stderr, 'fatal: could not create %s' % local | 481 | print('fatal: could not create %s' % local, file=sys.stderr) |
485 | raise CloneFailure() | 482 | raise CloneFailure() |
486 | 483 | ||
487 | _InitHttp() | 484 | _InitHttp() |
@@ -509,21 +506,18 @@ def _Verify(cwd, branch, quiet): | |||
509 | proc.stderr.close() | 506 | proc.stderr.close() |
510 | 507 | ||
511 | if proc.wait() != 0 or not cur: | 508 | if proc.wait() != 0 or not cur: |
512 | print >>sys.stderr | 509 | print(file=sys.stderr) |
513 | print >>sys.stderr,\ | 510 | print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) |
514 | "fatal: branch '%s' has not been signed" \ | ||
515 | % branch | ||
516 | raise CloneFailure() | 511 | raise CloneFailure() |
517 | 512 | ||
518 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) | 513 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) |
519 | if m: | 514 | if m: |
520 | cur = m.group(1) | 515 | cur = m.group(1) |
521 | if not quiet: | 516 | if not quiet: |
522 | print >>sys.stderr | 517 | print(file=sys.stderr) |
523 | print >>sys.stderr, \ | 518 | print("info: Ignoring branch '%s'; using tagged release '%s'" |
524 | "info: Ignoring branch '%s'; using tagged release '%s'" \ | 519 | % (branch, cur), file=sys.stderr) |
525 | % (branch, cur) | 520 | print(file=sys.stderr) |
526 | print >>sys.stderr | ||
527 | 521 | ||
528 | env = os.environ.copy() | 522 | env = os.environ.copy() |
529 | env['GNUPGHOME'] = gpg_dir.encode() | 523 | env['GNUPGHOME'] = gpg_dir.encode() |
@@ -541,10 +535,10 @@ def _Verify(cwd, branch, quiet): | |||
541 | proc.stderr.close() | 535 | proc.stderr.close() |
542 | 536 | ||
543 | if proc.wait() != 0: | 537 | if proc.wait() != 0: |
544 | print >>sys.stderr | 538 | print(file=sys.stderr) |
545 | print >>sys.stderr, out | 539 | print(out, file=sys.stderr) |
546 | print >>sys.stderr, err | 540 | print(err, file=sys.stderr) |
547 | print >>sys.stderr | 541 | print(file=sys.stderr) |
548 | raise CloneFailure() | 542 | raise CloneFailure() |
549 | return '%s^0' % cur | 543 | return '%s^0' % cur |
550 | 544 | ||
@@ -611,7 +605,7 @@ def _ParseArguments(args): | |||
611 | 605 | ||
612 | 606 | ||
613 | def _Usage(): | 607 | def _Usage(): |
614 | print >>sys.stderr,\ | 608 | print( |
615 | """usage: repo COMMAND [ARGS] | 609 | """usage: repo COMMAND [ARGS] |
616 | 610 | ||
617 | repo is not yet installed. Use "repo init" to install it here. | 611 | repo is not yet installed. Use "repo init" to install it here. |
@@ -622,7 +616,7 @@ The most commonly used repo commands are: | |||
622 | help Display detailed help on a command | 616 | help Display detailed help on a command |
623 | 617 | ||
624 | For access to the full online help, install repo ("repo init"). | 618 | For access to the full online help, install repo ("repo init"). |
625 | """ | 619 | """, file=sys.stderr) |
626 | sys.exit(1) | 620 | sys.exit(1) |
627 | 621 | ||
628 | 622 | ||
@@ -632,25 +626,23 @@ def _Help(args): | |||
632 | init_optparse.print_help() | 626 | init_optparse.print_help() |
633 | sys.exit(0) | 627 | sys.exit(0) |
634 | else: | 628 | else: |
635 | print >>sys.stderr,\ | 629 | print("error: '%s' is not a bootstrap command.\n" |
636 | "error: '%s' is not a bootstrap command.\n"\ | 630 | ' For access to online help, install repo ("repo init").' |
637 | ' For access to online help, install repo ("repo init").'\ | 631 | % args[0], file=sys.stderr) |
638 | % args[0] | ||
639 | else: | 632 | else: |
640 | _Usage() | 633 | _Usage() |
641 | sys.exit(1) | 634 | sys.exit(1) |
642 | 635 | ||
643 | 636 | ||
644 | def _NotInstalled(): | 637 | def _NotInstalled(): |
645 | print >>sys.stderr,\ | 638 | print('error: repo is not installed. Use "repo init" to install it here.', |
646 | 'error: repo is not installed. Use "repo init" to install it here.' | 639 | file=sys.stderr) |
647 | sys.exit(1) | 640 | sys.exit(1) |
648 | 641 | ||
649 | 642 | ||
650 | def _NoCommands(cmd): | 643 | def _NoCommands(cmd): |
651 | print >>sys.stderr,\ | 644 | print("""error: command '%s' requires repo to be installed first. |
652 | """error: command '%s' requires repo to be installed first. | 645 | Use "repo init" to install it here.""" % cmd, file=sys.stderr) |
653 | Use "repo init" to install it here.""" % cmd | ||
654 | sys.exit(1) | 646 | sys.exit(1) |
655 | 647 | ||
656 | 648 | ||
@@ -687,7 +679,7 @@ def _SetDefaultsTo(gitdir): | |||
687 | proc.stderr.close() | 679 | proc.stderr.close() |
688 | 680 | ||
689 | if proc.wait() != 0: | 681 | if proc.wait() != 0: |
690 | print >>sys.stderr, 'fatal: %s has no current branch' % gitdir | 682 | print('fatal: %s has no current branch' % gitdir, file=sys.stderr) |
691 | sys.exit(1) | 683 | sys.exit(1) |
692 | 684 | ||
693 | 685 | ||
@@ -736,8 +728,8 @@ def main(orig_args): | |||
736 | try: | 728 | try: |
737 | os.execv(repo_main, me) | 729 | os.execv(repo_main, me) |
738 | except OSError as e: | 730 | except OSError as e: |
739 | print >>sys.stderr, "fatal: unable to start %s" % repo_main | 731 | print("fatal: unable to start %s" % repo_main, file=sys.stderr) |
740 | print >>sys.stderr, "fatal: %s" % e | 732 | print("fatal: %s" % e, file=sys.stderr) |
741 | sys.exit(148) | 733 | sys.exit(148) |
742 | 734 | ||
743 | 735 | ||