summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/ops.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/ops.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/ops.py b/packages/meshbay-node/src/meshbay_node/ops.py
index 7a8e8ac..40de755 100644
--- a/packages/meshbay-node/src/meshbay_node/ops.py
+++ b/packages/meshbay-node/src/meshbay_node/ops.py
@@ -453,7 +453,7 @@ async def attach_group(state: dict, name: str, shared_dir: str,
if not separate_upload:
block += f' upload = true\n'
try:
- with conf_path.open("a") as f:
+ with conf_path.open("a", encoding="utf-8", newline="\n") as f:
f.write(block)
except OSError as e:
raise OpError(f"Cannot write {conf_path}: {e}", status=500) from e
@@ -485,7 +485,7 @@ async def detach_group(state: dict, name: str) -> dict:
group = match[0]
conf_path = Path(state.get("config_path") or DEFAULT_CONFIG_PATH)
- text = conf_path.read_text()
+ text = conf_path.read_text(encoding="utf-8")
lines = text.split("\n")
rng = _find_group_range(lines, group.id)
@@ -497,7 +497,7 @@ async def detach_group(state: dict, name: str) -> dict:
end += 1
new_lines = lines[:start] + lines[end:]
- conf_path.write_text("\n".join(new_lines))
+ conf_path.write_text("\n".join(new_lines), encoding="utf-8", newline="\n")
log.info("Group detached: %s (%s) removed from %s", group.name, group.id[:8], conf_path)
return {"group_id": group.id, "name": group.name, "config": str(conf_path),
@@ -534,7 +534,7 @@ def _update_node_toml(conf_path: Path, updates: dict) -> None:
"""
if not conf_path.exists():
return
- text = conf_path.read_text()
+ text = conf_path.read_text(encoding="utf-8")
lines = text.split("\n")
node_start = None
@@ -575,13 +575,13 @@ def _update_node_toml(conf_path: Path, updates: dict) -> None:
lines.insert(node_end, _format_value(key, value))
node_end += 1
- conf_path.write_text("\n".join(lines))
+ conf_path.write_text("\n".join(lines), encoding="utf-8", newline="\n")
def _insert_roots_block(conf_path: Path, group_id: str,
root_block: str) -> None:
"""Append a [[groups.roots]] block inside the matching [[groups]] section."""
- text = conf_path.read_text()
+ text = conf_path.read_text(encoding="utf-8")
lines = text.split("\n")
rng = _find_group_range(lines, group_id)
@@ -597,13 +597,13 @@ def _insert_roots_block(conf_path: Path, group_id: str,
+ [""]
+ root_block.rstrip("\n").split("\n")
+ lines[insert_at:])
- conf_path.write_text("\n".join(new_lines))
+ conf_path.write_text("\n".join(new_lines), encoding="utf-8", newline="\n")
def _remove_roots_block(conf_path: Path, group_id: str,
resolved_path: str) -> None:
"""Remove a [[groups.roots]] block whose resolved path matches."""
- text = conf_path.read_text()
+ text = conf_path.read_text(encoding="utf-8")
lines = text.split("\n")
rng = _find_group_range(lines, group_id)
@@ -631,7 +631,7 @@ def _remove_roots_block(conf_path: Path, group_id: str,
if rm_start > 0 and lines[rm_start - 1].strip() == "":
rm_start -= 1
new_lines = lines[:rm_start] + lines[rs_end:]
- conf_path.write_text("\n".join(new_lines))
+ conf_path.write_text("\n".join(new_lines), encoding="utf-8", newline="\n")
return
raise OpError(f"Root path not found in config", status=404)