def cleanup(self, releases_path, reserve_version):
        changes = 0

        if os.path.lexists(releases_path):
            releases = [ f for f in os.listdir(releases_path) if os.path.isdir(os.path.join(releases_path,f)) ]
            try:
                releases.remove(reserve_version)
            except __HOLE__:
                pass

            if not self.module.check_mode:
                releases.sort( key=lambda x: os.path.getctime(os.path.join(releases_path,x)), reverse=True)
                for release in releases[self.keep_releases:]:
                    changes += self.delete_path(os.path.join(releases_path, release))
            elif len(releases) > self.keep_releases:
                changes += (len(releases) - self.keep_releases)

        return changes
dataset/ETHPy150Open roots/trellis/lib/trellis/modules/deploy_helper.py/DeployHelper.cleanup