Ejemplo n.º 1
0
    def fixCurrentSymlink(self):
        """Update the 'current' symlink and prune old entries.

        The 'current' symbolic link will point to the latest version present
        in 'targetdir' and only the latest 3 valid entries will be kept.

        Entries named as invalid versions, for instance 'alpha-X', will be
        ignored and left alone. That's because they were probably copied
        manually into this location, they should remain in place.

        See `DebVersion` for more information about version validation.
        """
        # Get an appropriately-sorted list of the valid installer directories
        # now present in the target. Deliberately skip 'broken' versions
        # because they can't be sorted anyway.
        versions = []
        for entry in scandir.scandir(self.targetdir):
            # Skip the symlink.
            if entry.name == 'current':
                continue
            # Skip broken versions.
            try:
                make_version(entry.name)
            except VersionError:
                continue
            # Append the valid versions to the list.
            versions.append(entry.name)
        versions.sort(key=make_version, reverse=True)

        # Make sure the 'current' symlink points to the most recent version
        # The most recent version is in versions[0]
        current = os.path.join(self.targetdir, 'current')
        os.symlink(versions[0], '%s.new' % current)
        os.rename('%s.new' % current, current)

        # There may be some other unpacked installer directories in
        # the target already. We only keep the three with the highest
        # version (plus the one we just extracted, if for some reason
        # it's lower).
        for oldversion in versions[3:]:
            if oldversion != self.version:
                shutil.rmtree(os.path.join(self.targetdir, oldversion))
Ejemplo n.º 2
0
    def fixCurrentSymlink(self):
        """Update the 'current' symlink and prune old entries.

        The 'current' symbolic link will point to the latest version present
        in 'targetdir' and only the latest 3 valid entries will be kept.

        Entries named as invalid versions, for instance 'alpha-X', will be
        ignored and left alone. That's because they were probably copied
        manually into this location, they should remain in place.

        See `DebVersion` for more information about version validation.
        """
        # Get an appropriately-sorted list of the valid installer directories
        # now present in the target. Deliberately skip 'broken' versions
        # because they can't be sorted anyway.
        versions = []
        for inst in os.listdir(self.targetdir):
            # Skip the symlink.
            if inst == 'current':
                continue
            # Skip broken versions.
            try:
                make_version(inst)
            except VersionError:
                continue
            # Append the valid versions to the list.
            versions.append(inst)
        versions.sort(key=make_version, reverse=True)

        # Make sure the 'current' symlink points to the most recent version
        # The most recent version is in versions[0]
        current = os.path.join(self.targetdir, 'current')
        os.symlink(versions[0], '%s.new' % current)
        os.rename('%s.new' % current, current)

        # There may be some other unpacked installer directories in
        # the target already. We only keep the three with the highest
        # version (plus the one we just extracted, if for some reason
        # it's lower).
        for oldversion in versions[3:]:
            if oldversion != self.version:
                shutil.rmtree(os.path.join(self.targetdir, oldversion))
Ejemplo n.º 3
0
    def shouldInstall(self, filename):
        """ Install files from a dist-upgrader tarball.

        It raises DistUpgraderBadVersion if if finds a directory name that
        could not be treated as a valid Debian version.

        It returns False for extracted contents of a directory named
        'current' (since it would obviously conflict with the symbolic
        link in the archive).

        Return True for contents of 'versionable' directories.
        """
        # Only the first path part (directory name) must be *versionable*
        # and we may allow subdirectories.
        directory_name = filename.split(os.path.sep)[0]
        try:
            version = make_version(directory_name)
        except BadUpstreamError as exc:
            raise DistUpgraderBadVersion(self.tarfile_path, exc)
        return version and not filename.startswith('current')
Ejemplo n.º 4
0
    def shouldInstall(self, filename):
        """Install files from a dist-upgrader tarball.

        It raises DistUpgraderBadVersion if if finds a directory name that
        could not be treated as a valid Debian version.

        It returns False for extracted contents of a directory named
        'current' (since it would obviously conflict with the symbolic
        link in the archive).

        Return True for contents of 'versionable' directories.
        """
        # Only the first path part (directory name) must be *versionable*
        # and we may allow subdirectories.
        directory_name = filename.split(os.path.sep)[0]
        try:
            version = make_version(directory_name)
        except BadUpstreamError as exc:
            raise DistUpgraderBadVersion(self.tarfile_path, exc)
        return version and not filename.startswith('current')