handle missing xdg.BaseDirectory (headless platforms etc.)
This commit is contained in:
parent
01ef34b519
commit
ccea1fb986
1 changed files with 14 additions and 3 deletions
17
core/app.py
17
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue