Skip to content

Commit

Permalink
core: autopilot-manager: Migrate to use new settings
Browse files Browse the repository at this point in the history
* Migrate to use new implementations of settings
* Migrate default resources and general configuration to a config file
  • Loading branch information
JoaoMario109 committed Oct 24, 2024
1 parent c231098 commit d7a6ba8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
45 changes: 45 additions & 0 deletions core/services/ardupilot_manager/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This file is used to define general configurations for the app
import appdirs

from collections import namedtuple
from pathlib import Path

SERVICE_NAME = "autopilot-manager"


SETTINGS_PATH = Path(appdirs.user_config_dir(SERVICE_NAME))
LOG_PATH = Path.joinpath(SETTINGS_PATH, "logs")
FIRMWARE_PATH = Path.joinpath(SETTINGS_PATH, "firmware")
USER_FIRMWARE_PATH = Path("/usr/blueos/userdata/firmware")

BLUE_OS_FILES_PATH = Path.joinpath(Path.home(), "blueos-files")
DEFAULTS_PATH = Path.joinpath(BLUE_OS_FILES_PATH, "ardupilot-manager/default")


StaticFile = namedtuple("StaticFile", "parent filename url")
DEFAULT_RESOURCES = [
StaticFile(
DEFAULTS_PATH, "ardupilot_navigator", "https://firmware.ardupilot.org/Sub/stable-4.5.0/navigator/ardusub",
),
StaticFile(
DEFAULTS_PATH, "ardupilot_navigator", "https://firmware.ardupilot.org/Sub/stable-4.5.0/navigator64/ardusub",
),
StaticFile(
DEFAULTS_PATH, "ardupilot_pixhawk1", "https://firmware.ardupilot.org/Sub/stable-4.5.0/Pixhawk1/ardusub.apj"
),
StaticFile(
DEFAULTS_PATH, "ardupilot_pixhawk4", "https://firmware.ardupilot.org/Sub/stable-4.5.0/Pixhawk4/ardusub.apj"
),
]


__all__ = [
"SERVICE_NAME",
"DEFAULT_RESOURCES",
"SETTINGS_PATH",
"LOG_PATH",
"FIRMWARE_PATH",
"USER_FIRMWARE_PATH",
"BLUE_OS_FILES_PATH",
"DEFAULTS_PATH",
]
13 changes: 0 additions & 13 deletions core/services/ardupilot_manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@
from pathlib import Path
from typing import Any, Dict, Optional, Union, cast

import appdirs
from loguru import logger

from typedefs import SITLFrame

SERVICE_NAME = "ardupilot-manager"


class Settings:
app_name = SERVICE_NAME
settings_path = Path(appdirs.user_config_dir(app_name))
settings_file = Path.joinpath(settings_path, "settings.json")
firmware_folder = Path.joinpath(settings_path, "firmware")
user_firmware_folder = Path("/usr/blueos/userdata/firmware")
log_path = Path.joinpath(settings_path, "logs")
app_folders = [settings_path, firmware_folder, log_path, user_firmware_folder]

blueos_files_folder = Path.joinpath(Path.home(), "blueos-files")
defaults_folder = Path.joinpath(blueos_files_folder, "ardupilot-manager/default")
sitl_frame = SITLFrame.UNDEFINED
preferred_router: Optional[str] = None

Expand Down
31 changes: 4 additions & 27 deletions core/services/ardupilot_manager/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,18 @@
import sys
import time
import urllib.request
from collections import namedtuple

from warnings import warn

import setuptools

from settings import Settings

ssl._create_default_https_context = ssl._create_unverified_context
from config import DEFAULT_RESOURCES


autopilot_settings = Settings()
defaults_folder = autopilot_settings.defaults_folder

StaticFile = namedtuple("StaticFile", "parent filename url")
ssl._create_default_https_context = ssl._create_unverified_context

static_files = [
StaticFile(
defaults_folder,
"ardupilot_navigator",
"https://firmware.ardupilot.org/Sub/stable-4.5.0/navigator/ardusub",
),
StaticFile(
defaults_folder,
"ardupilot_navigator",
"https://firmware.ardupilot.org/Sub/stable-4.5.0/navigator64/ardusub",
),
StaticFile(
defaults_folder, "ardupilot_pixhawk1", "https://firmware.ardupilot.org/Sub/stable-4.5.0/Pixhawk1/ardusub.apj"
),
StaticFile(
defaults_folder, "ardupilot_pixhawk4", "https://firmware.ardupilot.org/Sub/stable-4.5.0/Pixhawk4/ardusub.apj"
),
]

for file in static_files:
for file in DEFAULT_RESOURCES:
path = pathlib.Path.joinpath(file.parent, file.filename)
path.parent.mkdir(parents=True, exist_ok=True)

Expand Down

0 comments on commit d7a6ba8

Please sign in to comment.