Source code for satnogsconfig.menu

"""Menu module"""

import logging
import subprocess
import sys

import yaml
from dialog import Dialog

from satnogsconfig import helpers, settings

LOGGER = logging.getLogger(__name__)


[docs]def _load_menu(file): """Load menu structure from YAML file :param file: Menu file stream :type file: file :return: Menu dictionary :rtype: dict """ try: return yaml.safe_load(file) except yaml.YAMLError: LOGGER.exception('Could not load YAML menu file') return None
[docs]def _reboot(): """Reboot system""" subprocess.run(['sync'], check=True) subprocess.run(['reboot'], check=True)
[docs]def _clear_screen(): """Clear screen""" subprocess.run(['clear'], check=True)
[docs]def _get_variables(menu, name=None, mandatory=False): """Get all menu variable items :param menu: Menu dictionary :type menu: dict :param name: Name of menu item :type name: str, optional :param mandatory: Return only mandatory variables :type mandatory: bool, optional :return: Menu variables dictionary :rtype: dict """ variables = {} if menu['type'] == 'submenu': for key, value in menu['items'].items(): variables.update( _get_variables(value, name=key, mandatory=mandatory) ) if menu['type'] in {'variablebox', 'variableyesno'}: if not mandatory or menu.get('mandatory'): variables[name] = menu return variables