Created ostools module to unify OSX integration and made everything use it.
This commit is contained in:
parent
da7cc697e5
commit
98b681fa56
5 changed files with 55 additions and 66 deletions
4
irc.py
4
irc.py
|
@ -11,8 +11,8 @@ from dataobjs import Mood, PesterProfile
|
|||
from generic import PesterList
|
||||
from version import _pcVersion
|
||||
|
||||
import sys, os
|
||||
if sys.platform == "darwin" and os.path.abspath('.').find('.app') != -1:
|
||||
import ostools
|
||||
if ostools.isOSXBundle():
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
|
11
logviewer.py
11
logviewer.py
|
@ -1,6 +1,7 @@
|
|||
import os, sys
|
||||
import codecs
|
||||
import re
|
||||
import ostools
|
||||
from time import strftime, strptime
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from generic import RightClickList, RightClickTree
|
||||
|
@ -41,9 +42,6 @@ class PesterLogUserSelect(QtGui.QDialog):
|
|||
self.theme = theme
|
||||
self.parent = parent
|
||||
self.handle = parent.profile().handle
|
||||
if sys.platform != "darwin":
|
||||
self.logpath = "logs"
|
||||
else:
|
||||
self.logpath = _datadir+"logs"
|
||||
|
||||
self.setStyleSheet(self.theme["main/defaultwindow/style"])
|
||||
|
@ -125,8 +123,8 @@ class PesterLogUserSelect(QtGui.QDialog):
|
|||
|
||||
@QtCore.pyqtSlot()
|
||||
def openDir(self):
|
||||
if sys.platform == "darwin":
|
||||
_datadir = os.path.join(str(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.DataLocation)),"Pesterchum/")
|
||||
if ostools.isOSX():
|
||||
_datadir = ostools.getDataDir()
|
||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl("file:///" + os.path.join(_datadir, "logs"), QtCore.QUrl.TolerantMode))
|
||||
else:
|
||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl("file:///" + os.path.join(os.getcwd(), "logs"), QtCore.QUrl.TolerantMode))
|
||||
|
@ -143,9 +141,6 @@ class PesterLogViewer(QtGui.QDialog):
|
|||
self.handle = parent.profile().handle
|
||||
self.chum = chum
|
||||
self.convos = {}
|
||||
if sys.platform != "darwin":
|
||||
self.logpath = "logs"
|
||||
else:
|
||||
self.logpath = _datadir+"logs"
|
||||
|
||||
self.setStyleSheet(self.theme["main/defaultwindow/style"])
|
||||
|
|
18
ostools.py
Normal file
18
ostools.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from os import path
|
||||
from sys import platform
|
||||
from PyQt4.QtGui import QDesktopServices
|
||||
|
||||
def isOSX():
|
||||
return platform == "darwin"
|
||||
|
||||
def isWin32():
|
||||
return platform == "win32"
|
||||
|
||||
def isOSXBundle():
|
||||
return isOSX() and path.abspath('.').find(".app")
|
||||
|
||||
def getDataDir():
|
||||
if isOSX():
|
||||
return path.join(str(QDesktopServices.storageLocation(QDesktopServices.DataLocation)), "Pesterchum/")
|
||||
else:
|
||||
return ''
|
|
@ -12,6 +12,7 @@ import codecs
|
|||
import re
|
||||
import socket
|
||||
import platform
|
||||
import ostools
|
||||
from time import strftime, time
|
||||
|
||||
missing = []
|
||||
|
@ -46,8 +47,9 @@ if not ((major > 4) or (major == 4 and minor >= 6)):
|
|||
# OSX's data directory and it doesn't hurt to have everything set up before
|
||||
# plowing on. :o)
|
||||
# ~Lex
|
||||
_datadir = os.path.join(str(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.DataLocation)),"Pesterchum/")
|
||||
if sys.platform == "darwin":
|
||||
_datadir = ostools.getDataDir()
|
||||
# See, what I've done here is that _datadir is '' if we're not on OSX, so the
|
||||
# concatination is the same as if it wasn't there.
|
||||
if not os.path.exists(_datadir):
|
||||
os.mkdir(_datadir)
|
||||
if not os.path.exists(_datadir+"profiles"):
|
||||
|
@ -56,15 +58,8 @@ if sys.platform == "darwin":
|
|||
f = open(_datadir+"pesterchum.js", 'w')
|
||||
f.write("{}")
|
||||
f.close()
|
||||
else:
|
||||
if not os.path.exists("logs"):
|
||||
os.mkdir("logs")
|
||||
if not os.path.exists("profiles"):
|
||||
os.mkdir("profiles")
|
||||
if not os.path.exists("pesterchum.js"):
|
||||
f = open("pesterchum.js", 'w')
|
||||
f.write("{}")
|
||||
f.close()
|
||||
if not os.path.exists(_datadir+"logs"):
|
||||
os.mkdir(_datadir+"logs")
|
||||
|
||||
from menus import PesterChooseQuirks, PesterChooseTheme, \
|
||||
PesterChooseProfile, PesterOptions, PesterUserlist, PesterMemoList, \
|
||||
|
@ -124,9 +119,6 @@ class PesterLog(object):
|
|||
self.parent = parent
|
||||
self.handle = handle
|
||||
self.convos = {}
|
||||
if sys.platform != "darwin":
|
||||
self.logpath = "logs"
|
||||
else:
|
||||
self.logpath = _datadir+"logs"
|
||||
|
||||
def log(self, handle, msg):
|
||||
|
@ -181,9 +173,6 @@ class PesterLog(object):
|
|||
|
||||
class PesterProfileDB(dict):
|
||||
def __init__(self):
|
||||
if sys.platform != "darwin":
|
||||
self.logpath = "logs"
|
||||
else:
|
||||
self.logpath = _datadir+"logs"
|
||||
|
||||
if not os.path.exists(self.logpath):
|
||||
|
@ -248,9 +237,6 @@ class PesterProfileDB(dict):
|
|||
|
||||
class pesterTheme(dict):
|
||||
def __init__(self, name, default=False):
|
||||
if sys.platform != "darwin":
|
||||
self.path = "themes/%s" % (name)
|
||||
else:
|
||||
self.path = _datadir+"themes/%s" % (name)
|
||||
if not os.path.exists(self.path):
|
||||
self.path = "themes/%s" % (name)
|
||||
|
@ -327,9 +313,6 @@ class userConfig(object):
|
|||
# Use for bit flag blink
|
||||
self.PBLINK = 1
|
||||
self.MBLINK = 2
|
||||
if sys.platform != "darwin":
|
||||
self.filename = "pesterchum.js"
|
||||
else:
|
||||
self.filename = _datadir+"pesterchum.js"
|
||||
fp = open(self.filename)
|
||||
self.config = json.load(fp)
|
||||
|
@ -339,9 +322,6 @@ class userConfig(object):
|
|||
else:
|
||||
self.userprofile = None
|
||||
|
||||
if sys.platform != "darwin":
|
||||
self.logpath = "logs"
|
||||
else:
|
||||
self.logpath = _datadir+"logs"
|
||||
|
||||
if not os.path.exists(self.logpath):
|
||||
|
@ -537,11 +517,13 @@ class userConfig(object):
|
|||
fp.close()
|
||||
def availableThemes(self):
|
||||
themes = []
|
||||
for dirname, dirnames, filenames in os.walk('themes'):
|
||||
# Load user themes.
|
||||
for dirname, dirnames, filenames in os.walk(_datadir+'themes'):
|
||||
for d in dirnames:
|
||||
themes.append(d)
|
||||
if sys.platform == "darwin":
|
||||
for dirname, dirnames, filenames in os.walk(_datadir+'themes'):
|
||||
# For OSX, also load embedded themes.
|
||||
if ostools.isOSX():
|
||||
for dirname, dirnames, filenames in os.walk('themes'):
|
||||
for d in dirnames:
|
||||
if d not in themes:
|
||||
themes.append(d)
|
||||
|
@ -549,10 +531,7 @@ class userConfig(object):
|
|||
return themes
|
||||
def availableProfiles(self):
|
||||
profs = []
|
||||
if sys.platform == "darwin":
|
||||
profileloc = _datadir+'profiles'
|
||||
else:
|
||||
profileloc = 'profiles'
|
||||
for dirname, dirnames, filenames in os.walk(profileloc):
|
||||
for filename in filenames:
|
||||
l = len(filename)
|
||||
|
@ -562,9 +541,6 @@ class userConfig(object):
|
|||
return [userProfile(p) for p in profs]
|
||||
class userProfile(object):
|
||||
def __init__(self, user):
|
||||
if sys.platform != "darwin":
|
||||
self.profiledir = "profiles"
|
||||
else:
|
||||
self.profiledir = _datadir+"profiles"
|
||||
|
||||
if type(user) is PesterProfile:
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import os, sys, imp, re
|
||||
import os, sys, imp, re, ostools
|
||||
from PyQt4 import QtGui, QtCore
|
||||
|
||||
class PythonQuirks(object):
|
||||
def __init__(self):
|
||||
self._datadir = os.path.join(str(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.DataLocation)),"Pesterchum/")
|
||||
self._datadir = ostools.getDataDir()
|
||||
self.home = os.getcwd()
|
||||
self.quirks = {}
|
||||
self.last = {}
|
||||
|
@ -18,7 +18,7 @@ class PythonQuirks(object):
|
|||
for fn in os.listdir(os.path.join(self.home, 'quirks')):
|
||||
if fn.endswith('.py') and not fn.startswith('_'):
|
||||
filenames.append(os.path.join(self.home, 'quirks', fn))
|
||||
if sys.platform == "darwin":
|
||||
if ostools.isOSX():
|
||||
if not os.path.exists(os.path.join(self._datadir, 'quirks')):
|
||||
os.mkdir(os.path.join(self._datadir, 'quirks'))
|
||||
for fn in os.listdir(os.path.join(self._datadir, 'quirks')):
|
||||
|
|
Loading…
Reference in a new issue