mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #1670 from Salamandar/apt_packages_list
Allow passing a list in the manifest.toml for the apt resource packages
This commit is contained in:
commit
d69c196fe4
1 changed files with 26 additions and 17 deletions
|
@ -1011,16 +1011,16 @@ class AptDependenciesAppResource(AppResource):
|
|||
##### Example
|
||||
```toml
|
||||
[resources.apt]
|
||||
packages = "nyancat, lolcat, sl"
|
||||
packages = ["nyancat", "lolcat", "sl"]
|
||||
|
||||
# (this part is optional and corresponds to the legacy ynh_install_extra_app_dependencies helper)
|
||||
extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main"
|
||||
extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
extras.yarn.packages = "yarn"
|
||||
extras.yarn.packages = ["yarn"]
|
||||
```
|
||||
|
||||
##### Properties
|
||||
- `packages`: Comma-separated list of packages to be installed via `apt`
|
||||
- `packages`: List of packages to be installed via `apt`
|
||||
- `packages_from_raw_bash`: A multi-line bash snippet (using triple quotes as open/close) which should echo additional packages to be installed. Meant to be used for packages to be conditionally installed depending on architecture, debian version, install questions, or other logic.
|
||||
- `extras`: A dict of (repo, key, packages) corresponding to "extra" repositories to fetch dependencies from
|
||||
|
||||
|
@ -1047,17 +1047,11 @@ class AptDependenciesAppResource(AppResource):
|
|||
extras: Dict[str, Dict[str, str]] = {}
|
||||
|
||||
def __init__(self, properties: Dict[str, Any], *args, **kwargs):
|
||||
for key, values in properties.get("extras", {}).items():
|
||||
if not all(
|
||||
isinstance(values.get(k), str) for k in ["repo", "key", "packages"]
|
||||
):
|
||||
raise YunohostError(
|
||||
"In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' and 'packages' defined and be strings",
|
||||
raw_msg=True,
|
||||
)
|
||||
|
||||
super().__init__(properties, *args, **kwargs)
|
||||
|
||||
if isinstance(self.packages, str):
|
||||
self.packages = [value.strip() for value in self.packages.split(",")]
|
||||
|
||||
if self.packages_from_raw_bash:
|
||||
out, err = self.check_output_bash_snippet(self.packages_from_raw_bash)
|
||||
if err:
|
||||
|
@ -1065,14 +1059,29 @@ class AptDependenciesAppResource(AppResource):
|
|||
"Error while running apt resource packages_from_raw_bash snippet:"
|
||||
)
|
||||
logger.error(err)
|
||||
self.packages += ", " + out.replace("\n", ", ")
|
||||
self.packages += out.split("\n")
|
||||
|
||||
for key, values in self.extras.items():
|
||||
if isinstance(values.get("packages"), str):
|
||||
values["packages"] = [value.strip() for value in values["packages"].split(",")]
|
||||
|
||||
if not isinstance(values.get("repo"), str) \
|
||||
or not isinstance(values.get("key"), str) \
|
||||
or not isinstance(values.get("packages"), list):
|
||||
raise YunohostError(
|
||||
"In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' defined as strings and 'packages' defined as list",
|
||||
raw_msg=True,
|
||||
)
|
||||
|
||||
def provision_or_update(self, context: Dict = {}):
|
||||
script = [f"ynh_install_app_dependencies {self.packages}"]
|
||||
script = " ".join(["ynh_install_app_dependencies", *self.packages])
|
||||
for repo, values in self.extras.items():
|
||||
script += [
|
||||
f"ynh_install_extra_app_dependencies --repo='{values['repo']}' --key='{values['key']}' --package='{values['packages']}'"
|
||||
]
|
||||
script += " ".join([
|
||||
"ynh_install_extra_app_dependencies",
|
||||
f"--repo='{values['repo']}'",
|
||||
f"--key='{values['key']}'",
|
||||
f"--package='{' '.join(values['packages'])}'"
|
||||
])
|
||||
# FIXME : we're feeding the raw value of values['packages'] to the helper .. if we want to be consistent, may they should be comma-separated, though in the majority of cases, only a single package is installed from an extra repo..
|
||||
|
||||
self._run_script("provision_or_update", "\n".join(script))
|
||||
|
|
Loading…
Add table
Reference in a new issue