Merge pull request 'ruff-6-warnings' (#4937) from ruff-6-warnings into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4937
This commit is contained in:
@@ -31,11 +31,11 @@ def ping_command(args: argparse.Namespace) -> None:
|
||||
if machine in network.peers:
|
||||
found = True
|
||||
|
||||
with network.module.connection(network) as network:
|
||||
with network.module.connection(network) as conn:
|
||||
log.info(f"Pinging '{machine}' in network '{net_name}' ...")
|
||||
res = ""
|
||||
# Check if peer is online
|
||||
ping = network.ping(machine)
|
||||
ping = conn.ping(machine)
|
||||
if ping is None:
|
||||
res = "not reachable"
|
||||
log.info(f"{machine} ({net_name}): {res}")
|
||||
|
||||
@@ -37,22 +37,22 @@ def import_sops(args: argparse.Namespace) -> None:
|
||||
res = run(cmd, RunOpts(error_msg=f"Could not import sops file {file}"))
|
||||
secrets = json.loads(res.stdout)
|
||||
for k, v in secrets.items():
|
||||
k = args.prefix + k
|
||||
secret_name = args.prefix + k
|
||||
if not isinstance(v, str):
|
||||
print(
|
||||
f"WARNING: {k} is not a string but {type(v)}, skipping",
|
||||
f"WARNING: {secret_name} is not a string but {type(v)}, skipping",
|
||||
file=sys.stderr,
|
||||
)
|
||||
continue
|
||||
if (sops_secrets_folder(args.flake.path) / k / "secret").exists():
|
||||
if (sops_secrets_folder(args.flake.path) / secret_name / "secret").exists():
|
||||
print(
|
||||
f"WARNING: {k} already exists, skipping",
|
||||
f"WARNING: {secret_name} already exists, skipping",
|
||||
file=sys.stderr,
|
||||
)
|
||||
continue
|
||||
encrypt_secret(
|
||||
args.flake.path,
|
||||
sops_secrets_folder(args.flake.path) / k,
|
||||
sops_secrets_folder(args.flake.path) / secret_name,
|
||||
v,
|
||||
add_groups=args.group,
|
||||
add_machines=args.machine,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
@@ -14,9 +16,7 @@ def list_command(args: argparse.Namespace) -> None:
|
||||
templates = list_templates(args.flake)
|
||||
|
||||
# Display all templates
|
||||
for i, (template_type, _builtin_template_set) in enumerate(
|
||||
templates.builtins.items(),
|
||||
):
|
||||
for template_type in templates.builtins:
|
||||
builtin_template_set: TemplateClanType | None = templates.builtins.get(
|
||||
template_type,
|
||||
None,
|
||||
@@ -26,31 +26,31 @@ def list_command(args: argparse.Namespace) -> None:
|
||||
|
||||
print(f"Available '{template_type}' templates")
|
||||
print("├── <builtin>")
|
||||
for i, (name, template) in enumerate(builtin_template_set.items()):
|
||||
for builtin_idx, (name, template) in enumerate(builtin_template_set.items()):
|
||||
description = template.get("description", "no description")
|
||||
is_last_template = i == len(builtin_template_set.items()) - 1
|
||||
is_last_template = builtin_idx == len(builtin_template_set.items()) - 1
|
||||
if not is_last_template:
|
||||
print(f"│ ├── {name}: {description}")
|
||||
else:
|
||||
print(f"│ └── {name}: {description}")
|
||||
|
||||
for i, (input_name, input_templates) in enumerate(templates.custom.items()):
|
||||
custom_templates: TemplateClanType | None = input_templates.get(
|
||||
template_type,
|
||||
None,
|
||||
) # type: ignore
|
||||
if not custom_templates:
|
||||
continue
|
||||
|
||||
is_last_input = i == len(templates.custom.items()) - 1
|
||||
visible_inputs = [
|
||||
(input_name, input_templates)
|
||||
for input_name, input_templates in templates.custom.items()
|
||||
if template_type in input_templates
|
||||
]
|
||||
last_idx = len(visible_inputs) - 1
|
||||
for input_idx, (input_name, input_templates) in enumerate(visible_inputs):
|
||||
custom_templates: TemplateClanType = input_templates[template_type] # type: ignore
|
||||
is_last_input = input_idx == last_idx
|
||||
prefix = "│" if not is_last_input else " "
|
||||
if not is_last_input:
|
||||
print(f"├── inputs.{input_name}:")
|
||||
else:
|
||||
print(f"└── inputs.{input_name}:")
|
||||
|
||||
for i, (name, template) in enumerate(custom_templates.items()):
|
||||
is_last_template = i == len(custom_templates.items()) - 1
|
||||
for custom_idx, (name, template) in enumerate(custom_templates.items()):
|
||||
is_last_template = custom_idx == len(custom_templates.items()) - 1
|
||||
if not is_last_template:
|
||||
print(
|
||||
f"{prefix} ├── {name}: {template.get('description', 'no description')}",
|
||||
|
||||
@@ -70,22 +70,31 @@ def substitute(
|
||||
|
||||
with file.open() as f:
|
||||
for line in f:
|
||||
line = line.replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||
processed_line = line.replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||
if clan_core_replacement:
|
||||
line = line.replace("__CLAN_CORE__", clan_core_replacement)
|
||||
line = line.replace(
|
||||
processed_line = processed_line.replace(
|
||||
"__CLAN_CORE__",
|
||||
clan_core_replacement,
|
||||
)
|
||||
processed_line = processed_line.replace(
|
||||
"git+https://git.clan.lol/clan/clan-core",
|
||||
clan_core_replacement,
|
||||
)
|
||||
line = line.replace(
|
||||
processed_line = processed_line.replace(
|
||||
"https://git.clan.lol/clan/clan-core/archive/main.tar.gz",
|
||||
clan_core_replacement,
|
||||
)
|
||||
line = line.replace("__INVENTORY_EXPR__", str(inventory_expr))
|
||||
processed_line = processed_line.replace(
|
||||
"__INVENTORY_EXPR__",
|
||||
str(inventory_expr),
|
||||
)
|
||||
|
||||
line = line.replace("__CLAN_SOPS_KEY_PATH__", sops_key)
|
||||
line = line.replace("__CLAN_SOPS_KEY_DIR__", str(flake / "facts"))
|
||||
buf += line
|
||||
processed_line = processed_line.replace("__CLAN_SOPS_KEY_PATH__", sops_key)
|
||||
processed_line = processed_line.replace(
|
||||
"__CLAN_SOPS_KEY_DIR__",
|
||||
str(flake / "facts"),
|
||||
)
|
||||
buf += processed_line
|
||||
|
||||
print(f"file: {file}")
|
||||
print(f"clan_core: {clan_core_flake}")
|
||||
@@ -202,9 +211,10 @@ class ClanFlake:
|
||||
buf = ""
|
||||
with file.open() as f:
|
||||
for line in f:
|
||||
processed_line = line
|
||||
for key, value in self.substitutions.items():
|
||||
line = line.replace(key, value)
|
||||
buf += line
|
||||
processed_line = processed_line.replace(key, value)
|
||||
buf += processed_line
|
||||
file.write_text(buf)
|
||||
|
||||
def init_from_template(self) -> None:
|
||||
|
||||
@@ -14,8 +14,8 @@ from clan_lib.errors import ClanError
|
||||
def should_skip(file_path: Path, excludes: list[Path]) -> bool:
|
||||
file_path = file_path.resolve() # Ensure absolute path
|
||||
for exclude in excludes:
|
||||
exclude = exclude.resolve()
|
||||
if exclude in file_path.parents or exclude == file_path:
|
||||
resolved_exclude = exclude.resolve()
|
||||
if resolved_exclude in file_path.parents or resolved_exclude == file_path:
|
||||
return True # Skip this file
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user