def find_app_path(): """Try to find the app_path, prompt user to set one if it is not found.""" import os import inquirer from hyperglass_agent.util import set_app_path from hyperglass_agent.constants import APP_PATHS try: set_app_path(required=True) app_path = Path(os.environ["hyperglass_agent_directory"]) except RuntimeError: warning( "None of the supported paths for hyperglass-agent were found.\n" + "Checked:\n{one}\n{two}", one=APP_PATHS[0], two=APP_PATHS[1], ) create = confirm(style("Would you like to create one?", **WARNING)) if not create: error("hyperglass-agent requires an application path, " + "but you've chosen not to create one.") elif create: available_paths = [ inquirer.List( "selected", message="Choose a directory for hyperglass-agent", choices=APP_PATHS, ) ] answer = inquirer.prompt(available_paths) if answer is None: error("A directory for hyperglass-agent is required") selected = answer["selected"] if not selected.exists(): create_dir(selected) app_path = selected return app_path
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ # Third Party import uvloop import stackprinter # Project from hyperglass_agent.util import set_app_path stackprinter.set_excepthook() uvloop.install() set_app_path(required=False) __name__ = "hyperglass_agent" __title__ = "Hyperglass Agent" __description__ = "The Linux Routing Agent for hyperglass" __version__ = "0.1.6"
import os from pathlib import Path # Third Party import yaml from pydantic import ValidationError # Project from hyperglass_agent.log import log, set_log_level, enable_file_logging from hyperglass_agent.util import set_app_path from hyperglass_agent.exceptions import ConfigError, ConfigInvalid from hyperglass_agent.models.general import General from hyperglass_agent.models.commands import Commands if os.environ.get("hyperglass_agent_directory") is None: set_app_path(required=True) try: APP_PATH = Path(os.environ["hyperglass_agent_directory"]) except KeyError: raise ConfigError( "No application path was found. Please consult the setup documentation." ) CONFIG_FILE = APP_PATH / "config.yaml" def _get_config(): """Read config file & load YAML to dict. Raises: