Skip to content
This repository has been archived by the owner on Oct 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #507 from raelgc/505-move-cache-to-xdg-cache-home
Browse files Browse the repository at this point in the history
Moving cache path to XDG_CACHE_HOME (#505)
  • Loading branch information
raelgc authored Nov 15, 2016
2 parents 67adddb + dd87253 commit 0159508
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
46 changes: 29 additions & 17 deletions scudcloud/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand Down
8 changes: 5 additions & 3 deletions scudcloud/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
7 changes: 4 additions & 3 deletions scudcloud/scudcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scudcloud/speller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
5 changes: 2 additions & 3 deletions scudcloud/wrapper.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,7 +10,6 @@
from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings
from PyQt4.QtNetwork import QNetworkProxy


class Wrapper(QWebView):

highlights = 0
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0159508

Please sign in to comment.