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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [256b1e5833]

Overview
Comment:Introduce log.ERR() etc. instead of __print__(dbg.XY...) workaround (was meant for Py3 only).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 256b1e5833983928c44130cab2e833fe16989fff
User & Date: mario on 2015-04-20 16:22:34
Other Links: manifest | tags
Context
2015-04-20
16:24
Move playlist extension and context probing into separate functions. Introduce some rather crude import functionality for a few playlist file formats. (Still requires proper importer with title= reading, and entirely rows[] based function signatures in action module.) check-in: 8e3b1e4d5b user: mario tags: trunk
16:22
Introduce log.ERR() etc. instead of __print__(dbg.XY...) workaround (was meant for Py3 only). check-in: 256b1e5833 user: mario tags: trunk
16:21
Remove some obsolete comments/code snippets. check-in: dd605f1352 user: mario tags: trunk
Changes

Modified config.py from [d8d4d07b70] to [8f2ac16ca3].

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import zlib
import zipfile
import inspect
import pkgutil
import argparse

# export symbols
__all__ = ["conf", "__print__", "dbg", "plugin_meta", "module_list", "get_data", "find_executable"]


#-- create a stub instance of config object
conf = object()

# separate instance of netrc, if needed
netrc = None







|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import zlib
import zipfile
import inspect
import pkgutil
import argparse

# export symbols
__all__ = ["conf", "log", "__print__", "dbg", "plugin_meta", "module_list", "get_data", "find_executable"]


#-- create a stub instance of config object
conf = object()

# separate instance of netrc, if needed
netrc = None
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
            else:
                return # file not found
            # decode
            r = json.load(f)
            f.close()
            return r
        except Exception as e:
            __print__(dbg.ERR, "JSON parsing error (in "+name+")", e)
        

    # recursive dict update
    def update(self, with_new_data):
        for key,value in with_new_data.items():
            if type(value) == dict:
                self[key].update(value)







|







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
            else:
                return # file not found
            # decode
            r = json.load(f)
            f.close()
            return r
        except Exception as e:
            log.ERR("JSON parsing error (in "+name+")", e)
        

    # recursive dict update
    def update(self, with_new_data):
        for key,value in with_new_data.items():
            if type(value) == dict:
                self[key].update(value)
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
        "type": "module", "api": "python", "doc": ""
    }

    # extract coherent comment block, split doc section
    if not literal:
        src = rx.comment.search(src)
        if not src:
            __print__(dbg.ERR, "Couldn't read source meta information:", fn)
            return meta
        src = src.group(0)
        src = rx.hash.sub("", src).strip()
    
    # split comment block
    if src.find("\n\n") > 0:
        src, meta["doc"] = src.split("\n\n", 1)







|







415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
        "type": "module", "api": "python", "doc": ""
    }

    # extract coherent comment block, split doc section
    if not literal:
        src = rx.comment.search(src)
        if not src:
            log.ERR("Couldn't read source meta information:", fn)
            return meta
        src = src.group(0)
        src = rx.hash.sub("", src).strip()
    
    # split comment block
    if src.find("\n\n") > 0:
        src, meta["doc"] = src.split("\n\n", 1)
483
484
485
486
487
488
489





































490
491
492
493
494
495
496
    "HTTP": r"[HTTP]", # magenta HTTP REQUEST
    "DATA": r"[DATA]", # cyan   DATA
    "INFO": r"[INFO]", # gray   INFO
    "STAT": r"[STATE]", # gray  CONFIG STATE
})









































   

#-- populate global conf instance
conf = ConfigDict()
__print__(dbg.PROC, "ConfigDict() initialized")







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






|
483
484
485
486
487
488
489
490
491
492
493
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
524
525
526
527
528
529
530
531
532
533
    "HTTP": r"[HTTP]", # magenta HTTP REQUEST
    "DATA": r"[DATA]", # cyan   DATA
    "INFO": r"[INFO]", # gray   INFO
    "STAT": r"[STATE]", # gray  CONFIG STATE
})


# Simplified print wrapper: `log.err(...)`
class log_printer(object):

    # Wrapper
    method = None
    def __getattr__(self, name):
        self.method = name
        return self.__print__
    
    # Printer
    def __print__(self, *args, **kwargs):
        # debug level
        method = self.method.upper()
        if not method == "ERR":
            if "debug" in conf and not conf.debug:
                return
        # color/prefix
        method = r"[{}[{}]".format(self.colors.get(method, "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
        "UI":   "34m", # blue   USER INTERFACE BEHAVIOUR
        "HTTP": "35m", # magenta HTTP REQUEST
        "DATA": "36m", # cyan   DATA
        "INFO": "37m", # gray   INFO
        "STAT": "37m", # gray   CONFIG STATE
    }

# instantiate right away
log = log_printer()



   

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