Initial Python 3 compatible code

This commit is contained in:
2019-06-06 11:52:23 -05:00
parent d441536f01
commit ef689d04fc
146 changed files with 589 additions and 246 deletions

View File

@@ -1,19 +1,23 @@
import _winreg
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
from builtins import str
import winreg
import os
import sys
from platform_utils import paths
RUN_REGKEY = ur"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
RUN_REGKEY = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
def is_installed(app_subkey):
"""Checks if the currently running copy is installed or portable variant. Requires the name of the application subkey found under the uninstall section in Windows registry."""
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s" % app_subkey)
inst_dir = _winreg.QueryValueEx(key,"InstallLocation")[0]
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s" % app_subkey)
inst_dir = winreg.QueryValueEx(key,"InstallLocation")[0]
except WindowsError:
return False
_winreg.CloseKey(key)
winreg.CloseKey(key)
try:
return os.stat(inst_dir) == os.stat(paths.app_path())
except WindowsError:
@@ -23,19 +27,18 @@ def getAutoStart(app_name):
"""Queries if the automatic startup should be set for the application or not, depending on it's current state."""
try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY)
val = _winreg.QueryValueEx(key, unicode(app_name))[0]
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, RUN_REGKEY)
val = winreg.QueryValueEx(key, str(app_name))[0]
return os.stat(val) == os.stat(sys.argv[0])
except (WindowsError, OSError):
return False
def setAutoStart(app_name, enable=True):
"""Configures automatic startup for the application, if the enable argument is set to True. If set to False, deletes the application AutoStart value."""
print paths.get_executable()
if getAutoStart(app_name) == enable:
return
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY, 0, _winreg.KEY_WRITE)
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, RUN_REGKEY, 0, winreg.KEY_WRITE)
if enable:
_winreg.SetValueEx(key, unicode(app_name), None, _winreg.REG_SZ, paths.get_executable())
winreg.SetValueEx(key, str(app_name), None, winreg.REG_SZ, paths.get_executable())
else:
_winreg.DeleteValue(key, unicode(app_name))
winreg.DeleteValue(key, str(app_name))

View File

@@ -1,3 +1,4 @@
from __future__ import unicode_literals
import os
import languageHandler
import logging

View File

@@ -1,3 +1,4 @@
from __future__ import unicode_literals
import threading
import logging
log = logging.getLogger("mysc.repeating_timer")

View File

@@ -1,4 +1,5 @@
# -*- coding: cp1252
from __future__ import unicode_literals
import sys, os
def restart_program():

View File

@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import logging
log = logging.getLogger("mysc.thread_utils")
import threading