Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 544f9a7e authored by Wolfgang Rohdewald's avatar Wolfgang Rohdewald

move appdataDir, cacheDir, socketName from kde to common

parent 5803e519
......@@ -24,10 +24,12 @@ from collections import defaultdict
import datetime
import sys
import os
import shutil
import logging
import logging.handlers
import socket
from qt import QStandardPaths
try:
from sip import unwrapinstance
except ImportError:
......@@ -62,6 +64,69 @@ def isAlive(qobj):
return True
def appdataDir():
"""
The per user directory with kajongg application information like the database.
@return: The directory path.
@rtype: C{str}.
"""
serverDir = os.path.expanduser('~/.kajonggserver/')
if Internal.isServer:
# the server might or might not have KDE installed, so to be on
# the safe side we use our own .kajonggserver directory
# the following code moves an existing kajonggserver.db to .kajonggserver
# but only if .kajonggserver does not yet exist
kdehome = os.environ.get('KDEHOME', '~/.kde')
oldPath = os.path.expanduser(
kdehome +
'/share/apps/kajongg/kajonggserver.db')
if not os.path.exists(oldPath):
oldPath = os.path.expanduser(
'~/.kde' +'4/share/apps/kajongg/kajonggserver.db')
if os.path.exists(oldPath) and not os.path.exists(serverDir):
# upgrading an old kajonggserver installation
os.makedirs(serverDir)
shutil.move(oldPath, serverDir)
if not os.path.exists(serverDir):
try:
os.makedirs(serverDir)
except OSError:
pass
return serverDir
else:
if not os.path.exists(serverDir):
# the client wants to place the socket in serverDir
os.makedirs(serverDir)
result = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)
# this may end with kajongg.py or .pyw or whatever, so fix that:
result = os.path.join(os.path.dirname(result), 'kajongg')
if not os.path.exists(result):
os.makedirs(result)
return result
def cacheDir():
"""the cache directory for this user"""
result = os.path.join(appdataDir(), '.cache')
if not os.path.exists(result):
os.makedirs(result)
return result
def socketName():
"""client and server process use this socket to talk to each other"""
serverDir = os.path.expanduser('~/.kajonggserver')
if not os.path.exists(serverDir):
appdataDir()
# allocate the directory and possibly move old databases
# there
if Options.socket:
return Options.socket
else:
return os.path.normpath('{}/socket{}'.format(serverDir, Internal.defaultPort))
class Debug:
"""holds flags for debugging output. At a later time we might
......
......@@ -34,12 +34,10 @@ import gc
from optparse import OptionParser
from common import Debug, StrMixin
from common import Debug, StrMixin, cacheDir
from util import removeIfExists, gitHead, checkMemory
from util import Csv, CsvWriter, popenReadlines
from kde import cacheDir
# fields in row:
RULESETFIELD = 0
AIFIELD = 1
......
......@@ -20,73 +20,4 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# pylint: disable=unused-import, wrong-import-order, wrong-import-position
import os
import shutil
from common import Internal, Options
from kdestub import * # pylint: disable=wildcard-import, unused-wildcard-import
from qt import QStandardPaths
def appdataDir():
"""
The per user directory with kajongg application information like the database.
@return: The directory path.
@rtype: C{str}.
"""
serverDir = os.path.expanduser('~/.kajonggserver/')
if Internal.isServer:
# the server might or might not have KDE installed, so to be on
# the safe side we use our own .kajonggserver directory
# the following code moves an existing kajonggserver.db to .kajonggserver
# but only if .kajonggserver does not yet exist
kdehome = os.environ.get('KDEHOME', '~/.kde')
oldPath = os.path.expanduser(
kdehome +
'/share/apps/kajongg/kajonggserver.db')
if not os.path.exists(oldPath):
oldPath = os.path.expanduser(
'~/.kde' +'4/share/apps/kajongg/kajonggserver.db')
if os.path.exists(oldPath) and not os.path.exists(serverDir):
# upgrading an old kajonggserver installation
os.makedirs(serverDir)
shutil.move(oldPath, serverDir)
if not os.path.exists(serverDir):
try:
os.makedirs(serverDir)
except OSError:
pass
return serverDir
else:
if not os.path.exists(serverDir):
# the client wants to place the socket in serverDir
os.makedirs(serverDir)
result = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)
# this may end with kajongg.py or .pyw or whatever, so fix that:
result = os.path.join(os.path.dirname(result), 'kajongg')
if not os.path.exists(result):
os.makedirs(result)
return result
def cacheDir():
"""the cache directory for this user"""
result = os.path.join(appdataDir(), '.cache')
if not os.path.exists(result):
os.makedirs(result)
return result
def socketName():
"""client and server process use this socket to talk to each other"""
serverDir = os.path.expanduser('~/.kajonggserver')
if not os.path.exists(serverDir):
appdataDir()
# allocate the directory and possibly move old databases
# there
if Options.socket:
return Options.socket
else:
return os.path.normpath('{}/socket{}'.format(serverDir, Internal.defaultPort))
......@@ -36,7 +36,7 @@ from qt import QDialog, QDialogButtonBox, QVBoxLayout, \
QLabel, QComboBox, QLineEdit, QFormLayout, \
QSizePolicy, QWidget
from kde import KUser, KDialog, KDialogButtonBox, appdataDir, socketName
from kde import KUser, KDialog, KDialogButtonBox
from mi18n import i18n, i18nc, english
from dialogs import DeferredDialog, QuestionYesNo
......@@ -45,6 +45,7 @@ from util import removeIfExists, which
from common import Internal, Options, SingleshotOptions, Debug, isAlive
from common import interpreterName
from common import StrMixin
from common import appdataDir, socketName
from game import Players
from query import Query
from statesaver import StateSaver
......
......@@ -32,10 +32,9 @@ from collections import defaultdict
import sqlite3
from mi18n import i18n, i18ncE
from kde import appdataDir
from util import Duration
from log import logInfo, logWarning, logException, logError, logDebug, id4
from common import IntDict, Options, Internal, Debug
from common import IntDict, Options, Internal, Debug, appdataDir
class QueryException(Exception):
......
......@@ -27,14 +27,12 @@ from hashlib import md5
if os.name == 'nt':
import winsound # pylint: disable=import-error
from common import Debug, Internal, StrMixin
from common import Debug, Internal, StrMixin, cacheDir
from util import which, removeIfExists, uniqueList, elapsedSince
from log import logWarning, i18n, logDebug, logException
from qt import QStandardPaths
from kde import cacheDir
from tile import Tile
# Phonon does not work with short files - it plays them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment