mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
feat: can specify several users to configure
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
@@ -19,12 +19,17 @@ when not overridden - the same tradeoff the `php` module's Composer config
|
||||
already accepts. A `<clear />` element is included so the configured
|
||||
sources fully replace nuget.org rather than being merged alongside it,
|
||||
matching every other package-manager module's behaviour.
|
||||
|
||||
The same file is additionally written under each configured `--user`'s own
|
||||
home directory (`context.users`), since a non-root user invoking `dotnet`
|
||||
reads its config from there instead.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import xml.etree.ElementTree as ET
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from id_configurator.config import NuGetRepository
|
||||
from id_configurator.context import Context
|
||||
@@ -48,10 +53,17 @@ def _write_nuget_config(context: Context, repositories: list[NuGetRepository]) -
|
||||
package_sources = ET.SubElement(configuration, "packageSources")
|
||||
ET.SubElement(package_sources, "clear")
|
||||
for repository in repositories:
|
||||
ET.SubElement(
|
||||
package_sources, "add", {"key": repository.name, "value": repository.url}
|
||||
attributes = {"key": repository.name, "value": repository.url}
|
||||
if urlparse(repository.url).scheme.lower() != "https":
|
||||
attributes["allowInsecureConnections"] = "true"
|
||||
ET.SubElement(package_sources, "add", attributes)
|
||||
content = _render_xml(configuration)
|
||||
context.write_file(_NUGET_CONFIG, content)
|
||||
for user in context.users:
|
||||
context.write_file(
|
||||
f"{context.home_dir(user)}/.nuget/NuGet/NuGet.Config", content
|
||||
)
|
||||
context.write_file(_NUGET_CONFIG, _render_xml(configuration))
|
||||
logger.info("configured nuget for user %s", user)
|
||||
logger.info("configured nuget to use %d package source(s)", len(repositories))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user