def build_exceptions()

in legacy/autodmg_cache_builder/autodmg_cache_build.py [0:0]


def build_exceptions(cache_dir):
    """Build a package for each exception."""
    exceptions_pkg_list = []
    exceptions_dir = os.path.join(cache_dir, 'exceptions')
    exceptions_pkgs_dir = os.path.join(cache_dir, 'exceptions_pkgs')
    # Empty out existing exceptions packages first, to avoid cruft
    for file in os.listdir(exceptions_pkgs_dir):
        os.unlink(os.path.join(exceptions_pkgs_dir, file))
    counter = 1
    tmp_cache_dir = '/tmp/individ_except/Library/Managed Installs/Cache'
    try:
        os.makedirs(tmp_cache_dir)
    except OSError:
        # Path likely exists
        pass
    # Now begin our building
    for exception in os.listdir(exceptions_dir):
        split_name = re.split('_|-|\s', exception)[0]
        output_name = "munki_cache_%s-%s" % (split_name, str(counter))
        receipt_name = os.path.splitext(exception)[0]
        counter += 1
        # Copy each one to a temporary location
        shutil.copy2(
            os.path.join(cache_dir, 'exceptions', exception),
            tmp_cache_dir
        )
        output_exception_pkg = build_pkg(
            tmp_cache_dir,
            output_name,
            'com.facebook.cpe.munki_exceptions.%s' % receipt_name,
            '/Library/Managed Installs/Cache',
            exceptions_pkgs_dir,
            'Building exception pkg for %s' % exception
        )
        if output_exception_pkg:
            exceptions_pkg_list.append(output_exception_pkg)
        if not output_exception_pkg:
            print("Failed to build exceptions package for %s!" % exception)
        # Delete the copied file
        os.unlink(os.path.join(tmp_cache_dir, exception))
    return exceptions_pkg_list