diff --git a/scudcloud/__main__.py b/scudcloud/__main__.py index ff8e45c..39ce2c6 100755 --- a/scudcloud/__main__.py +++ b/scudcloud/__main__.py @@ -43,15 +43,20 @@ def main(): app.setWindowIcon(QtGui.QIcon(Resources.get_path('scudcloud.png'))) try: - settings_path = load_settings(args.confdir) + settings_path, cache_path = load_settings(args.confdir, args.cachedir) except: - print("Configuration directory " + args.confdir +\ - " could not be created! Exiting...") + print("Data directories "+args.confdir+" and "+args.cachedir+" could not be created! Exiting...") raise SystemExit() minimized = True if args.minimized is True else None urgent_hint = True if args.urgent_hint is True else None - win = sca.ScudCloud(debug=args.debug, minimized=minimized, urgent_hint=urgent_hint, settings_path=settings_path) + win = sca.ScudCloud( + debug=args.debug, + minimized=minimized, + urgent_hint=urgent_hint, + settings_path=settings_path, + cache_path=cache_path + ) app.commitDataRequest.connect(win.setForceClose, type=QtCore.Qt.DirectConnection) server = QLocalServer() @@ -70,31 +75,38 @@ def restore(): win.showNormal() win.activateWindow() -def load_settings(confdir): - if not os.path.isdir(confdir): - os.makedirs(confdir) - if confdir not in sys.path: - sys.path[0:0] = [confdir] - return confdir +def load_settings(*dirs): + for d in dirs: + if not os.path.isdir(d): + os.makedirs(d) + if dirs[0] not in sys.path: + sys.path[0:0] = [dirs[0]] + return dirs def parse_arguments(): from argparse import ArgumentParser from os.path import expanduser if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: - default_confdir = os.environ['XDG_CONFIG_HOME'] + '/scudcloud' + default_confdir = os.path.join(os.environ['XDG_CONFIG_HOME'], 'scudcloud') else: - default_confdir = '~/.config/scudcloud' + default_confdir = Resources.DEFAULT_CONFDIR + if 'XDG_CACHE_HOME' in os.environ and os.environ['XDG_CACHE_HOME']: + default_cachedir = os.path.join(os.environ['XDG_CACHE_HOME'], 'scudcloud') + else: + default_cachedir = Resources.DEFAULT_CACHEDIR parser = ArgumentParser() - parser.add_argument('--confdir', dest='confdir', metavar='dir', default=default_confdir, help="change the configuration directory") - parser.add_argument('--debug', dest='debug', type=bool, default=False, help="enable webkit debug console (default: False)") - parser.add_argument('--minimized', dest='minimized', type=bool, default=False, help="start minimized to tray (default: False)") - parser.add_argument('--urgent-hint',dest='urgent_hint', type=bool, default=False, help="set window manager URGENT hint( default: False)") - parser.add_argument('--version', action="store_true", help="print version and exit") + parser.add_argument('--confdir', dest='confdir', metavar='dir', default=default_confdir, help="change the configuration directory") + parser.add_argument('--cachedir', dest='cachedir', metavar='dir', default=default_cachedir, help="change the default cache directory") + parser.add_argument('--debug', dest='debug', type=bool, default=False, help="enable webkit debug console (default: False)") + parser.add_argument('--minimized', dest='minimized', type=bool, default=False, help="start minimized to tray (default: False)") + parser.add_argument('--urgent-hint',dest='urgent_hint', type=bool, default=False, help="set window manager URGENT hint( default: False)") + parser.add_argument('--version', action="store_true", help="print version and exit") args = parser.parse_args() if args.version: versions() sys.exit() args.confdir = expanduser(args.confdir) + args.cachedir = expanduser(args.cachedir) return args def versions(): diff --git a/scudcloud/resources.py b/scudcloud/resources.py index 62201cf..2e82f10 100644 --- a/scudcloud/resources.py +++ b/scudcloud/resources.py @@ -2,16 +2,18 @@ class Resources: - APP_NAME = "ScudCloud" - SIGNIN_URL = "https://slack.com/signin" + APP_NAME = 'ScudCloud' + SIGNIN_URL = 'https://slack.com/signin' MAINPAGE_URL_RE = re.compile(r'^http[s]://[a-zA-Z0-9_\-]+.slack.com/?$') MESSAGES_URL_RE = re.compile(r'^http[s]://[a-zA-Z0-9_\-]+.slack.com/messages/.*') SSO_URL_RE = re.compile(r'^http[s]://[a-zA-Z0-9_\-]+.slack.com/sso/saml/start$') SERVICES_URL_RE = re.compile(r'^http[s]://[a-zA-Z0-9_\-]+.slack.com/services/.*') GOOGLE_OAUTH2_URL_RE = re.compile(r'^https://accounts.google.com/o/oauth') - SPELL_DICT_PATH = "/usr/share/hunspell/" SPELL_LIMIT = 6 + SPELL_DICT_PATH = '/usr/share/hunspell' + DEFAULT_CONFDIR = '~/.config/scudcloud' + DEFAULT_CACHEDIR = '~/.cache/scudcloud' # It's initialized in /scudcloud script INSTALL_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/scudcloud/scudcloud.py b/scudcloud/scudcloud.py index cb082bd..ba13dbe 100755 --- a/scudcloud/scudcloud.py +++ b/scudcloud/scudcloud.py @@ -37,13 +37,14 @@ class ScudCloud(QtGui.QMainWindow): speller = Speller() title = 'ScudCloud' - def __init__(self, debug = False, parent = None, minimized = None, urgent_hint = None, settings_path = ""): - super(ScudCloud, self).__init__(parent) + def __init__(self, debug = False, minimized = None, urgent_hint = None, settings_path = '', cache_path = ''): + super(ScudCloud, self).__init__(None) self.debug = debug self.minimized = minimized self.urgent_hint = urgent_hint self.setWindowTitle(self.title) self.settings_path = settings_path + self.cache_path = cache_path self.notifier = Notifier(Resources.APP_NAME, Resources.get_path('scudcloud.png')) self.settings = QSettings(self.settings_path + '/scudcloud.cfg', QSettings.IniFormat) self.notifier.enabled = self.settings.value('Notifications', defaultValue=True, type=bool) @@ -133,7 +134,7 @@ def webSettings(self): QWebSettings.globalSettings().setAttribute(QWebSettings.PrivateBrowsingEnabled, False) # Enabling Cache self.diskCache = QNetworkDiskCache(self) - self.diskCache.setCacheDirectory(self.settings_path) + self.diskCache.setCacheDirectory(self.cache_path) # Required for copy and paste clipboard integration QWebSettings.globalSettings().setAttribute(QWebSettings.JavascriptCanAccessClipboard, True) # Enabling Inspeclet only when --debug=True (requires more CPU usage) diff --git a/scudcloud/speller.py b/scudcloud/speller.py index 9b34a6f..2608397 100644 --- a/scudcloud/speller.py +++ b/scudcloud/speller.py @@ -46,7 +46,7 @@ def dictionaryExists(self, path): return QFile(path + ".dic").exists() and QFile(path + ".aff").exists(); def getDictionaryPath(self): - dicPath = Resources.SPELL_DICT_PATH + QLocale.system().name() + dicPath = os.path.join(Resources.SPELL_DICT_PATH, QLocale.system().name()) if self.dictionaryExists(dicPath): return dicPath return '' diff --git a/scudcloud/wrapper.py b/scudcloud/wrapper.py index 2abd94d..3271264 100644 --- a/scudcloud/wrapper.py +++ b/scudcloud/wrapper.py @@ -1,6 +1,6 @@ from scudcloud.resources import Resources -import sys, subprocess, os, json, tempfile +import sys, subprocess, os, json from urllib import request from urllib.parse import parse_qs, urlparse, urlsplit @@ -10,7 +10,6 @@ from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings from PyQt4.QtNetwork import QNetworkProxy - class Wrapper(QWebView): highlights = 0 @@ -221,7 +220,7 @@ def populate(self, serialized): self.name = data['teams'][0]['team_name'] # Using team id to avoid invalid icon paths (Fixes #315) icon_name = 'scudcloud_' + data['teams'][0]['id'] + '.jpg' - icon_path = os.path.join(tempfile.gettempdir(), icon_name) + icon_path = os.path.join(self.window.cache_path, icon_name) # Download the file to use in notifications file_name, headers = request.urlretrieve(data['icon'], icon_path) self.icon = file_name