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