-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDeprecated.py
More file actions
114 lines (105 loc) · 5.1 KB
/
Deprecated.py
File metadata and controls
114 lines (105 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import logging
import os
import pathlib
import typing
from ..modes.Clock import Clock
from ..modes.GameOfLife import GameOfLife
from ..modes.PingPong import PingPong
from ..modes.Snake import Snake
from ..modes.Stream import Stream
from ..modes.Weather import Weather
if typing.TYPE_CHECKING:
from ..Frekvens import Frekvens
class Deprecated:
FEATURES: list[tuple[str, str, str, str]] = [
("MODE_ARTNET", "Art-Net", Stream.ENV_OPTION, Stream.NAME),
("MODE_BOLDCLOCK", "Bold clock", Clock.ENV_OPTION, Clock.NAME),
("MODE_DISTRIBUTEDDISPLAYPROTOCOL", "Distributed Display Protocol", Stream.ENV_OPTION, Stream.NAME),
("MODE_E131", "E1.31", Stream.ENV_OPTION, Stream.NAME),
("MODE_GAMEOFLIFECLOCK", "Game of Life clock", GameOfLife.ENV_OPTION, GameOfLife.NAME),
("MODE_GOOGLEWEATHER", "Google weather", Weather.ENV_OPTION, Weather.NAME),
("MODE_HOMEASSISTANTWEATHER", "Home Assistant weather", Weather.ENV_OPTION, Weather.NAME),
("MODE_LARGECLOCK", "Large clock", Clock.ENV_OPTION, Clock.NAME),
("MODE_LARGETICKINGCLOCK", "Large ticking clock", Clock.ENV_OPTION, Clock.NAME),
("MODE_OPENMETEO", "Open-Meteo", Weather.ENV_OPTION, Weather.NAME),
("MODE_OPENWEATHER", "Open Weather", Weather.ENV_OPTION, Weather.NAME),
("MODE_PINGPONGCLOCK", "Ping-Pong clock", PingPong.ENV_OPTION, PingPong.NAME),
("MODE_SMALLCLOCK", "Small clock", Clock.ENV_OPTION, Clock.NAME),
("MODE_SMALLTICKINGCLOCK", "Small ticking clock", Clock.ENV_OPTION, Clock.NAME),
("MODE_SNAKECLOCK", "Snake clock", Snake.ENV_OPTION, Snake.NAME),
("MODE_WORLDWEATHERONLINE", "World Weather Online", Weather.ENV_OPTION, Weather.NAME),
("MODE_WTTRIN", "Wttr.in", Weather.ENV_OPTION, Weather.NAME),
("MODE_YR", "Yr", Weather.ENV_OPTION, Weather.NAME),
]
project: "Frekvens"
def __init__(self, project: "Frekvens") -> None:
self.project = project
def initialize(self) -> None:
self._env()
self._platformio_ini()
def _env(self) -> None:
for old_option, old_name, new_option, new_name in self.FEATURES:
if old_option in self.project.dotenv:
if new_option == Weather.ENV_OPTION:
weather_option = f"WEATHER_{old_option.removeprefix('MODE_')}"
if old_name != "Open Weather":
weather_option = weather_option.removesuffix("WEATHER")
logging.warning(
"%s '%s' is deprecated. Use %s '%s' and %s '%s' instead.",
old_option,
old_name,
new_option,
new_name,
weather_option,
old_name,
)
if weather_option not in self.project.dotenv:
self.project.dotenv[weather_option] = self.project.dotenv[old_option]
else:
logging.warning(
"%s '%s' is deprecated. Use %s '%s' instead.", old_option, old_name, new_option, new_name
)
if new_option not in self.project.dotenv:
self.project.dotenv[new_option] = self.project.dotenv[old_option]
del self.project.dotenv[old_option]
def _platformio_ini(self) -> None:
embed_option = "board_build.embed_files"
embed_path = "firmware/embed/x509_crt_bundle.bin"
embed_paths = self.project.env.GetProjectOption(embed_option, None)
if embed_paths and (
(isinstance(embed_paths, list) and embed_path in embed_paths)
or (isinstance(embed_paths, str) and embed_paths == embed_path)
):
logging.warning(
"'%s = %s' is deprecated and should be removed from platformio.ini.", embed_option, embed_path
)
_path = pathlib.Path(embed_path)
if not _path.exists():
_path.parent.mkdir(parents=True, exist_ok=True)
_path.write_bytes(b"\x00")
partition_table = self.project.env.GetProjectOption("board_build.partitions", None)
if "partitions/2MB_no_ota.csv" == partition_table:
logging.warning(
"The '2MB_no_ota.csv' partition table is deprecated, please migrate to the newer '2MB_no_ota_rev2.csv' table"
)
elif "partitions/4MB.csv" == partition_table:
logging.warning(
"The '4MB.csv' partition table is deprecated, please migrate to the newer '4MB_rev2.csv' table"
)
@staticmethod
def clean() -> None:
for file in [
"firmware/certs/bundle/ca_roots.pem",
"firmware/embed/x509_crt_bundle.bin",
]:
if os.path.isfile(file):
os.remove(file)
print(f"Removing {file}")
for directory in [
"firmware/certs/bundle",
"firmware/certs",
"firmware/embed",
]:
if os.path.isdir(directory):
os.rmdir(directory)
print(f"Removing {directory}")