# Path: antbs/utils/utility_functions.py
# def remove(src):
#     if not isinstance(src, str):
#         raise ValueError('src must be of type(str), type({0}) given.'.format(type(src)))
# 
#     if os.path.islink(src):
#         method_to_call = os.unlink
# 
#     elif os.path.isdir(src):
#         method_to_call = shutil.rmtree
# 
#     else:
#         method_to_call = os.remove
# 
#     try:
#         method_to_call(src)
#     except Exception as err:
#         logging.exception(err)


import glob
import logging
import os
import gevent
from redis.exceptions import LockError
from . import remove
        for cache_dir in self.all_caches:
            if not os.path.exists(cache_dir):
                os.mkdir(cache_dir, mode=0o777)
            elif os.path.exists(cache_dir):
                already_checked = []
                for path, dir_name, pkg_files in os.walk(cache_dir):
                    for pkg_file in pkg_files:
                        try:
                            pkg, version, rel, suffix = pkg_file.rsplit('-', 3)
                        except ValueError:
                            logging.error('value error for %s', pkg_file)
                            continue
                        # Use globbing to check for multiple versions of the package.
                        all_versions = glob.glob('{0}/{1}***.xz'.format(cache_dir, pkg))
                        if pkg in already_checked:
                            # We've already handled all versions of this package.
                            continue
                        elif len(all_versions) < 2:
                            # There is only one version of the package in this cache dir, keep it.
                            already_checked.append(pkg)
                            continue
                        elif pkg not in already_checked and len(all_versions) > 1:
                            # There are multiple versions of the package. Determine the latest.
                            newest = max(glob.iglob('{0}/{1}**.xz'.format(cache_dir, pkg)),
                                         key=os.path.getctime)
                            logging.debug(newest)
                            logging.debug(all_versions)
                            for package_file in all_versions:
                                if package_file != newest:
                                    # This file is not the newest. Remove it.

# Path: antbs/utils/utility_functions.py
# def remove(src):
#     if not isinstance(src, str):
#         raise ValueError('src must be of type(str), type({0}) given.'.format(type(src)))
# 
#     if os.path.islink(src):
#         method_to_call = os.unlink
# 
#     elif os.path.isdir(src):
#         method_to_call = shutil.rmtree
# 
#     else:
#         method_to_call = os.remove
# 
#     try:
#         method_to_call(src)
#     except Exception as err:
#         logging.exception(err)


# Path: antbs/utils/utility_classes.py
import glob
import logging
import os
import gevent
from redis.exceptions import LockError
from . import remove

        for cache_dir in self.all_caches:
            if not os.path.exists(cache_dir):
                os.mkdir(cache_dir, mode=0o777)
            elif os.path.exists(cache_dir):
                already_checked = []
                for path, dir_name, pkg_files in os.walk(cache_dir):
                    for pkg_file in pkg_files:
                        try:
                            pkg, version, rel, suffix = pkg_file.rsplit('-', 3)
                        except ValueError:
                            logging.error('value error for %s', pkg_file)
                            continue
                        # Use globbing to check for multiple versions of the package.
                        all_versions = glob.glob('{0}/{1}***.xz'.format(cache_dir, pkg))
                        if pkg in already_checked:
                            # We've already handled all versions of this package.
                            continue
                        elif len(all_versions) < 2:
                            # There is only one version of the package in this cache dir, keep it.
                            already_checked.append(pkg)
                            continue
                        elif pkg not in already_checked and len(all_versions) > 1:
                            # There are multiple versions of the package. Determine the latest.
                            newest = max(glob.iglob('{0}/{1}**.xz'.format(cache_dir, pkg)),
                                         key=os.path.getctime)
                            logging.debug(newest)
                            logging.debug(all_versions)
                            for package_file in all_versions:
                                if package_file != newest:
                                    # This file is not the newest. Remove it.

                                    remove(package_file)