202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
+
+
+
+
+
+
+
+
+
+
+
+
|
return players[typ][-1]
# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
def xdg(self, path="/streamtuner2"):
home = os.environ.get("HOME", self.tmp)
config = os.environ.get("XDG_CONFIG_HOME", os.environ.get("APPDATA", home+"/.config"))
datadir = os.environ.get("XDG_DATA_HOME", os.environ.get("APPDATA", home+"/.cache"))
# storage dir
self.dir = config + path
self.datadir = datadir + path # not actually used, for now we have subdir symlinks from .config to .cache
# create if necessary
if (not os.path.exists(self.dir)):
os.makedirs(self.dir)
if (not os.path.exists(self.datadir)):
os.makedirs(self.datadir)
# move/symlink cache files/dirs into datadir
if not self.windows:
for source, target in [(self.dir+"/"+sub, self.datadir+"/"+sub) for sub in ["cache", "icons", "themes"]]:
if os.path.exists(source) and not os.path.exists(target):
os.rename(source, target)
if os.path.exists(target) and not os.path.exists(source):
os.symlink(target, source)
# store some configuration list/dict into a file
def save(self, name="settings", data=None, gz=0, nice=0):
name = name + ".json"
if (data is None):
data = vars(self)
|