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"[35m[HTTP][0m", # magenta HTTP REQUEST
"DATA": r"[36m[DATA][0m", # cyan DATA
"INFO": r"[37m[INFO][0m", # gray INFO
"STAT": r"[37m[STATE][0m", # 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"[35m[HTTP][0m", # magenta HTTP REQUEST
"DATA": r"[36m[DATA][0m", # cyan DATA
"INFO": r"[37m[INFO][0m", # gray INFO
"STAT": r"[37m[STATE][0m", # 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"[{}[{}][0m".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")
|