Skip to content

Commit

Permalink
feat: zip file support for gh-release installer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbraun89 authored Apr 8, 2023
1 parent fb2df7b commit 99998ec
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 80 deletions.
24 changes: 16 additions & 8 deletions nanolayer/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ def _strip_if_wrapped_around(value: str, char: str) -> str:

@app.command("apt-get")
def install_apt_get_packages(
packages: str = typer.Argument(None, help="comma separated list of apt-get packages"),
ppas: Optional[str] = typer.Option(None, help="comma separated list of ppas to make use of"),
packages: str = typer.Argument(
None, help="comma separated list of apt-get packages"
),
ppas: Optional[str] = typer.Option(
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,
Expand All @@ -93,13 +96,14 @@ def install_apt_get_packages(
@app.command("apt")
def install_apt_packages(
packages: str = typer.Argument(None, help="comma separated list of apt packages"),
ppas: Optional[str] = typer.Option(None, help="comma separated list of ppas to make use of"),
ppas: Optional[str] = typer.Option(
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,
Expand All @@ -112,8 +116,12 @@ def install_apt_packages(

@app.command("aptitude")
def install_aptitude_packages(
packages: str = typer.Argument(None, help="comma separated list of aptitude packages"),
ppas: Optional[str] = typer.Option(None, help="comma separated list of ppas to make use of"),
packages: str = typer.Argument(
None, help="comma separated list of aptitude packages"
),
ppas: Optional[str] = typer.Option(
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,
Expand All @@ -140,7 +148,7 @@ def install_gh_release_binary(
) -> None:
if target == "":
raise typer.BadParameter("target cannot be empty string")

GHReleaseInstaller.install(
repo=repo,
target_name=target,
Expand Down
18 changes: 10 additions & 8 deletions nanolayer/installers/apt/apt_installer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import tempfile
from typing import Dict, List, Optional

from nanolayer.installers.apt_get.apt_get_installer import AptGetInstaller
from nanolayer.utils.invoker import Invoker
from nanolayer.utils.linux_information_desk import LinuxInformationDesk
from nanolayer.installers.apt_get.apt_get_installer import AptGetInstaller


class AptInstaller:

class AptUpdateFailed(Invoker.InvokerException):
pass

Expand All @@ -23,7 +22,6 @@ def _parse_env_file(path: str) -> Dict[str, str]:
if not line.startswith("#")
)


@classmethod
def is_debian_like(cls) -> bool:
return (
Expand Down Expand Up @@ -63,9 +61,11 @@ def install(
)

if ppas:
software_properties_common_installed = AptGetInstaller._add_ppas(ppas=ppas,
update=True,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu)
software_properties_common_installed = AptGetInstaller._add_ppas(
ppas=ppas,
update=True,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu,
)

Invoker.invoke(
command=f"apt install -y --no-install-recommends {' '.join(packages)}",
Expand All @@ -75,8 +75,10 @@ def install(

finally:
if clean_ppas:
AptGetInstaller._clean_ppas(ppas=ppas,
remove_software_properties_common=software_properties_common_installed)
AptGetInstaller._clean_ppas(
ppas=ppas,
remove_software_properties_common=software_properties_common_installed,
)

if clean_cache:
Invoker.invoke(
Expand Down
43 changes: 21 additions & 22 deletions nanolayer/installers/apt_get/apt_get_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def is_debian_like(cls) -> bool:
)

@classmethod
def _clean_ppas(cls, ppas: List[str], remove_software_properties_common: bool) -> None:

def _clean_ppas(
cls, ppas: List[str], remove_software_properties_common: bool
) -> None:
normalized_ppas = cls.normalize_ppas(ppas)

for ppa in normalized_ppas:
Expand All @@ -62,33 +63,30 @@ def _clean_ppas(cls, ppas: List[str], remove_software_properties_common: bool) -
exception_class=cls.RemovePPAsFailed,
)


@classmethod
def _add_ppas(cls, ppas: List[str], update: bool, force_ppas_on_non_ubuntu: bool = False) -> bool:
def _add_ppas(
cls, ppas: List[str], update: bool, force_ppas_on_non_ubuntu: bool = False
) -> bool:
software_properties_common_installed = False

if not ppas:
return software_properties_common_installed

if not cls.is_ubuntu() and not force_ppas_on_non_ubuntu:
raise cls.PPASOnNonUbuntu()

normalized_ppas = cls.normalize_ppas(ppas)

if (
Invoker.invoke(
"dpkg -s software-properties-common", raise_on_failure=False
)
!= 0
):

if (
Invoker.invoke("dpkg -s software-properties-common", raise_on_failure=False)
!= 0
):
Invoker.invoke(
command="apt-get install -y software-properties-common",
raise_on_failure=True,
exception_class=cls.AddPPAsFailed,
)
software_properties_common_installed = True


for ppa in normalized_ppas:
Invoker.invoke(
Expand All @@ -103,9 +101,8 @@ def _add_ppas(cls, ppas: List[str], update: bool, force_ppas_on_non_ubuntu: bool
raise_on_failure=True,
exception_class=cls.AptGetUpdateFailed,
)

return software_properties_common_installed


@classmethod
def install(
Expand All @@ -124,7 +121,6 @@ def install(
if ppas and not cls.is_ubuntu() and not force_ppas_on_non_ubuntu:
raise cls.PPASOnNonUbuntu()


software_properties_common_installed = False
with tempfile.TemporaryDirectory() as tempdir:
if preserve_apt_list:
Expand All @@ -142,8 +138,10 @@ def install(
)

if ppas:
software_properties_common_installed = cls._add_ppas(ppas, update=True)

software_properties_common_installed = cls._add_ppas(
ppas, update=True
)

Invoker.invoke(
command=f"apt-get install -y --no-install-recommends {' '.join(packages)}",
raise_on_failure=True,
Expand All @@ -152,9 +150,10 @@ def install(

finally:
if ppas and clean_ppas:
cls._clean_ppas(ppas=ppas,
remove_software_properties_common=software_properties_common_installed)

cls._clean_ppas(
ppas=ppas,
remove_software_properties_common=software_properties_common_installed,
)

if clean_cache:
Invoker.invoke(
Expand Down
15 changes: 9 additions & 6 deletions nanolayer/installers/aptitude/aptitude_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ def install(
aptitude_installed = True

if ppas:
software_properties_common_installed = AptGetInstaller._add_ppas(ppas=ppas,
update=True,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu)

software_properties_common_installed = AptGetInstaller._add_ppas(
ppas=ppas,
update=True,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu,
)

Invoker.invoke(
command=f"aptitude install -y {' '.join(packages)}",
Expand All @@ -76,8 +77,10 @@ def install(

finally:
if clean_ppas:
AptGetInstaller._clean_ppas(ppas=ppas,
remove_software_properties_common=software_properties_common_installed)
AptGetInstaller._clean_ppas(
ppas=ppas,
remove_software_properties_common=software_properties_common_installed,
)

if clean_cache:
Invoker.invoke(
Expand Down
Loading

0 comments on commit 99998ec

Please sign in to comment.