# AUTOGENERATED! DO NOT EDIT! File to edit: ../../../pts/mod/cmds/06_exclude_repo.pct.py.

# %% top_export
from pathlib import Path

from repoyard._utils.sync_helper import SyncSetting
from repoyard.config import get_config
from repoyard import const

async def exclude_repo(
    config_path: Path,
    repo_full_name: str,
    skip_sync: bool = False,
    soft_interruption_enabled: bool = True,
):
    """
    """
    
    # AUTOGENERATED! DO NOT EDIT! File to edit: ../../../pts/mod/cmds/06_exclude_repo.pct.py.
    
    # %% auto 0
    __all__ = ['config', 'repoyard_meta', 'repo_meta']
    
    # %% ../../../pts/mod/cmds/06_exclude_repo.pct.py 11
    config = get_config(config_path)
    
    # %% ../../../pts/mod/cmds/06_exclude_repo.pct.py 14
    from .._models import get_repoyard_meta
    repoyard_meta = get_repoyard_meta(config)
    
    if repo_full_name not in repoyard_meta.by_full_name:
        raise ValueError(f"Repo '{repo_full_name}' does not exist.")
    
    repo_meta = repoyard_meta.by_full_name[repo_full_name]
    
    if not repo_meta.check_included(config):
        raise ValueError(f"Repo '{repo_full_name}' is already excluded.")
    
    # %% ../../../pts/mod/cmds/06_exclude_repo.pct.py 16
    from . import sync_repo
    
    if not skip_sync:
        await sync_repo(
            config_path=config_path,
            repo_full_name=repo_full_name,
            sync_setting=SyncSetting.CAREFUL,
        )
    
    # %% ../../../pts/mod/cmds/06_exclude_repo.pct.py 18
    import shutil
    from .._models import RepoPart
    shutil.rmtree(repo_meta.get_local_repodata_path(config))
    repo_meta.get_local_sync_record_path(config, RepoPart.DATA).unlink()