mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 07:28:10 +01:00
Fix os.symlink on Windows (#460)
This commit is contained in:
parent
69a74a30e8
commit
3951a2b22a
2 changed files with 15 additions and 2 deletions
|
@ -132,3 +132,16 @@ def resolve_ip_address(host):
|
||||||
raise EsphomeError("Error resolving IP address: {}".format(err))
|
raise EsphomeError("Error resolving IP address: {}".format(err))
|
||||||
|
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
|
|
||||||
|
def symlink(src, dst):
|
||||||
|
if hasattr(os, 'symlink'):
|
||||||
|
os.symlink(src, dst)
|
||||||
|
else:
|
||||||
|
import ctypes
|
||||||
|
csl = ctypes.windll.kernel32.CreateSymbolicLinkW
|
||||||
|
csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
|
||||||
|
csl.restype = ctypes.c_ubyte
|
||||||
|
flags = 1 if os.path.isdir(src) else 0
|
||||||
|
if csl(dst, src, flags) == 0:
|
||||||
|
raise ctypes.WinError()
|
||||||
|
|
|
@ -14,7 +14,7 @@ from esphome.const import ARDUINO_VERSION_ESP32_1_0_1, ARDUINO_VERSION_ESP32_DEV
|
||||||
CONF_TAG, CONF_USE_CUSTOM_CODE
|
CONF_TAG, CONF_USE_CUSTOM_CODE
|
||||||
from esphome.core import CORE, EsphomeError
|
from esphome.core import CORE, EsphomeError
|
||||||
from esphome.core_config import GITHUB_ARCHIVE_ZIP, LIBRARY_URI_REPO, VERSION_REGEX
|
from esphome.core_config import GITHUB_ARCHIVE_ZIP, LIBRARY_URI_REPO, VERSION_REGEX
|
||||||
from esphome.helpers import mkdir_p, run_system_command
|
from esphome.helpers import mkdir_p, run_system_command, symlink
|
||||||
from esphome.pins import ESP8266_FLASH_SIZES, ESP8266_LD_SCRIPTS
|
from esphome.pins import ESP8266_FLASH_SIZES, ESP8266_LD_SCRIPTS
|
||||||
from esphome.py_compat import IS_PY3, string_types
|
from esphome.py_compat import IS_PY3, string_types
|
||||||
from esphome.storage_json import StorageJSON, storage_path
|
from esphome.storage_json import StorageJSON, storage_path
|
||||||
|
@ -229,7 +229,7 @@ def symlink_esphome_core_version(esphome_core_version):
|
||||||
do_write = False
|
do_write = False
|
||||||
if do_write:
|
if do_write:
|
||||||
mkdir_p(lib_path)
|
mkdir_p(lib_path)
|
||||||
os.symlink(src_path, dst_path)
|
symlink(src_path, dst_path)
|
||||||
else:
|
else:
|
||||||
# Remove symlink when changing back from local version
|
# Remove symlink when changing back from local version
|
||||||
if os.path.islink(dst_path):
|
if os.path.islink(dst_path):
|
||||||
|
|
Loading…
Reference in a new issue