summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind@gmail.com>2018-11-11 14:56:07 +0000
committerCalum Lind <calumlind@gmail.com>2018-11-12 10:05:45 +0000
commit10fcbecc0413733f50590890fb54d4b3fd710d13 (patch)
tree1509254594f08635f0b8638cd968c7111dd957c5
parentab7f19fbb8d7b84e8feb62d60d4c3d116ceee442 (diff)
downloaddeluge-10fcbecc0413733f50590890fb54d4b3fd710d13.tar.gz
deluge-10fcbecc0413733f50590890fb54d4b3fd710d13.tar.bz2
deluge-10fcbecc0413733f50590890fb54d4b3fd710d13.zip
[Common] Fix win32 set env issue on Python 3
- On Python 3 find_msvcrt returns None and _wputenv should be used with unicode strings. - Removed the alternative msvcrt set env since `cdll.msvcrt` should suffice. - Removed the broad exception catching.
-rw-r--r--deluge/common.py42
1 files changed, 9 insertions, 33 deletions
diff --git a/deluge/common.py b/deluge/common.py
index f0b519d7e..d82970990 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -1239,50 +1239,26 @@ def set_env_variable(name, value):
if windows_check():
from ctypes import windll
from ctypes import cdll
- from ctypes.util import find_msvcrt
# Update the copy maintained by Windows (so SysInternals Process Explorer sees it)
- try:
- result = windll.kernel32.SetEnvironmentVariableW(name, value)
- if result == 0:
- raise Warning
- except Exception:
- log.warning(
- 'Failed to set Env Var \'%s\' (\'kernel32.SetEnvironmentVariableW\')',
- name,
+ result = windll.kernel32.SetEnvironmentVariableW(name, value)
+ if result == 0:
+ log.info(
+ "Failed to set Env Var '%s' (kernel32.SetEnvironmentVariableW)", name
)
else:
log.debug(
- 'Set Env Var \'%s\' to \'%s\' (\'kernel32.SetEnvironmentVariableW\')',
+ "Set Env Var '%s' to '%s' (kernel32.SetEnvironmentVariableW)",
name,
value,
)
# Update the copy maintained by msvcrt (used by gtk+ runtime)
- try:
- result = cdll.msvcrt._putenv('%s=%s' % (name, value))
- if result != 0:
- raise Warning
- except Exception:
- log.warning('Failed to set Env Var \'%s\' (\'msvcrt._putenv\')', name)
+ result = cdll.msvcrt._wputenv('%s=%s' % (name, value))
+ if result != 0:
+ log.info("Failed to set Env Var '%s' (msvcrt._putenv)", name)
else:
- log.debug('Set Env Var \'%s\' to \'%s\' (\'msvcrt._putenv\')', name, value)
-
- # Update the copy maintained by whatever c runtime is used by Python
- try:
- msvcrt = find_msvcrt()
- msvcrtname = str(msvcrt).split('.')[0] if '.' in msvcrt else str(msvcrt)
- result = cdll.LoadLibrary(msvcrt)._putenv('%s=%s' % (name, value))
- if result != 0:
- raise Warning
- except Exception:
- log.warning(
- 'Failed to set Env Var \'%s\' (\'%s._putenv\')', name, msvcrtname
- )
- else:
- log.debug(
- 'Set Env Var \'%s\' to \'%s\' (\'%s._putenv\')', name, value, msvcrtname
- )
+ log.debug("Set Env Var '%s' to '%s' (msvcrt._putenv)", name, value)
def unicode_argv():