コード例 #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 as e:
      print('Failed to remove %s (%s)' % (os.path.join(path, '.git'), str(e)), 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 platform_utils.walk(path):
      for f in files:
        try:
          platform_utils.remove(os.path.join(root, f))
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, f), str(e)), 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 as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), file=sys.stderr)
          failed = True
      elif len(platform_utils.listdir(d)) == 0:
        try:
          platform_utils.rmdir(d)
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), 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(platform_utils.listdir(project_dir)) == 0:
        platform_utils.rmdir(project_dir)
      else:
        break
      project_dir = os.path.dirname(project_dir)

    return 0
コード例 #2
0
ファイル: sync.py プロジェクト: cfig/git-repo
  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 as e:
      print('Failed to remove %s (%s)' % (os.path.join(path, '.git'), str(e)), 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 platform_utils.walk(path):
      for f in files:
        try:
          platform_utils.remove(os.path.join(root, f))
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, f), str(e)), 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 as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), file=sys.stderr)
          failed = True
      elif len(platform_utils.listdir(d)) == 0:
        try:
          platform_utils.rmdir(d)
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), 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(platform_utils.listdir(project_dir)) == 0:
        platform_utils.rmdir(project_dir)
      else:
        break
      project_dir = os.path.dirname(project_dir)

    return 0
コード例 #3
0
  def _Load(self):
    if not self._loaded:
      m = self.manifestProject
      b = m.GetBranch(m.CurrentBranch).merge
      if b is not None and b.startswith(R_HEADS):
        b = b[len(R_HEADS):]
      self.branch = b

      nodes = []
      nodes.append(self._ParseManifestXml(self.manifestFile,
                                          self.manifestProject.worktree))

      if self._load_local_manifests and self.local_manifests:
        try:
          for local_file in sorted(platform_utils.listdir(self.local_manifests)):
            if local_file.endswith('.xml'):
              local = os.path.join(self.local_manifests, local_file)
              nodes.append(self._ParseManifestXml(local, self.repodir))
        except OSError:
          pass

      try:
        self._ParseManifest(nodes)
      except ManifestParseError as e:
        # There was a problem parsing, unload ourselves in case they catch
        # this error and try again later, we will show the correct error
        self._Unload()
        raise e

      if self.IsMirror:
        self._AddMetaProjectMirror(self.repoProject)
        self._AddMetaProjectMirror(self.manifestProject)

      self._loaded = True
コード例 #4
0
 def _ReadLoose(self, prefix):
     base = os.path.join(self._gitdir, prefix)
     for name in platform_utils.listdir(base):
         p = os.path.join(base, name)
         if platform_utils.isdir(p):
             self._mtime[prefix] = os.path.getmtime(base)
             self._ReadLoose(prefix + name + '/')
         elif name.endswith('.lock'):
             pass
         else:
             self._ReadLoose1(p, prefix + name)
コード例 #5
0
ファイル: git_refs.py プロジェクト: android/tools_repo
 def _ReadLoose(self, prefix):
   base = os.path.join(self._gitdir, prefix)
   for name in platform_utils.listdir(base):
     p = os.path.join(base, name)
     if platform_utils.isdir(p):
       self._mtime[prefix] = os.path.getmtime(base)
       self._ReadLoose(prefix + name + '/')
     elif name.endswith('.lock'):
       pass
     else:
       self._ReadLoose1(p, prefix + name)
コード例 #6
0
    def _Load(self):
        if not self._loaded:
            m = self.manifestProject
            b = m.GetBranch(m.CurrentBranch).merge
            if b is not None and b.startswith(R_HEADS):
                b = b[len(R_HEADS):]
            self.branch = b

            nodes = []
            nodes.append(
                self._ParseManifestXml(self.manifestFile,
                                       self.manifestProject.worktree))

            if self._load_local_manifests:
                local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME)
                if os.path.exists(local):
                    if not self.localManifestWarning:
                        self.localManifestWarning = True
                        print('warning: %s is deprecated; put local manifests '
                              'in `%s` instead' %
                              (LOCAL_MANIFEST_NAME,
                               os.path.join(self.repodir,
                                            LOCAL_MANIFESTS_DIR_NAME)),
                              file=sys.stderr)
                    nodes.append(self._ParseManifestXml(local, self.repodir))

                local_dir = os.path.abspath(
                    os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME))
                try:
                    for local_file in sorted(
                            platform_utils.listdir(local_dir)):
                        if local_file.endswith('.xml'):
                            local = os.path.join(local_dir, local_file)
                            nodes.append(
                                self._ParseManifestXml(local, self.repodir))
                except OSError:
                    pass

            try:
                self._ParseManifest(nodes)
            except ManifestParseError as e:
                # There was a problem parsing, unload ourselves in case they catch
                # this error and try again later, we will show the correct error
                self._Unload()
                raise e

            if self.IsMirror:
                self._AddMetaProjectMirror(self.repoProject)
                self._AddMetaProjectMirror(self.manifestProject)

            self._loaded = True
コード例 #7
0
 def _ReadLoose(self, prefix):
     base = os.path.join(self._gitdir, prefix)
     for name in platform_utils.listdir(base):
         p = os.path.join(base, name)
         # We don't implement the full ref validation algorithm, just the simple
         # rules that would show up in local filesystems.
         # https://git-scm.com/docs/git-check-ref-format
         if name.startswith('.') or name.endswith('.lock'):
             pass
         elif platform_utils.isdir(p):
             self._mtime[prefix] = os.path.getmtime(base)
             self._ReadLoose(prefix + name + '/')
         else:
             self._ReadLoose1(p, prefix + name)
コード例 #8
0
ファイル: manifest_xml.py プロジェクト: android/tools_repo
  def _Load(self):
    if not self._loaded:
      m = self.manifestProject
      b = m.GetBranch(m.CurrentBranch).merge
      if b is not None and b.startswith(R_HEADS):
        b = b[len(R_HEADS):]
      self.branch = b

      nodes = []
      nodes.append(self._ParseManifestXml(self.manifestFile,
                                          self.manifestProject.worktree))

      local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME)
      if os.path.exists(local):
        if not self.localManifestWarning:
          self.localManifestWarning = True
          print('warning: %s is deprecated; put local manifests in `%s` instead'
                % (LOCAL_MANIFEST_NAME, os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)),
                file=sys.stderr)
        nodes.append(self._ParseManifestXml(local, self.repodir))

      local_dir = os.path.abspath(os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME))
      try:
        for local_file in sorted(platform_utils.listdir(local_dir)):
          if local_file.endswith('.xml'):
            local = os.path.join(local_dir, local_file)
            nodes.append(self._ParseManifestXml(local, self.repodir))
      except OSError:
        pass

      try:
        self._ParseManifest(nodes)
      except ManifestParseError as e:
        # There was a problem parsing, unload ourselves in case they catch
        # this error and try again later, we will show the correct error
        self._Unload()
        raise e

      if self.IsMirror:
        self._AddMetaProjectMirror(self.repoProject)
        self._AddMetaProjectMirror(self.manifestProject)

      self._loaded = True