From 56dbd3966cad5bb46ba26c0288ebc043c3340c04 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Thu, 22 Sep 2022 01:40:59 +0200 Subject: [PATCH] wrapper.is_wrapped(): handle wrapper_type = 'none' --- packages/cli.py | 28 ++++++++++++++++++++-------- wrapper/__init__.py | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/cli.py b/packages/cli.py index 3ffe1a8..0e43400 100644 --- a/packages/cli.py +++ b/packages/cli.py @@ -6,7 +6,7 @@ from glob import glob from typing import Iterable, Optional from config import config -from constants import Arch, ARCHES, REPOSITORIES +from constants import Arch, ARCHES, REPOSITORIES, SRCINFO_FILE, SRCINFO_METADATA_FILE from exec.file import remove_file from distro.distro import get_kupfer_local from distro.package import LocalPackage @@ -118,12 +118,22 @@ def cmd_sideload(paths: Iterable[str], arch: Optional[Arch] = None, no_build: bo alloc_tty=True).check_returncode() +CLEAN_LOCATIONS = ['src', 'pkg', SRCINFO_FILE, SRCINFO_METADATA_FILE] + + @cmd_packages.command(name='clean') @click.option('-f', '--force', is_flag=True, default=False, help="Don't prompt for confirmation") @click.option('-n', '--noop', is_flag=True, default=False, help="Print what would be removed but dont execute") -@click.argument('what', type=click.Choice(['all', 'src', 'pkg']), nargs=-1) +@click.argument('what', type=click.Choice(['all', 'git', *CLEAN_LOCATIONS]), nargs=-1) def cmd_clean(what: Iterable[str] = ['all'], force: bool = False, noop: bool = False): - """Remove files and directories not tracked in PKGBUILDs.git. Passing in an empty `what` defaults it to `['all']`""" + """ + Clean temporary files from PKGBUILDs + + Specifying no location defaults to the special value 'all', meaning all regular locations. + + There is also the special value 'git' which uses git to clean everything. + Be careful with it, as it means re-downloading sources for your packages. + """ if noop: logging.debug('Running in noop mode!') if force: @@ -131,7 +141,7 @@ def cmd_clean(what: Iterable[str] = ['all'], force: bool = False, noop: bool = F what = what or ['all'] logging.debug(f'Clearing {what} from PKGBUILDs') pkgbuilds = config.get_path('pkgbuilds') - if 'all' in what: + if 'git' in what: check_programs_wrap(['git']) warning = "Really reset PKGBUILDs to git state completely?\nThis will erase any untracked changes to your PKGBUILDs directory." if not (noop or force or click.confirm(warning)): @@ -147,11 +157,13 @@ def cmd_clean(what: Iterable[str] = ['all'], force: bool = False, noop: bool = F logging.fatal('Failed to git clean') exit(1) else: + if 'all' in what: + what = CLEAN_LOCATIONS what = set(what) dirs = [] - for loc in ['pkg', 'src']: + for loc in CLEAN_LOCATIONS: if loc in what: - logging.info(f'gathering {loc} directories') + logging.info(f'gathering {loc} instances') dirs += glob(os.path.join(pkgbuilds, '*', '*', loc)) dir_lines = '\n'.join(dirs) @@ -162,8 +174,8 @@ def cmd_clean(what: Iterable[str] = ['all'], force: bool = False, noop: bool = F if not click.confirm("Really remove all of these?", default=True): return - for dir in dirs: - if not noop: + if not noop: + for dir in dirs: remove_file(dir, recursive=True) diff --git a/wrapper/__init__.py b/wrapper/__init__.py index 5ec4d37..5571867 100644 --- a/wrapper/__init__.py +++ b/wrapper/__init__.py @@ -29,7 +29,8 @@ def wrap(wrapper_type: str = None): def is_wrapped(wrapper_type: str = None): - return get_wrapper_impl(wrapper_type).is_wrapped() + wrapper_type = get_wrapper_type(wrapper_type) + return wrapper_type != 'none' and get_wrapper_impl(wrapper_type).is_wrapped() def enforce_wrap(no_wrapper=False):