summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py102
1 files changed, 54 insertions, 48 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index d6389118..a64f2c45 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -13,6 +13,7 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16from __future__ import print_function
16import netrc 17import netrc
17from optparse import SUPPRESS_HELP 18from optparse import SUPPRESS_HELP
18import os 19import os
@@ -234,9 +235,10 @@ later is required to fix a server side protocol bug.
234 did_lock = True 235 did_lock = True
235 236
236 if not success: 237 if not success:
237 print >>sys.stderr, 'error: Cannot fetch %s' % project.name 238 print('error: Cannot fetch %s' % project.name, file=sys.stderr)
238 if opt.force_broken: 239 if opt.force_broken:
239 print >>sys.stderr, 'warn: --force-broken, continuing to sync' 240 print('warn: --force-broken, continuing to sync',
241 file=sys.stderr)
240 else: 242 else:
241 raise _FetchError() 243 raise _FetchError()
242 244
@@ -265,9 +267,9 @@ later is required to fix a server side protocol bug.
265 clone_bundle=not opt.no_clone_bundle): 267 clone_bundle=not opt.no_clone_bundle):
266 fetched.add(project.gitdir) 268 fetched.add(project.gitdir)
267 else: 269 else:
268 print >>sys.stderr, 'error: Cannot fetch %s' % project.name 270 print('error: Cannot fetch %s' % project.name, file=sys.stderr)
269 if opt.force_broken: 271 if opt.force_broken:
270 print >>sys.stderr, 'warn: --force-broken, continuing to sync' 272 print('warn: --force-broken, continuing to sync', file=sys.stderr)
271 else: 273 else:
272 sys.exit(1) 274 sys.exit(1)
273 else: 275 else:
@@ -300,7 +302,7 @@ later is required to fix a server side protocol bug.
300 302
301 # If we saw an error, exit with code 1 so that other scripts can check. 303 # If we saw an error, exit with code 1 so that other scripts can check.
302 if err_event.isSet(): 304 if err_event.isSet():
303 print >>sys.stderr, '\nerror: Exited sync due to fetch errors' 305 print('\nerror: Exited sync due to fetch errors', file=sys.stderr)
304 sys.exit(1) 306 sys.exit(1)
305 307
306 pm.end() 308 pm.end()
@@ -353,7 +355,7 @@ later is required to fix a server side protocol bug.
353 t.join() 355 t.join()
354 356
355 if err_event.isSet(): 357 if err_event.isSet():
356 print >>sys.stderr, '\nerror: Exited sync due to gc errors' 358 print('\nerror: Exited sync due to gc errors', file=sys.stderr)
357 sys.exit(1) 359 sys.exit(1)
358 360
359 def UpdateProjectList(self): 361 def UpdateProjectList(self):
@@ -390,12 +392,14 @@ later is required to fix a server side protocol bug.
390 groups = None) 392 groups = None)
391 393
392 if project.IsDirty(): 394 if project.IsDirty():
393 print >>sys.stderr, 'error: Cannot remove project "%s": \ 395 print('error: Cannot remove project "%s": uncommitted changes'
394uncommitted changes are present' % project.relpath 396 'are present' % project.relpath, file=sys.stderr)
395 print >>sys.stderr, ' commit changes, then run sync again' 397 print(' commit changes, then run sync again',
398 file=sys.stderr)
396 return -1 399 return -1
397 else: 400 else:
398 print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree 401 print('Deleting obsolete path %s' % project.worktree,
402 file=sys.stderr)
399 shutil.rmtree(project.worktree) 403 shutil.rmtree(project.worktree)
400 # Try deleting parent subdirs if they are empty 404 # Try deleting parent subdirs if they are empty
401 project_dir = os.path.dirname(project.worktree) 405 project_dir = os.path.dirname(project.worktree)
@@ -423,24 +427,24 @@ uncommitted changes are present' % project.relpath
423 self.jobs = min(self.jobs, (soft_limit - 5) / 3) 427 self.jobs = min(self.jobs, (soft_limit - 5) / 3)
424 428
425 if opt.network_only and opt.detach_head: 429 if opt.network_only and opt.detach_head:
426 print >>sys.stderr, 'error: cannot combine -n and -d' 430 print('error: cannot combine -n and -d', file=sys.stderr)
427 sys.exit(1) 431 sys.exit(1)
428 if opt.network_only and opt.local_only: 432 if opt.network_only and opt.local_only:
429 print >>sys.stderr, 'error: cannot combine -n and -l' 433 print('error: cannot combine -n and -l', file=sys.stderr)
430 sys.exit(1) 434 sys.exit(1)
431 if opt.manifest_name and opt.smart_sync: 435 if opt.manifest_name and opt.smart_sync:
432 print >>sys.stderr, 'error: cannot combine -m and -s' 436 print('error: cannot combine -m and -s', file=sys.stderr)
433 sys.exit(1) 437 sys.exit(1)
434 if opt.manifest_name and opt.smart_tag: 438 if opt.manifest_name and opt.smart_tag:
435 print >>sys.stderr, 'error: cannot combine -m and -t' 439 print('error: cannot combine -m and -t', file=sys.stderr)
436 sys.exit(1) 440 sys.exit(1)
437 if opt.manifest_server_username or opt.manifest_server_password: 441 if opt.manifest_server_username or opt.manifest_server_password:
438 if not (opt.smart_sync or opt.smart_tag): 442 if not (opt.smart_sync or opt.smart_tag):
439 print >>sys.stderr, 'error: -u and -p may only be combined with ' \ 443 print('error: -u and -p may only be combined with -s or -t',
440 '-s or -t' 444 file=sys.stderr)
441 sys.exit(1) 445 sys.exit(1)
442 if None in [opt.manifest_server_username, opt.manifest_server_password]: 446 if None in [opt.manifest_server_username, opt.manifest_server_password]:
443 print >>sys.stderr, 'error: both -u and -p must be given' 447 print('error: both -u and -p must be given', file=sys.stderr)
444 sys.exit(1) 448 sys.exit(1)
445 449
446 if opt.manifest_name: 450 if opt.manifest_name:
@@ -448,8 +452,8 @@ uncommitted changes are present' % project.relpath
448 452
449 if opt.smart_sync or opt.smart_tag: 453 if opt.smart_sync or opt.smart_tag:
450 if not self.manifest.manifest_server: 454 if not self.manifest.manifest_server:
451 print >>sys.stderr, \ 455 print('error: cannot smart sync: no manifest server defined in'
452 'error: cannot smart sync: no manifest server defined in manifest' 456 'manifest', file=sys.stderr)
453 sys.exit(1) 457 sys.exit(1)
454 458
455 manifest_server = self.manifest.manifest_server 459 manifest_server = self.manifest.manifest_server
@@ -464,7 +468,8 @@ uncommitted changes are present' % project.relpath
464 try: 468 try:
465 info = netrc.netrc() 469 info = netrc.netrc()
466 except IOError: 470 except IOError:
467 print >>sys.stderr, '.netrc file does not exist or could not be opened' 471 print('.netrc file does not exist or could not be opened',
472 file=sys.stderr)
468 else: 473 else:
469 try: 474 try:
470 parse_result = urlparse.urlparse(manifest_server) 475 parse_result = urlparse.urlparse(manifest_server)
@@ -474,10 +479,10 @@ uncommitted changes are present' % project.relpath
474 except TypeError: 479 except TypeError:
475 # TypeError is raised when the given hostname is not present 480 # TypeError is raised when the given hostname is not present
476 # in the .netrc file. 481 # in the .netrc file.
477 print >>sys.stderr, 'No credentials found for %s in .netrc' % \ 482 print('No credentials found for %s in .netrc'
478 parse_result.hostname 483 % parse_result.hostname, file=sys.stderr)
479 except netrc.NetrcParseError as e: 484 except netrc.NetrcParseError as e:
480 print >>sys.stderr, 'Error parsing .netrc file: %s' % e 485 print('Error parsing .netrc file: %s' % e, file=sys.stderr)
481 486
482 if (username and password): 487 if (username and password):
483 manifest_server = manifest_server.replace('://', '://%s:%s@' % 488 manifest_server = manifest_server.replace('://', '://%s:%s@' %
@@ -516,20 +521,21 @@ uncommitted changes are present' % project.relpath
516 finally: 521 finally:
517 f.close() 522 f.close()
518 except IOError: 523 except IOError:
519 print >>sys.stderr, 'error: cannot write manifest to %s' % \ 524 print('error: cannot write manifest to %s' % manifest_path,
520 manifest_path 525 file=sys.stderr)
521 sys.exit(1) 526 sys.exit(1)
522 self.manifest.Override(manifest_name) 527 self.manifest.Override(manifest_name)
523 else: 528 else:
524 print >>sys.stderr, 'error: %s' % manifest_str 529 print('error: %s' % manifest_str, file=sys.stderr)
525 sys.exit(1) 530 sys.exit(1)
526 except (socket.error, IOError, xmlrpclib.Fault) as e: 531 except (socket.error, IOError, xmlrpclib.Fault) as e:
527 print >>sys.stderr, 'error: cannot connect to manifest server %s:\n%s' % ( 532 print('error: cannot connect to manifest server %s:\n%s'
528 self.manifest.manifest_server, e) 533 % (self.manifest.manifest_server, e), file=sys.stderr)
529 sys.exit(1) 534 sys.exit(1)
530 except xmlrpclib.ProtocolError as e: 535 except xmlrpclib.ProtocolError as e:
531 print >>sys.stderr, 'error: cannot connect to manifest server %s:\n%d %s' % ( 536 print('error: cannot connect to manifest server %s:\n%d %s'
532 self.manifest.manifest_server, e.errcode, e.errmsg) 537 % (self.manifest.manifest_server, e.errcode, e.errmsg),
538 file=sys.stderr)
533 sys.exit(1) 539 sys.exit(1)
534 540
535 rp = self.manifest.repoProject 541 rp = self.manifest.repoProject
@@ -585,14 +591,14 @@ uncommitted changes are present' % project.relpath
585 if project.worktree: 591 if project.worktree:
586 project.Sync_LocalHalf(syncbuf) 592 project.Sync_LocalHalf(syncbuf)
587 pm.end() 593 pm.end()
588 print >>sys.stderr 594 print(file=sys.stderr)
589 if not syncbuf.Finish(): 595 if not syncbuf.Finish():
590 sys.exit(1) 596 sys.exit(1)
591 597
592 # If there's a notice that's supposed to print at the end of the sync, print 598 # If there's a notice that's supposed to print at the end of the sync, print
593 # it now... 599 # it now...
594 if self.manifest.notice: 600 if self.manifest.notice:
595 print self.manifest.notice 601 print(self.manifest.notice)
596 602
597def _PostRepoUpgrade(manifest, quiet=False): 603def _PostRepoUpgrade(manifest, quiet=False):
598 wrapper = WrapperModule() 604 wrapper = WrapperModule()
@@ -604,27 +610,28 @@ def _PostRepoUpgrade(manifest, quiet=False):
604 610
605def _PostRepoFetch(rp, no_repo_verify=False, verbose=False): 611def _PostRepoFetch(rp, no_repo_verify=False, verbose=False):
606 if rp.HasChanges: 612 if rp.HasChanges:
607 print >>sys.stderr, 'info: A new version of repo is available' 613 print('info: A new version of repo is available', file=sys.stderr)
608 print >>sys.stderr, '' 614 print(file=sys.stderr)
609 if no_repo_verify or _VerifyTag(rp): 615 if no_repo_verify or _VerifyTag(rp):
610 syncbuf = SyncBuffer(rp.config) 616 syncbuf = SyncBuffer(rp.config)
611 rp.Sync_LocalHalf(syncbuf) 617 rp.Sync_LocalHalf(syncbuf)
612 if not syncbuf.Finish(): 618 if not syncbuf.Finish():
613 sys.exit(1) 619 sys.exit(1)
614 print >>sys.stderr, 'info: Restarting repo with latest version' 620 print('info: Restarting repo with latest version', file=sys.stderr)
615 raise RepoChangedException(['--repo-upgraded']) 621 raise RepoChangedException(['--repo-upgraded'])
616 else: 622 else:
617 print >>sys.stderr, 'warning: Skipped upgrade to unverified version' 623 print('warning: Skipped upgrade to unverified version', file=sys.stderr)
618 else: 624 else:
619 if verbose: 625 if verbose:
620 print >>sys.stderr, 'repo version %s is current' % rp.work_git.describe(HEAD) 626 print('repo version %s is current' % rp.work_git.describe(HEAD),
627 file=sys.stderr)
621 628
622def _VerifyTag(project): 629def _VerifyTag(project):
623 gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') 630 gpg_dir = os.path.expanduser('~/.repoconfig/gnupg')
624 if not os.path.exists(gpg_dir): 631 if not os.path.exists(gpg_dir):
625 print >>sys.stderr,\ 632 print('warning: GnuPG was not available during last "repo init"\n'
626"""warning: GnuPG was not available during last "repo init" 633 'warning: Cannot automatically authenticate repo."""',
627warning: Cannot automatically authenticate repo.""" 634 file=sys.stderr)
628 return True 635 return True
629 636
630 try: 637 try:
@@ -638,10 +645,9 @@ warning: Cannot automatically authenticate repo."""
638 if rev.startswith(R_HEADS): 645 if rev.startswith(R_HEADS):
639 rev = rev[len(R_HEADS):] 646 rev = rev[len(R_HEADS):]
640 647
641 print >>sys.stderr 648 print(file=sys.stderr)
642 print >>sys.stderr,\ 649 print("warning: project '%s' branch '%s' is not signed"
643 "warning: project '%s' branch '%s' is not signed" \ 650 % (project.name, rev), file=sys.stderr)
644 % (project.name, rev)
645 return False 651 return False
646 652
647 env = os.environ.copy() 653 env = os.environ.copy()
@@ -660,10 +666,10 @@ warning: Cannot automatically authenticate repo."""
660 proc.stderr.close() 666 proc.stderr.close()
661 667
662 if proc.wait() != 0: 668 if proc.wait() != 0:
663 print >>sys.stderr 669 print(file=sys.stderr)
664 print >>sys.stderr, out 670 print(out, file=sys.stderr)
665 print >>sys.stderr, err 671 print(err, file=sys.stderr)
666 print >>sys.stderr 672 print(file=sys.stderr)
667 return False 673 return False
668 return True 674 return True
669 675