Files
revng-revng/python/revng/daemon/util.py
Giacomo Vercesi 7f73e2bfde revng.daemon: drop REVNG_PROJECT_ID
Remove the logic for computing a manager's workdir using the
REVNG_PROJECT_ID environment variable, as it was unused. The
REVNG_DATA_DIR remains to allow persistence across restarts.
2023-05-24 14:59:16 +02:00

62 lines
1.5 KiB
Python

#
# This file is distributed under the MIT License. See LICENSE.md for details.
#
import json
import os
from base64 import b64encode
from pathlib import Path
from typing import Dict, List, Optional
def clean_double_dict(dictionary: Dict[str, Dict[str, List]]):
keys_to_delete = []
for key in dictionary.keys():
clean_dict(dictionary[key])
if not dictionary[key]:
keys_to_delete.append(key)
for key in keys_to_delete:
dictionary.pop(key)
def clean_dict(dictionary: Dict[str, List]):
keys_to_delete = []
for key in dictionary.keys():
if not dictionary[key]:
keys_to_delete.append(key)
for key in keys_to_delete:
dictionary.pop(key)
def clean_step_list(step_list: List):
for step in step_list:
clean_container_list(step["containers"])
for step in step_list[:]:
if len(step["containers"]) == 0:
step_list.remove(step)
def clean_container_list(container_list: List):
for container in container_list[:]:
if len(container["targets"]) == 0:
container_list.remove(container)
def project_workdir() -> Optional[Path]:
if "REVNG_DATA_DIR" in os.environ:
return Path(os.environ["REVNG_DATA_DIR"])
else:
return None
def produce_serializer(input_: Dict[str, str | bytes]) -> str:
return json.dumps(
{
key: (value if isinstance(value, str) else b64encode(value).decode("utf-8"))
for key, value in input_.items()
}
)