diff --git a/nanolayer/cli/install.py b/nanolayer/cli/install.py index f7849680..138533b6 100644 --- a/nanolayer/cli/install.py +++ b/nanolayer/cli/install.py @@ -81,17 +81,11 @@ def install_apt_get_packages( None, help="comma separated list of ppas to make use of" ), force_ppas_on_non_ubuntu: bool = False, - clean_ppas: bool = True, - clean_cache: bool = True, - preserve_apt_list: bool = True, ) -> None: AptGetInstaller.install( packages=packages.split(","), ppas=ppas.split(",") if ppas else None, force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu, - clean_ppas=clean_ppas, - clean_cache=clean_cache, - preserve_apt_list=preserve_apt_list, ) @@ -102,17 +96,11 @@ def install_apt_packages( None, help="comma separated list of ppas to make use of" ), force_ppas_on_non_ubuntu: bool = False, - clean_ppas: bool = True, - clean_cache: bool = True, - preserve_apt_list: bool = True, ) -> None: AptInstaller.install( packages=packages.split(","), ppas=ppas.split(",") if ppas else None, force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu, - clean_ppas=clean_ppas, - clean_cache=clean_cache, - preserve_apt_list=preserve_apt_list, ) @@ -125,17 +113,11 @@ def install_aptitude_packages( None, help="comma separated list of ppas to make use of" ), force_ppas_on_non_ubuntu: bool = False, - clean_ppas: bool = True, - clean_cache: bool = True, - preserve_apt_list: bool = True, ) -> None: AptitudeInstaller.install( packages=packages.split(","), ppas=ppas.split(",") if ppas else None, force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu, - clean_ppas=clean_ppas, - clean_cache=clean_cache, - preserve_apt_list=preserve_apt_list, ) diff --git a/nanolayer/installers/apt/apt_installer.py b/nanolayer/installers/apt/apt_installer.py index 2d75d162..480a541a 100644 --- a/nanolayer/installers/apt/apt_installer.py +++ b/nanolayer/installers/apt/apt_installer.py @@ -29,9 +29,6 @@ def install( packages: List[str], ppas: Optional[List[str]] = None, force_ppas_on_non_ubuntu: bool = False, - clean_ppas: bool = True, - clean_cache: bool = True, - preserve_apt_list: bool = True, ) -> None: assert ( cls.is_debian_like() @@ -41,8 +38,8 @@ def install( installed_ppas: List[str] = [] with tempfile.TemporaryDirectory() as tempdir: - if preserve_apt_list: - Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}") + # preserving previuse cache + Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}") try: Invoker.invoke(command="apt update -y") @@ -62,13 +59,18 @@ def install( ) finally: - if clean_ppas: - AptGetInstaller._clean_ppas( - ppas=installed_ppas, - purge_packages=support_packages_installed, - ) + # remove ppa indexes + AptGetInstaller._clean_ppas( + ppas=installed_ppas, + purge_packages=support_packages_installed, + ) + + # remove archives cache + Invoker.invoke(command="apt clean") - if clean_cache: - Invoker.invoke(command="apt clean") - if preserve_apt_list: - Invoker.invoke(command=f"mv {tempdir} /var/lib/apt/lists") + # restore lists cache + # Note: The reason for not using the dir/* syntax is because + # that doesnt work on ash based shell (alpine) + Invoker.invoke( + command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists" + ) diff --git a/nanolayer/installers/apt_get/apt_get_installer.py b/nanolayer/installers/apt_get/apt_get_installer.py index 64f173f1..d4dd7845 100644 --- a/nanolayer/installers/apt_get/apt_get_installer.py +++ b/nanolayer/installers/apt_get/apt_get_installer.py @@ -10,9 +10,6 @@ class AptGetInstaller: PPA_SUPPORT_PACKAGES = ("software-properties-common",) PPA_SUPPORT_PACKAGES_DEBIAN = ("python3-launchpadlib",) - class AptGetInstallerError(Exception): - pass - @staticmethod def normalize_ppas(ppas: List[str]) -> List[str]: # normalize ppas to have the ppa: initials @@ -102,9 +99,6 @@ def install( packages: List[str], ppas: Optional[List[str]] = None, force_ppas_on_non_ubuntu: bool = False, - clean_ppas: bool = True, - clean_cache: bool = True, - preserve_apt_list: bool = True, ) -> None: if ppas is None: ppas = [] @@ -117,8 +111,8 @@ def install( installed_ppas: List[str] = [] with tempfile.TemporaryDirectory() as tempdir: - if preserve_apt_list: - Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}") + # preserving previuse cache + Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}") try: Invoker.invoke(command="apt-get update -y") @@ -132,17 +126,18 @@ def install( ) finally: - if ppas and clean_ppas: - cls._clean_ppas( - ppas=installed_ppas, - purge_packages=support_packages_installed, - ) - - if clean_cache: - Invoker.invoke(command="apt-get clean") - - if preserve_apt_list: - # Note: not using dir/* syntax as that doesnt work on 'sh' shell (alpine) - Invoker.invoke( - command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists" - ) + # remove ppa indexes + cls._clean_ppas( + ppas=installed_ppas, + purge_packages=support_packages_installed, + ) + + # remove archives cache + Invoker.invoke(command="apt-get clean") + + # restore lists cache + # Note: The reason for not using the dir/* syntax is because + # that doesnt work on ash based shell (alpine) + Invoker.invoke( + command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists" + ) diff --git a/nanolayer/installers/aptitude/aptitude_installer.py b/nanolayer/installers/aptitude/aptitude_installer.py index 7b24a208..5788d9a2 100644 --- a/nanolayer/installers/aptitude/aptitude_installer.py +++ b/nanolayer/installers/aptitude/aptitude_installer.py @@ -20,10 +20,6 @@ def install( packages: List[str], ppas: Optional[List[str]] = None, force_ppas_on_non_ubuntu: bool = False, - clean_ppas: bool = True, - clean_cache: bool = True, - preserve_apt_list: bool = True, - remove_installer_if_not_exists: bool = True, ) -> None: assert ( cls.is_debian_like() @@ -35,8 +31,8 @@ def install( with tempfile.TemporaryDirectory() as tempdir: try: - if preserve_apt_list: - Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}") + # preserving previuse cache + Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}") Invoker.invoke(command="apt-get update -y") @@ -44,8 +40,6 @@ def install( if Invoker.invoke("dpkg -s aptitude", raise_on_failure=False) != 0: AptGetInstaller.install( packages=["aptitude"], - clean_cache=clean_cache, - preserve_apt_list=preserve_apt_list, ) aptitude_installed = True @@ -62,17 +56,19 @@ def install( Invoker.invoke(command=f"aptitude install -y {' '.join(packages)}") finally: - if clean_ppas: - AptGetInstaller._clean_ppas( - ppas=installed_ppas, - purge_packages=support_packages_installed, - ) + AptGetInstaller._clean_ppas( + ppas=installed_ppas, + purge_packages=support_packages_installed, + ) - if clean_cache: - Invoker.invoke(command="aptitude clean") + Invoker.invoke(command="aptitude clean") - if aptitude_installed and remove_installer_if_not_exists: + if aptitude_installed: Invoker.invoke(command="apt-get -y purge aptitude --auto-remove") - if preserve_apt_list: - Invoker.invoke(command=f"mv {tempdir} /var/lib/apt/lists") + # restore lists cache + # Note: The reason for not using the dir/* syntax is because + # that doesnt work on ash based shell (alpine) + Invoker.invoke( + command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists" + ) diff --git a/nanolayer/installers/devcontainer_feature/oci_feature_installer.py b/nanolayer/installers/devcontainer_feature/oci_feature_installer.py index dc108ec8..fb679b83 100644 --- a/nanolayer/installers/devcontainer_feature/oci_feature_installer.py +++ b/nanolayer/installers/devcontainer_feature/oci_feature_installer.py @@ -24,9 +24,6 @@ class OCIFeatureInstaller: - class FeatureInstallationException(Exception): - pass - class NoPremissions(PermissionError): pass