pesterchum/ostools.py
Dpeta 9d0f074bbe Changes to imports, contants, shebang, luaquirks, pynotify, oyoyo.
- Removed unnecessary imports.
    - Reorganized import order.
    - Removed legacy import conditions.
    - Added python3 shebang to pesterchum.py
    - Set QString to always be str, Python 2 is not supported.
    - Depreciated luaquirks.
    - Added ValueError to write exception block
    - Set "pynotify" to always be none, even if pynotify succesfully imported, since pynotify implementation is broken.
2022-03-20 00:48:19 +01:00

45 lines
1.3 KiB
Python

import os
import sys
import platform
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import QStandardPaths
def isOSX():
return sys.platform == "darwin"
def isWin32():
return sys.platform == "win32"
def isLinux():
return sys.platform.startswith("linux")
def isOSXBundle():
return isOSX() and (os.path.abspath('.').find(".app") != -1)
def isOSXLeopard():
return isOSX() and platform.mac_ver()[0].startswith("10.5")
def osVer():
if isWin32():
return " ".join(platform.win32_ver())
elif isOSX():
ver = platform.mac_ver();
return " ".join((ver[0], " (", ver[2], ")"))
elif isLinux():
return " ".join(platform.linux_distribution())
def getDataDir():
# Temporary fix for non-ascii usernames
# If username has non-ascii characters, just store userdata
# in the Pesterchum install directory (like before)
try:
if isOSX():
return os.path.join(str(QStandardPaths.writableLocation(QStandardPaths.DataLocation)), "Pesterchum/")
elif isLinux():
return os.path.join(str(QStandardPaths.writableLocation(QStandardPaths.HomeLocation)), ".pesterchum/")
else:
return os.path.join(str(QStandardPaths.writableLocation(QStandardPaths.DataLocation)), "pesterchum/")
except UnicodeDecodeError:
return ''