|
5 | 5 | import argparse |
6 | 6 | from configparser import SectionProxy |
7 | 7 |
|
8 | | -from ybox.cmd import PkgMgr, build_shell_command, run_command |
| 8 | +from ybox.cmd import (PkgMgr, build_shell_command, check_active_ybox, |
| 9 | + run_command) |
9 | 10 | from ybox.config import StaticConfiguration |
10 | 11 | from ybox.print import print_info |
| 12 | +from ybox.state import RuntimeConfiguration, YboxStateManagement |
11 | 13 |
|
12 | 14 |
|
| 15 | +# noinspection PyUnusedLocal |
13 | 16 | def clean_cache(args: argparse.Namespace, pkgmgr: SectionProxy, docker_cmd: str, |
14 | | - conf: StaticConfiguration) -> int: |
| 17 | + conf: StaticConfiguration, runtime_conf: RuntimeConfiguration, |
| 18 | + state: YboxStateManagement) -> int: |
| 19 | + # pylint: disable=unused-argument |
15 | 20 | """ |
16 | 21 | Clean package cache and related intermediate files. |
17 | 22 |
|
18 | | - :param args: arguments having `quiet` and all other attributes passed by the user |
| 23 | + :param args: arguments having `package` and all other attributes passed by the user |
19 | 24 | :param pkgmgr: the `[pkgmgr]` section from `distro.ini` configuration file of the distribution |
20 | 25 | :param docker_cmd: the podman/docker executable to use |
21 | 26 | :param conf: the :class:`StaticConfiguration` for the container |
| 27 | + :param runtime_conf: the `RuntimeConfiguration` of the container |
| 28 | + :param state: instance of `YboxStateManagement` having the state of all ybox containers |
22 | 29 | :return: integer exit status of clean command where 0 represents success |
23 | 30 | """ |
24 | | - print_info(f"Cleaning package cache in container '{conf.box_name}'") |
25 | | - clean_cmd = pkgmgr[PkgMgr.CLEAN_QUIET.value] if args.quiet else pkgmgr[PkgMgr.CLEAN.value] |
26 | | - return int(run_command(build_shell_command(docker_cmd, conf.box_name, clean_cmd), |
27 | | - exit_on_error=False, error_msg="cleaning package cache")) |
| 31 | + clean_cmd = pkgmgr[PkgMgr.CLEAN.value] if args.ask else pkgmgr[PkgMgr.CLEAN_QUIET.value] |
| 32 | + # run clean for each container since it can involve actions that are container specific |
| 33 | + # apart from the generic ones for the shared root (e.g. AUR cache cleaning for Arch Linux) |
| 34 | + code = 0 |
| 35 | + for container in state.get_containers(shared_root=runtime_conf.shared_root): |
| 36 | + if not check_active_ybox(docker_cmd, container): |
| 37 | + continue |
| 38 | + print_info(f"Cleaning package cache in container '{container}'") |
| 39 | + if (c := int(run_command(build_shell_command(docker_cmd, container, clean_cmd), |
| 40 | + exit_on_error=False, error_msg="cleaning package cache"))) != 0: |
| 41 | + code = c |
| 42 | + print() |
| 43 | + return code |
0 commit comments