示例#1
0
  def _DeleteProject(self, path):
    print('Deleting obsolete path %s' % path, file=sys.stderr)

    # Delete the .git directory first, so we're less likely to have a partially
    # working git repository around. There shouldn't be any git projects here,
    # so rmtree works.
    try:
      platform_utils.rmtree(os.path.join(path, '.git'))
    except OSError:
      print('Failed to remove %s' % os.path.join(path, '.git'), file=sys.stderr)
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return -1

    # Delete everything under the worktree, except for directories that contain
    # another git project
    dirs_to_remove = []
    failed = False
    for root, dirs, files in os.walk(path):
      for f in files:
        try:
          platform_utils.remove(os.path.join(root, f))
        except OSError:
          print('Failed to remove %s' % os.path.join(root, f), file=sys.stderr)
          failed = True
      dirs[:] = [d for d in dirs
                 if not os.path.lexists(os.path.join(root, d, '.git'))]
      dirs_to_remove += [os.path.join(root, d) for d in dirs
                         if os.path.join(root, d) not in dirs_to_remove]
    for d in reversed(dirs_to_remove):
      if platform_utils.islink(d):
        try:
          platform_utils.remove(d)
        except OSError:
          print('Failed to remove %s' % os.path.join(root, d), file=sys.stderr)
          failed = True
      elif len(os.listdir(d)) == 0:
        try:
          os.rmdir(d)
        except OSError:
          print('Failed to remove %s' % os.path.join(root, d), file=sys.stderr)
          failed = True
          continue
    if failed:
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return -1

    # Try deleting parent dirs if they are empty
    project_dir = path
    while project_dir != self.manifest.topdir:
      if len(os.listdir(project_dir)) == 0:
        os.rmdir(project_dir)
      else:
        break
      project_dir = os.path.dirname(project_dir)

    return 0
示例#2
0
  def _DeleteProject(self, path):
    print('Deleting obsolete path %s' % path, file=sys.stderr)

    # Delete the .git directory first, so we're less likely to have a partially
    # working git repository around. There shouldn't be any git projects here,
    # so rmtree works.
    try:
      platform_utils.rmtree(os.path.join(path, '.git'))
    except OSError:
      print('Failed to remove %s' % os.path.join(path, '.git'), file=sys.stderr)
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return -1

    # Delete everything under the worktree, except for directories that contain
    # another git project
    dirs_to_remove = []
    failed = False
    for root, dirs, files in os.walk(path):
      for f in files:
        try:
          platform_utils.remove(os.path.join(root, f))
        except OSError:
          print('Failed to remove %s' % os.path.join(root, f), file=sys.stderr)
          failed = True
      dirs[:] = [d for d in dirs
                 if not os.path.lexists(os.path.join(root, d, '.git'))]
      dirs_to_remove += [os.path.join(root, d) for d in dirs
                         if os.path.join(root, d) not in dirs_to_remove]
    for d in reversed(dirs_to_remove):
      if platform_utils.islink(d):
        try:
          platform_utils.remove(d)
        except OSError:
          print('Failed to remove %s' % os.path.join(root, d), file=sys.stderr)
          failed = True
      elif len(os.listdir(d)) == 0:
        try:
          os.rmdir(d)
        except OSError:
          print('Failed to remove %s' % os.path.join(root, d), file=sys.stderr)
          failed = True
          continue
    if failed:
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return -1

    # Try deleting parent dirs if they are empty
    project_dir = path
    while project_dir != self.manifest.topdir:
      if len(os.listdir(project_dir)) == 0:
        os.rmdir(project_dir)
      else:
        break
      project_dir = os.path.dirname(project_dir)

    return 0
示例#3
0
def _PostRepoUpgrade(manifest, quiet=False):
  # Link the docs for the internal .repo/ layout for people
  link = os.path.join(manifest.repodir, 'internal-fs-layout.md')
  if not platform_utils.islink(link):
    target = os.path.join('repo', 'docs', 'internal-fs-layout.md')
    try:
      platform_utils.symlink(target, link)
    except Exception:
      pass

  wrapper = Wrapper()
  if wrapper.NeedSetupGnuPG():
    wrapper.SetupGnuPG(quiet)
  for project in manifest.projects:
    if project.Exists:
      project.PostRepoUpgrade()