Example #1
0
    def UpdateProjectList(self, opt):
        new_project_paths = []
        for project in self.GetProjects(None, missing_ok=True):
            if project.relpath:
                new_project_paths.append(project.relpath)
        file_name = 'project.list'
        file_path = os.path.join(self.manifest.repodir, file_name)
        old_project_paths = []

        if os.path.exists(file_path):
            fd = open(file_path, 'r')
            try:
                old_project_paths = fd.read().split('\n')
            finally:
                fd.close()
            # In reversed order, so subfolders are deleted before parent folder.
            for path in sorted(old_project_paths, reverse=True):
                if not path:
                    continue
                if path not in new_project_paths:
                    # If the path has already been deleted, we don't need to do it
                    gitdir = os.path.join(self.manifest.topdir, path, '.git')
                    if os.path.exists(gitdir):
                        project = Project(manifest=self.manifest,
                                          name=path,
                                          remote=RemoteSpec('origin'),
                                          gitdir=gitdir,
                                          objdir=gitdir,
                                          worktree=os.path.join(
                                              self.manifest.topdir, path),
                                          relpath=path,
                                          revisionExpr='HEAD',
                                          revisionId=None,
                                          groups=None)

                        if project.IsDirty() and opt.force_remove_dirty:
                            print(
                                'WARNING: Removing dirty project "%s": uncommitted changes '
                                'erased' % project.relpath,
                                file=sys.stderr)
                            self._DeleteProject(project.worktree)
                        elif project.IsDirty():
                            print(
                                'error: Cannot remove project "%s": uncommitted changes '
                                'are present' % project.relpath,
                                file=sys.stderr)
                            print('       commit changes, then run sync again',
                                  file=sys.stderr)
                            return -1
                        elif self._DeleteProject(project.worktree):
                            return -1

        new_project_paths.sort()
        fd = open(file_path, 'w')
        try:
            fd.write('\n'.join(new_project_paths))
            fd.write('\n')
        finally:
            fd.close()
        return 0
Example #2
0
  def UpdateProjectList(self):
    new_project_paths = []
    for project in self.GetProjects(None, missing_ok=True):
      if project.relpath:
        new_project_paths.append(project.relpath)
    file_name = 'project.list'
    file_path = os.path.join(self.manifest.repodir, file_name)
    old_project_paths = []

    if os.path.exists(file_path):
      fd = open(file_path, 'r')
      try:
        old_project_paths = fd.read().split('\n')
      finally:
        fd.close()
      for path in old_project_paths:
        if not path:
          continue
        if path not in new_project_paths:
          # If the path has already been deleted, we don't need to do it
          if os.path.exists(self.manifest.topdir + '/' + path):
            project = Project(
                           manifest = self.manifest,
                           name = path,
                           remote = RemoteSpec('origin'),
                           gitdir = os.path.join(self.manifest.topdir,
                                                 path, '.git'),
                           worktree = os.path.join(self.manifest.topdir, path),
                           relpath = path,
                           revisionExpr = 'HEAD',
                           revisionId = None,
                           groups = None)

            if project.IsDirty():
              print('error: Cannot remove project "%s": uncommitted changes '
                    'are present' % project.relpath, file=sys.stderr)
              print('       commit changes, then run sync again',
                    file=sys.stderr)
              return -1
            else:
              print('Deleting obsolete path %s' % project.worktree,
                    file=sys.stderr)
              shutil.rmtree(project.worktree)
              # Try deleting parent subdirs if they are empty
              project_dir = os.path.dirname(project.worktree)
              while project_dir != self.manifest.topdir:
                try:
                  os.rmdir(project_dir)
                except OSError:
                  break
                project_dir = os.path.dirname(project_dir)

    new_project_paths.sort()
    fd = open(file_path, 'w')
    try:
      fd.write('\n'.join(new_project_paths))
      fd.write('\n')
    finally:
      fd.close()
    return 0
Example #3
0
    def UpdateProjectList(self):
        new_project_paths = []
        for project in self.manifest.projects.values():
            if project.relpath:
                new_project_paths.append(project.relpath)
        file_name = 'project.list'
        file_path = os.path.join(self.manifest.repodir, file_name)
        old_project_paths = []

        if os.path.exists(file_path):
            fd = open(file_path, 'r')
            try:
                old_project_paths = fd.read().split('\n')
            finally:
                fd.close()
            for path in old_project_paths:
                if not path:
                    continue
                if path not in new_project_paths:
                    project = Project(
                        manifest=self.manifest,
                        name=path,
                        remote=RemoteSpec('origin'),
                        gitdir=os.path.join(self.manifest.topdir, path,
                                            '.git'),
                        worktree=os.path.join(self.manifest.topdir, path),
                        relpath=path,
                        revisionExpr='HEAD',
                        revisionId=None)
                    if project.IsDirty():
                        print >> sys.stderr, 'error: Cannot remove project "%s": \
uncommitted changes are present' % project.relpath
                        print >> sys.stderr, '       commit changes, then run sync again'
                        return -1
                    else:
                        print >> sys.stderr, 'Deleting obsolete path %s' % project.worktree
                        shutil.rmtree(project.worktree)
                        # Try deleting parent subdirs if they are empty
                        dir = os.path.dirname(project.worktree)
                        while dir != self.manifest.topdir:
                            try:
                                os.rmdir(dir)
                            except OSError:
                                break
                            dir = os.path.dirname(dir)

        new_project_paths.sort()
        fd = open(file_path, 'w')
        try:
            fd.write('\n'.join(new_project_paths))
            fd.write('\n')
        finally:
            fd.close()
        return 0