fix python lint errors
This commit is contained in:
parent
4820c45982
commit
a48100b8a1
@ -513,9 +513,9 @@ def nix_eval_config(
|
||||
)
|
||||
)
|
||||
|
||||
#factory.addStep(
|
||||
# factory.addStep(
|
||||
# DeployTrigger(scheduler="nixos-deploy", name="nixos-deploy", machines=machines)
|
||||
#)
|
||||
# )
|
||||
# factory.addStep(
|
||||
# DeployNixOS(
|
||||
# name="Deploy NixOS machines",
|
||||
|
@ -13,17 +13,18 @@ from buildbot.process.properties import Interpolate
|
||||
# allow to import modules
|
||||
sys.path.append(str(Path(__file__).parent))
|
||||
|
||||
# ignore: E402
|
||||
from buildbot_nix import nix_build_config, nix_eval_config, nix_update_flake_config
|
||||
|
||||
# ignore: E402
|
||||
from irc_notify import NotifyFailedBuilds
|
||||
from buildbot_nix import ( # noqa: E402
|
||||
nix_build_config,
|
||||
nix_eval_config,
|
||||
nix_update_flake_config,
|
||||
)
|
||||
from irc_notify import NotifyFailedBuilds # noqa: E402
|
||||
|
||||
|
||||
def read_secret_file(secret_name: str) -> str:
|
||||
directory = os.environ.get("CREDENTIALS_DIRECTORY")
|
||||
if directory is None:
|
||||
print(f"directory not set", file=sys.stderr)
|
||||
print("directory not set", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return Path(directory).joinpath(secret_name).read_text()
|
||||
|
||||
@ -111,8 +112,12 @@ def build_config() -> dict[str, Any]:
|
||||
worker_config = json.loads(read_secret_file("buildbot-nix-workers"))
|
||||
|
||||
credentials = os.environ.get("CREDENTIALS_DIRECTORY", ".")
|
||||
has_cachix_auth_token = os.path.isfile(os.path.join(credentials, "cachix-auth-token"))
|
||||
has_cachix_signing_key = os.path.isfile(os.path.join(credentials, "cachix-signing-key"))
|
||||
has_cachix_auth_token = os.path.isfile(
|
||||
os.path.join(credentials, "cachix-auth-token")
|
||||
)
|
||||
has_cachix_signing_key = os.path.isfile(
|
||||
os.path.join(credentials, "cachix-signing-key")
|
||||
)
|
||||
|
||||
systemd_secrets = secrets.SecretInAFile(dirname=credentials)
|
||||
c["secretsProviders"] = [systemd_secrets]
|
||||
@ -127,10 +132,17 @@ def build_config() -> dict[str, Any]:
|
||||
c["builders"] = [
|
||||
# Since all workers run on the same machine, we only assign one of them to do the evaluation.
|
||||
# This should prevent exessive memory usage.
|
||||
nix_eval_config([worker_names[0]], github_token_secret="github-token", automerge_users=[BUILDBOT_GITHUB_USER]),
|
||||
nix_eval_config(
|
||||
[worker_names[0]],
|
||||
github_token_secret="github-token",
|
||||
automerge_users=[BUILDBOT_GITHUB_USER],
|
||||
),
|
||||
nix_build_config(worker_names, has_cachix_auth_token, has_cachix_signing_key),
|
||||
nix_update_flake_config(
|
||||
worker_names, f"{ORG}/{REPO}", github_token_secret="github-token", github_bot_user=BUILDBOT_GITHUB_USER
|
||||
worker_names,
|
||||
f"{ORG}/{REPO}",
|
||||
github_token_secret="github-token",
|
||||
github_bot_user=BUILDBOT_GITHUB_USER,
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -4,15 +4,12 @@ devices = [
|
||||
"phone",
|
||||
]
|
||||
|
||||
hosts = {
|
||||
"turingmachine": "turingmachine.r",
|
||||
"bernie": "bernie.r"
|
||||
}
|
||||
hosts = {"turingmachine": "turingmachine.r", "bernie": "bernie.r"}
|
||||
|
||||
mac_addrs = {
|
||||
"headphone": "E8:07:BF:C8:6B:2C",
|
||||
"shannans_headphone": "00:6A:8E:60:0B:F7",
|
||||
"speaker": "E6:4D:D6:0A:CC:9B"
|
||||
"speaker": "E6:4D:D6:0A:CC:9B",
|
||||
}
|
||||
|
||||
|
||||
@ -27,11 +24,16 @@ def ssh_bluetooth(device: str, action: str, mac: str) -> None:
|
||||
if host is None:
|
||||
logger.warning(f"Unknown host: {host}")
|
||||
return
|
||||
hass.services.call("shell_command", "ssh_bluetooth", {
|
||||
"host": host,
|
||||
"action": action,
|
||||
"mac": mac,
|
||||
}, blocking=False)
|
||||
hass.services.call(
|
||||
"shell_command",
|
||||
"ssh_bluetooth",
|
||||
{
|
||||
"host": host,
|
||||
"action": action,
|
||||
"mac": mac,
|
||||
},
|
||||
blocking=False,
|
||||
)
|
||||
|
||||
|
||||
def connect(device: str, mac: str) -> None:
|
||||
@ -65,7 +67,9 @@ def main() -> None:
|
||||
|
||||
mac = mac_addrs.get(bluetooth_device, None)
|
||||
if not mac:
|
||||
logger.warning("Called without unknown bluetooth device {bluetooth_device} parameter")
|
||||
logger.warning(
|
||||
"Called without unknown bluetooth device {bluetooth_device} parameter"
|
||||
)
|
||||
return
|
||||
|
||||
for d in devices:
|
||||
@ -76,4 +80,5 @@ def main() -> None:
|
||||
if d == device:
|
||||
connect(d, mac)
|
||||
|
||||
|
||||
main()
|
||||
|
@ -1,3 +1,5 @@
|
||||
# noqa: F821
|
||||
|
||||
to_state = data.get("to_state")
|
||||
from_state = data.get("from_state")
|
||||
entity_id = data.get("entity_id")
|
||||
@ -54,7 +56,7 @@ def main():
|
||||
hass.services.call("notify", notify_service, {"message": message}, blocking=False)
|
||||
|
||||
if joerg.state == shannan.state:
|
||||
logger.info(f"shannan and joerg are together now")
|
||||
logger.info("shannan and joerg are together now")
|
||||
hass.services.call(
|
||||
"input_boolean",
|
||||
"turn_off",
|
||||
|
@ -36,7 +36,7 @@ def serialize_option_val(
|
||||
elif isinstance(val, list):
|
||||
return [f"add_list {key}='{interpolate_secrets(v, secrets)}'" for v in val]
|
||||
else:
|
||||
raise ConfigError(f"{context} is not a string")
|
||||
raise ConfigError(f"{val} is not a string")
|
||||
|
||||
|
||||
def serialize_list_section(
|
||||
|
@ -4,6 +4,11 @@ line-length = 88
|
||||
select = ["E", "F", "I"]
|
||||
ignore = [ "E501" ]
|
||||
|
||||
|
||||
[tool.ruff.per-file-ignores]
|
||||
# home-assistant has implicit variables
|
||||
"nixos/eve/modules/home-assistant/python-scripts/*" = ["F821"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.10"
|
||||
warn_redundant_casts = true
|
||||
|
22
tasks.py
22
tasks.py
@ -49,6 +49,7 @@ def deploy_nixos(hosts: List[DeployHost]) -> None:
|
||||
def get_hosts(hosts: str) -> List[DeployHost]:
|
||||
return [DeployHost(h, user="root") for h in hosts.split(",")]
|
||||
|
||||
|
||||
@task
|
||||
def deploy(c, _hosts=""):
|
||||
"""
|
||||
@ -84,7 +85,6 @@ def deploy(c, _hosts=""):
|
||||
eve.run("systemctl restart buildbot-master")
|
||||
|
||||
|
||||
|
||||
@task
|
||||
def deploy_k3s(c):
|
||||
"""
|
||||
@ -137,7 +137,9 @@ def deploy_matchbox(c):
|
||||
DeployHost(
|
||||
"localhost",
|
||||
command_prefix="matchbox.r",
|
||||
meta=dict(target_user="root", target_host="matchbox.r", flake_attr="matchbox"),
|
||||
meta=dict(
|
||||
target_user="root", target_host="matchbox.r", flake_attr="matchbox"
|
||||
),
|
||||
user="joerg",
|
||||
)
|
||||
]
|
||||
@ -203,7 +205,7 @@ def wait_for_port(host: str, port: int, shutdown: bool = False) -> None:
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
break
|
||||
except OSError as ex:
|
||||
except OSError:
|
||||
if shutdown:
|
||||
break
|
||||
else:
|
||||
@ -238,7 +240,7 @@ def kexec_nixos(c, hosts=""):
|
||||
|
||||
url = "https://boot.thalheim.io/kexec-image-$(uname -m).tar.xz"
|
||||
h.run(f"(wget {url} -qO- || curl {url}) | tar -C / -xJf -", become_root=True)
|
||||
h.run(f"/kexec_nixos", become_root=True)
|
||||
h.run("/kexec_nixos", become_root=True)
|
||||
|
||||
print(f"Wait for {h.host} to start", end="")
|
||||
sys.stdout.flush()
|
||||
@ -253,7 +255,7 @@ def kexec_nixos(c, hosts=""):
|
||||
@task
|
||||
def add_github_user(c, hosts="", github_user="Mic92"):
|
||||
def add_user(h: DeployHost) -> None:
|
||||
h.run(f"mkdir -m700 /root/.ssh")
|
||||
h.run("mkdir -m700 /root/.ssh")
|
||||
out = h.run_local(
|
||||
f"curl https://github.com/{github_user}.keys", stdout=subprocess.PIPE
|
||||
)
|
||||
@ -278,16 +280,16 @@ def cloudlab_install(c, disk="/dev/sda", hosts=""):
|
||||
""",
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
h.run(f"/etc/nixos/nixos/images/cloudlab/partition.sh")
|
||||
h.run("/etc/nixos/nixos/images/cloudlab/partition.sh")
|
||||
|
||||
h.run(f"mkdir -p /mnt/var/lib/sops-nix")
|
||||
h.run("mkdir -p /mnt/var/lib/sops-nix")
|
||||
h.run(f"echo '{out.stdout}' > /mnt/var/lib/sops-nix/key.txt")
|
||||
h.run(f"chmod 400 /mnt/var/lib/sops-nix/key.txt")
|
||||
h.run("chmod 400 /mnt/var/lib/sops-nix/key.txt")
|
||||
|
||||
h.run(f"mkdir -p /mnt/etc && cp -r /etc/nixos /mnt/etc/")
|
||||
h.run("mkdir -p /mnt/etc && cp -r /etc/nixos /mnt/etc/")
|
||||
|
||||
h.run(
|
||||
f"""
|
||||
"""
|
||||
nix shell "nixpkgs#git" -c nixos-install --no-root-passwd --flake "/mnt/etc/nixos#cloudlab-node" && reboot
|
||||
"""
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user