From ccea1fb986ae677cc47980bf68cc5abd022ecb85 Mon Sep 17 00:00:00 2001 From: Martinez Date: Thu, 5 Nov 2015 10:17:19 +0100 Subject: [PATCH] handle missing xdg.BaseDirectory (headless platforms etc.) --- core/app.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/app.py b/core/app.py index c26eae7..3930ce7 100644 --- a/core/app.py +++ b/core/app.py @@ -4,7 +4,11 @@ import os import sys import re -import xdg.BaseDirectory + +try: + import xdg.BaseDirectory as xdg_bd +except: + xdg_bd = None from . import file from . import text @@ -237,11 +241,18 @@ class Main: self.help_texts = [] # (chapter, [paragraphs]) self.print = text.Output(self.name + '.main') - self.data_dir = os.path.join(xdg.BaseDirectory.xdg_data_home, self.name) + if xdg_bd: + xdg_data = xdg_bd.xdg_data_home + xdg_config = xdg_bd.xdg_config_home + else: + xdg_data = os.path.expanduser('~/.local/share') + xdg_config = os.path.expanduser('~/.config') + + self.data_dir = os.path.join(xdg_data, self.name) file.File(os.path.join(self.data_dir, '.keep')) if use_cfg_file: - self.cfg_file = file.File(os.path.join(xdg.BaseDirectory.xdg_config_home, self.name, 'main.cfg'), encoding='utf-8') + self.cfg_file = file.File(os.path.join(xdg_config, self.name, 'main.cfg'), encoding='utf-8') if not self.cfg_file.data: self.cfg_file.data = '''# Configuration file for %s