[windows] Replace python2-specific error handling with a check that works in python3 as well (#300)
Fixes #298
This commit is contained in:
4
emsdk
4
emsdk
@@ -268,7 +268,7 @@ def win_set_environment_variable_direct(key, value, system=True):
|
||||
win32api.RegSetValueEx(folder, key, 0, win32con.REG_EXPAND_SZ, value)
|
||||
if VERBOSE: print('Set key=' + key + ' with value ' + value + ' in registry.')
|
||||
except Exception as e:
|
||||
if e[0] == 5 or e[2] == 'Access is denied.':
|
||||
if e.args[0] == 5: # 'Access is denied.'
|
||||
print('Error! Failed to set the environment variable \'' + key + '\'! Setting environment variables permanently requires administrator access. Please rerun this command with administrative privileges. This can be done for example by holding down the Ctrl and Shift keys while opening a command prompt in start menu.')
|
||||
sys.exit(1)
|
||||
print('Failed to write environment variable ' + key + ':', file=sys.stderr)
|
||||
@@ -302,7 +302,7 @@ def win_get_environment_variable(key, system=True):
|
||||
# need to be precise not to set these back to system registry, or expansion items would be lost.
|
||||
return os.environ[key]
|
||||
except Exception as e:
|
||||
if e[0] != 2: # 'The system cannot find the file specified.'
|
||||
if e.args[0] != 2: # 'The system cannot find the file specified.'
|
||||
print('Failed to read environment variable ' + key + ':', file=sys.stderr)
|
||||
print(str(e), file=sys.stderr)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user