Skip to content

Commit 3c07f25

Browse files
Refactor get_pio_environments to use ConfigParser
1 parent a370198 commit 3c07f25

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

OATFWGUI/gui_logic.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import configparser
12
import re
23
import logging
34
import sys
@@ -31,12 +32,9 @@ def read_platformio_ini_file(logic_state: LogicState) -> List[str]:
3132

3233

3334
def get_pio_environments(ini_lines: List[str]) -> List[PioEnv]:
34-
environment_lines = [ini_line for ini_line in ini_lines if ini_line.startswith('[env:')]
35-
raw_pio_envs = []
36-
for environment_line in environment_lines:
37-
match = re.search(r'\[env:(.+)\]', environment_line)
38-
if match:
39-
raw_pio_envs.append(match.group(1))
35+
platformio_ini = configparser.ConfigParser()
36+
platformio_ini.read_string(''.join(ini_lines))
37+
raw_pio_envs = [s.split(':', maxsplit=1)[1] for s in platformio_ini.sections() if s.startswith('env:')]
4038
log.info(f'Found pio environments: {raw_pio_envs}')
4139

4240
# we don't want to build native

0 commit comments

Comments
 (0)