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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [0943cca27e]

Overview
Comment:More customized log categories/colorization.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0943cca27ee4a1a03a84f6537592e8bd28b647f8
User & Date: mario on 2015-04-26 15:34:37
Other Links: manifest | tags
Context
2015-04-26
15:35
Cover most catched exceptions with log messages. check-in: 363dce5eb9 user: mario tags: trunk
15:34
More customized log categories/colorization. check-in: 0943cca27e user: mario tags: trunk
15:34
Add custom pls extractor (for unordered playlist entries), keep regex method as fallback. More logging. check-in: 0725d3fbc8 user: mario tags: trunk
Changes

Modified config.py from [ae59bddda4] to [7f53cc759c].

188
189
190
191
192
193
194
195

196






197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

210

211
212
213
214
215
216
217







-
+

+
+
+
+
+
+







-
+
-







        # 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()
        # write                        
        # target filename
        file = self.dir + "/" + name
        # encode as JSON
        try:
            data = json.dumps(data, indent=(4 if nice else None))
        except Exception as e:
            log.ERR("JSON encoding failed", e)
            return
        # .gz or normal file
        if gz:
            f = gzip.open(file+".gz", "w")
            if os.path.exists(file):
                os.unlink(file)
        else:
            f = open(file, "w")
        # encode
        # write
        data = json.dumps(data, indent=(4 if nice else None))
        try:
            f.write(data.encode("utf-8"))
        except TypeError as e:
            f.write(data)  # Python3 sometimes wants to write strings rather than bytes
        f.close()


265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284







-
+







            try:
                from netrc import netrc as parser
                try:
                     netrc = parser().hosts
                except:
                     netrc = parser(self.xdg() + "/netrc").hosts
            except:
                pass
                log.STAT("No .netrc")
        for server in varhosts:
            if server in netrc:
                return netrc[server]


    # Use config:-style definitions for argv extraction,
    # such as: { arg: -D, name: debug, type: bool }
351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370







-
+







        if gz:
            bin = gzip_decode(bin)
        if decode:
            return bin.decode("utf-8", errors='ignore')
        else:
            return str(bin)
    except:
        pass
        log.WARN("get_data() didn't find:", fn)


# Search through ./channels/ and get module basenames.
# (Reordering channel tabs is now done by uikit.apply_state.)
#
def module_list(plugin_base="channels"):

380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399







-
+







#
def plugin_meta(fn=None, src=None, module=None, frame=1, plugin_base="channels"):

    # try via pkgutil first
    if module:
       fn = module
       try: src = pkgutil.get_data(plugin_base, fn+".py")
       except: pass
       except: pass  # Notice in plugin_meta_extract() is sufficient

    # get source directly from caller
    elif not src and not fn:
        module = inspect.getmodule(sys._getframe(frame))
        fn = inspect.getsourcefile(module)
        src = inspect.getcomments(module)

494
495
496
497
498
499
500
501
502
503
504
505
506









507

508
509
510
511




512
513
514
515
516
517
518
519
520
521
522
523
499
500
501
502
503
504
505






506
507
508
509
510
511
512
513
514
515
516




517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532







-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

+
-
-
-
-
+
+
+
+












        # color/prefix
        method = r"[{}[{}]".format(self.colors.get(method.split("_")[0], "47m"), method)
        # output
        print(method + " " + " ".join([str(a) for a in args]), file=sys.stderr)

    # Colors
    colors = {
        "ERR":  "31m", # red    ERROR
        "INIT": "31m", # red    INIT ERROR
        "PROC": "32m", # green  PROCESS
        "CONF": "33m", # brown  CONFIG DATA
        "DND":  "1;33;41m", #   DRAG'N'DROP
        "UI":   "34m", # blue   USER INTERFACE BEHAVIOUR
        "ERR":  "31m",          # red    ERROR
        "INIT": "38;5;196m",    # red    INIT ERROR
        "WARN": "38;5;208m",    # orange WARNING
        "EXEC": "38;5;66m",     # green  EXEC
        "PROC": "32m",          # green  PROCESS
        "FAVICON":"58;5;119m",  # green  FAVICON
        "CONF": "33m",          # brown  CONFIG DATA
        "DND":  "1;33;41m",     # yl/red DRAG'N'DROP
        "UI":   "34m",          # blue   USER INTERFACE BEHAVIOUR
        "UIKIT":"38;5;222;48;5;235m", # THREAD/UIKIT/IDLE TASKS
        "APPSTATE":"38;5;200m", # magenta APPSTATE RESTORE
        "HTTP": "35m", # magenta HTTP REQUEST
        "DATA": "36m", # cyan   DATA
        "INFO": "37m", # gray   INFO
        "STAT": "37m", # gray   CONFIG STATE
        "HTTP": "35m",          # magenta HTTP REQUEST
        "DATA": "36m",          # cyan   DATA
        "INFO": "38;5;238m",    # lgray  INFO
        "STAT": "37m",          # gray   CONFIG STATE
    }

# instantiate right away
log = log_printer()



   

#-- populate global conf instance
conf = ConfigDict()
log.PROC("ConfigDict() initialized")