mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
7f73e2bfde
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.
62 lines
1.5 KiB
Python
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()
|
|
}
|
|
)
|