Replace config.CACHE_DIR with xdg.CACHE_HOME.

This commit is contained in:
Emmanuel Gil Peyrot 2018-07-04 12:44:55 +02:00
parent 35495fba60
commit d41bfa1c57
4 changed files with 6 additions and 29 deletions

View file

@ -516,26 +516,6 @@ def get_image_cache():
return xdg.CACHE_HOME / 'images'
def check_create_cache_dir():
"""
create the cache directory if it doesn't exist
also create the subdirectories
"""
global CACHE_DIR
cache_home = environ.get("XDG_CACHE_HOME")
if cache_home is None or not Path(cache_home).is_absolute():
cache_home = path.join(environ.get('HOME'), '.cache')
CACHE_DIR = path.join(cache_home, 'poezio')
try:
makedirs(CACHE_DIR)
makedirs(path.join(CACHE_DIR, 'avatars'))
makedirs(path.join(CACHE_DIR, 'images'))
makedirs(path.join(CACHE_DIR, 'caps'))
except OSError:
pass
def check_config():
"""
Check the config file and print results
@ -725,6 +705,3 @@ DATA_DIR = ''
# the global log dir
LOG_DIR = ''
# the global cache dir
CACHE_DIR = ''

View file

@ -25,8 +25,9 @@ from slixmpp.util import FileSystemCache
from poezio import common
from poezio import fixes
from poezio import xdg
from poezio.common import safeJID
from poezio.config import config, options, CACHE_DIR
from poezio.config import config, options
class Connection(slixmpp.ClientXMPP):
@ -120,7 +121,7 @@ class Connection(slixmpp.ClientXMPP):
# Must be loaded before 0030.
self.register_plugin('xep_0115', {
'caps_node': 'https://poez.io',
'cache': FileSystemCache(CACHE_DIR, 'caps', encode=str,
'cache': FileSystemCache(xdg.CACHE_HOME, 'caps', encode=str,
decode=lambda x: DiscoInfo(ET.fromstring(x))),
})
self.register_plugin('xep_0030')

View file

@ -31,7 +31,7 @@ from poezio import windows
from poezio.bookmarks import BookmarkList
from poezio.common import safeJID
from poezio.config import config, firstrun, CACHE_DIR
from poezio.config import config, firstrun
from poezio.contact import Contact, Resource
from poezio.daemon import Executor
from poezio.fifo import Fifo
@ -41,7 +41,7 @@ from poezio.roster import roster
from poezio.size_manager import SizeManager
from poezio.text_buffer import TextBuffer
from poezio.theming import get_theme
from poezio import keyboard
from poezio import keyboard, xdg
from poezio.core.completions import CompletionCore
from poezio.core.commands import CommandCore
@ -77,7 +77,7 @@ class Core(object):
self.bookmarks = BookmarkList()
self.debug = False
self.remote_fifo = None
self.avatar_cache = FileSystemPerJidCache(CACHE_DIR, 'avatars', binary=True)
self.avatar_cache = FileSystemPerJidCache(xdg.CACHE_HOME, 'avatars', binary=True)
# a unique buffer used to store global information
# that are displayed in almost all tabs, in an
# information window.

View file

@ -81,7 +81,6 @@ def main():
config.create_global_config()
config.check_create_data_dir()
config.check_create_log_dir()
config.check_create_cache_dir()
config.setup_logging()
config.post_logging_setup()