-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp_utils.py
53 lines (42 loc) · 1.35 KB
/
esp_utils.py
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
"""
Utility functions for ESP-IDF tools
"""
import os
import asyncio
from typing import Tuple
async def run_command_async(command: str) -> Tuple[int, str, str]:
"""Run a command asynchronously and capture output
Args:
command: The command to run
Returns:
Tuple[int, str, str]: Return code, stdout, stderr
"""
try:
process = await asyncio.create_subprocess_shell(
command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
return process.returncode, stdout.decode(), stderr.decode()
except Exception as e:
return 1, "", f"Error executing command: {str(e)}"
def get_esp_idf_dir() -> str:
"""Get the ESP-IDF directory path
Returns:
str: Path to the ESP-IDF directory
"""
idf_dir = os.environ["IDF_PATH"]
return os.path.join(idf_dir, "esp-idf")
def get_export_script() -> str:
"""Get the path to the ESP-IDF export script
Returns:
str: Path to the export script
"""
return os.path.join(get_esp_idf_dir(), "export.sh")
def check_esp_idf_installed() -> bool:
"""Check if ESP-IDF is installed
Returns:
bool: True if ESP-IDF is installed, False otherwise
"""
return os.path.exists(get_esp_idf_dir())