From 829fedcba5aa2d3518f439bc279e18b688db46f7 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Mon, 28 Nov 2011 21:15:19 -0800 Subject: [PATCH] Use data directory on all OSs --- logviewer.py | 5 +---- ostools.py | 4 +++- pesterchum.py | 19 ++++++++++++++++--- profile.py | 20 ++++++++++++-------- pyquirks.py | 2 +- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/logviewer.py b/logviewer.py index 3fe358a..77935ca 100644 --- a/logviewer.py +++ b/logviewer.py @@ -125,10 +125,7 @@ class PesterLogUserSelect(QtGui.QDialog): @QtCore.pyqtSlot() def openDir(self): - if ostools.isOSX(): - 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)) + QtGui.QDesktopServices.openUrl(QtCore.QUrl("file:///" + os.path.join(_datadir, "logs"), QtCore.QUrl.TolerantMode)) class PesterLogViewer(QtGui.QDialog): def __init__(self, chum, config, theme, parent): diff --git a/ostools.py b/ostools.py index e395477..11ef58b 100644 --- a/ostools.py +++ b/ostools.py @@ -29,5 +29,7 @@ def osVer(): def getDataDir(): if isOSX(): return os.path.join(str(QDesktopServices.storageLocation(QDesktopServices.DataLocation)), "Pesterchum/") + elif isLinux(): + return os.path.join(str(QDesktopServices.storageLocation(QDesktopServices.HomeLocation)), ".pesterchum/") else: - return '' + return os.path.join(str(QDesktopServices.storageLocation(QDesktopServices.DataLocation)), "pesterchum/") diff --git a/pesterchum.py b/pesterchum.py index 1b050e0..17f4d9b 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -1,5 +1,5 @@ # pesterchum -import os, sys, getopt +import os, shutil, sys, getopt if os.path.dirname(sys.argv[0]): os.chdir(os.path.dirname(sys.argv[0])) import version @@ -47,8 +47,21 @@ if not ((major > 4) or (major == 4 and minor >= 6)): _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 _datadir and not os.path.exists(_datadir): - os.mkdir(_datadir) +# UPDATE 2011-11-28 : +# Now using data directory as defined by QDesktopServices on all platforms +# (on Linux, same as using xdg). To stay safe with older versions, copy any +# data (profiles, logs, etc) from old location to new data directory. + +if _datadir: + if not os.path.exists(_datadir): + os.makedirs(_datadir) + if not os.path.exists(_datadir+"profiles/") and os.path.exists("profiles/"): + shutil.move("profiles/", _datadir+"profiles/") + if not os.path.exists(_datadir+"pesterchum.js") and os.path.exists("pesterchum.js"): + shutil.move("pesterchum.js", _datadir+"pesterchum.js") + if not os.path.exists(_datadir+"logs/") and os.path.exists("logs/"): + shutil.move("logs/", _datadir+"logs/") + if not os.path.exists(_datadir+"profiles"): os.mkdir(_datadir+"profiles") if not os.path.exists(_datadir+"pesterchum.js"): diff --git a/profile.py b/profile.py index 4f38054..65dc4d5 100644 --- a/profile.py +++ b/profile.py @@ -311,8 +311,8 @@ class userConfig(object): for dirname, dirnames, filenames in os.walk(_datadir+'themes'): for d in dirnames: themes.append(d) - # For OSX, also load embedded themes. - if ostools.isOSX(): + # Also load embedded themes. + if _datadir: for dirname, dirnames, filenames in os.walk('themes'): for d in dirnames: if d not in themes: @@ -430,7 +430,7 @@ class userProfile(object): fp.close() @staticmethod def newUserProfile(chatprofile): - if os.path.exists("profiles/%s.js" % (chatprofile.handle)): + if os.path.exists("%s/%s.js" % (_datadir+"profiles", chatprofile.handle)): newprofile = userProfile(chatprofile.handle) else: newprofile = userProfile(chatprofile) @@ -519,11 +519,15 @@ class PesterProfileDB(dict): class pesterTheme(dict): def __init__(self, name, default=False): - self.path = _datadir+"themes/%s" % (name) - if not os.path.exists(self.path): - self.path = "themes/%s" % (name) - if not os.path.exists(self.path): - self.path = "themes/pesterchum" + possiblepaths = (_datadir+"themes/%s" % (name), + "themes/%s" % (name), + _datadir+"themes/pesterchum", + "themes/pesterchum") + self.path = "themes/pesterchum" + for p in possiblepaths: + if os.path.exists(p): + self.path = p + break self.name = name try: diff --git a/pyquirks.py b/pyquirks.py index 57d3d38..7bccf7c 100644 --- a/pyquirks.py +++ b/pyquirks.py @@ -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 ostools.isOSX(): + if self._datadir: 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')):