Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ ⎇ branch:  streamtuner2


Diff

Differences From Artifact [08e51d1986]:

To Artifact [833278b4e6]:


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#    { arg: --gtk3, type: boolean,  name: gtk3,      description: Start with Gtk3 interface. }
#    { arg: --nt,   type: boolean,  name: nothreads, description: Disable threading/gtk_idle UI. }
#    { arg: -D,     type: boolean,  name: debug,     description: Enable debug messages on console }
#    { arg: action, type: str *,    name: action[],  description: CLI interface commands. }
#    { arg: -x,     type: boolean,  name: exit,      hidden: 1 }
#    { arg: -V,     type: boolean,  name: version,   description: Print version.  }
#    { arg: -w,     type: boolean,  name: pydoc,     hiden: 1  }
# version: 2.7
# priority: core
# depends: pluginconf >= 0.1, os, json, re, zlib, pkgutil
#
# Ties together the global conf.* object. It's typically used
# in the main application and modules with:
#
#   from config import *







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#    { arg: --gtk3, type: boolean,  name: gtk3,      description: Start with Gtk3 interface. }
#    { arg: --nt,   type: boolean,  name: nothreads, description: Disable threading/gtk_idle UI. }
#    { arg: -D,     type: boolean,  name: debug,     description: Enable debug messages on console }
#    { arg: action, type: str *,    name: action[],  description: CLI interface commands. }
#    { arg: -x,     type: boolean,  name: exit,      hidden: 1 }
#    { arg: -V,     type: boolean,  name: version,   description: Print version.  }
#    { arg: -w,     type: boolean,  name: pydoc,     hiden: 1  }
# version: 2.8
# priority: core
# depends: pluginconf >= 0.1, os, json, re, zlib, pkgutil
#
# Ties together the global conf.* object. It's typically used
# in the main application and modules with:
#
#   from config import *
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
235
236
237


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
        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)
            if "args" in data:
                data.pop("args")
            nice = 1


        # check for subdir
        if (name.find("/") > 0):
            subdir = name[0:name.find("/")]
            subdir = self.dir + "/" + subdir
            if (not os.path.exists(subdir)):
                os.mkdir(subdir)
                open(subdir+"/.nobackup", "w").close()
        # target filename
        file = self.dir + "/" + name
        # encode as JSON
        try:
            data = json.dumps(data, indent=(4 if nice else None), sort_keys=True)
        except Exception as e:
            log.ERR("JSON encoding failed", e)
            return
        # .gz or normal file







|



|






|
>
>
>
|
>
|
>
|
>
|
>

>
>
|
|










>
>



|



<
|







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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
        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_CACHE_HOME", os.environ.get("APPDATA", home+"/.cache"))
        
        # storage dir
        self.dir = config + path
        self.datadir = datadir + path
        
        # 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)

        # symlink subdirs from .config to .cache
        self.xdg_move(self.dir, self.datadir, ["cache", "icons", "themes"])

    # move/symlink cache files/dirs into datadir
    def xdg_move(self, config_dir, cache_dir, folders):
        if self.windows:
            return
        for sub in folders:
            source, target = (dir+"/"+sub for dir in [config_dir, cache_dir])
            if not os.path.exists(target):
                if os.path.exists(source): # move .config/* to .cache/*
                    os.rename(source, target)
                else:
                    os.makedirs(target)    # create .cache/*
            if os.path.exists(target) and not os.path.exists(source):
                os.symlink(target, source) # symlink .config → .cache
       

    # 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)
            if "args" in data:
                data.pop("args")
            nice = 1
        # target filename
        file = self.dir + "/" + name
        # check for subdir
        if (name.find("/") > 0):
            subdir = name[0:name.find("/")]
            subdir = self.datadir + "/" + subdir
            if (not os.path.exists(subdir)):
                os.mkdir(subdir)
                open(subdir+"/.nobackup", "w").close()

            file = self.datadir + "/" + name
        # encode as JSON
        try:
            data = json.dumps(data, indent=(4 if nice else None), sort_keys=True)
        except Exception as e:
            log.ERR("JSON encoding failed", e)
            return
        # .gz or normal file
263
264
265
266
267
268
269



270
271
272
273
274
275
276
277
        except TypeError as e:
            f.write(data)  # Python3 sometimes wants to write strings rather than bytes
        f.close()

    # retrieve data from config file            
    def load(self, name):
        name = name + ".json"



        file = self.dir + "/" + name
        try:
            # .gz or normal file
            if os.path.exists(file + ".gz"):
                f = gzip.open(file + ".gz", self.open_mode)
            elif os.path.exists(file):
                f = open(file, self.open_mode)
            else:







>
>
>
|







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
        except TypeError as e:
            f.write(data)  # Python3 sometimes wants to write strings rather than bytes
        f.close()

    # retrieve data from config file            
    def load(self, name):
        name = name + ".json"
        if (name.find("/") > 0):
            file = self.datadir + "/" + name
        else:
            file = self.dir + "/" + name
        try:
            # .gz or normal file
            if os.path.exists(file + ".gz"):
                f = gzip.open(file + ".gz", self.open_mode)
            elif os.path.exists(file):
                f = open(file, self.open_mode)
            else: