Fix os.symlink on Windows (#460)

This commit is contained in:
Otto Winter 2019-02-28 10:15:57 +01:00 committed by GitHub
parent 69a74a30e8
commit 3951a2b22a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -132,3 +132,16 @@ def resolve_ip_address(host):
raise EsphomeError("Error resolving IP address: {}".format(err))
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()

View File

@ -14,7 +14,7 @@ from esphome.const import ARDUINO_VERSION_ESP32_1_0_1, ARDUINO_VERSION_ESP32_DEV
CONF_TAG, CONF_USE_CUSTOM_CODE
from esphome.core import CORE, EsphomeError
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.py_compat import IS_PY3, string_types
from esphome.storage_json import StorageJSON, storage_path
@ -229,7 +229,7 @@ def symlink_esphome_core_version(esphome_core_version):
do_write = False
if do_write:
mkdir_p(lib_path)
os.symlink(src_path, dst_path)
symlink(src_path, dst_path)
else:
# Remove symlink when changing back from local version
if os.path.islink(dst_path):