feature: custom software suggestions

This commit is contained in:
Vinicius Moreira
2022-05-26 18:18:09 -03:00
parent 9c4d3872bd
commit 57ac55c53f
25 changed files with 840 additions and 368 deletions

View File

@@ -0,0 +1,20 @@
from typing import Optional, Any
class Value:
def __init__(self, value: Optional[Any] = None):
self.value = value
def __repr__(self):
return str(self.value)
def __str__(self):
return self.__repr__()
def __eq__(self, other):
if isinstance(other, Value):
return self.value == other.value
def __hash__(self):
return hash(self.value)

View File

@@ -0,0 +1,35 @@
from logging import Logger
from typing import Dict, Optional, Tuple
from bauh.api.abstract.model import SuggestionPriority
def parse(suggestions_str: str, logger: Optional[Logger] = None, type_: Optional[str] = None,
splitter: str = '=') \
-> Dict[str, SuggestionPriority]:
output = dict()
for line in suggestions_str.split('\n'):
clean_line = line.strip()
if clean_line:
line_split = clean_line.split(splitter, 1)
if len(line_split) == 2:
prio_str, name = line_split[0].strip(), line_split[1].strip()
if prio_str and name:
try:
prio = int(line_split[0])
except ValueError:
if logger:
logger.warning(f"Could not parse {type_ + ' ' if type_ else ''}suggestion: {line}")
continue
output[line_split[1]] = SuggestionPriority(prio)
return output
def sort_by_priority(names_prios: Dict[str, SuggestionPriority]) -> Tuple[str, ...]:
return tuple(pair[1] for pair in sorted(((names_prios[n], n) for n in names_prios), reverse=True))