comparison sat_frontends/jp/output_std.py @ 3640:f4c02bdb2d91

CLI: use global constants for output names
author Goffi <goffi@goffi.org>
date Wed, 08 Sep 2021 11:13:35 +0200
parents be6d91572633
children 4b842c1fb686
comparison
equal deleted inserted replaced
3636:43542cf32e5a 3640:f4c02bdb2d91
24 from sat.tools.common.ansi import ANSI as A 24 from sat.tools.common.ansi import ANSI as A
25 from sat.tools.common import date_utils 25 from sat.tools.common import date_utils
26 import json 26 import json
27 27
28 __outputs__ = ["Simple", "Json"] 28 __outputs__ = ["Simple", "Json"]
29 SIMPLE = "simple"
30 JSON = "json"
31 JSON_RAW = "json_raw"
32 29
33 30
34 class Simple(object): 31 class Simple(object):
35 """Default outputs""" 32 """Default outputs"""
36 33
37 def __init__(self, host): 34 def __init__(self, host):
38 self.host = host 35 self.host = host
39 host.register_output(C.OUTPUT_TEXT, SIMPLE, self.simple_print) 36 host.register_output(C.OUTPUT_TEXT, C.OUTPUT_NAME_SIMPLE, self.simple_print)
40 host.register_output(C.OUTPUT_LIST, SIMPLE, self.list) 37 host.register_output(C.OUTPUT_LIST, C.OUTPUT_NAME_SIMPLE, self.list)
41 host.register_output(C.OUTPUT_DICT, SIMPLE, self.dict) 38 host.register_output(C.OUTPUT_DICT, C.OUTPUT_NAME_SIMPLE, self.dict)
42 host.register_output(C.OUTPUT_LIST_DICT, SIMPLE, self.list_dict) 39 host.register_output(C.OUTPUT_LIST_DICT, C.OUTPUT_NAME_SIMPLE, self.list_dict)
43 host.register_output(C.OUTPUT_DICT_DICT, SIMPLE, self.dict_dict) 40 host.register_output(C.OUTPUT_DICT_DICT, C.OUTPUT_NAME_SIMPLE, self.dict_dict)
44 host.register_output(C.OUTPUT_MESS, SIMPLE, self.messages) 41 host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_SIMPLE, self.messages)
45 host.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print) 42 host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_SIMPLE, self.simple_print)
46 43
47 def simple_print(self, data): 44 def simple_print(self, data):
48 self.host.disp(str(data)) 45 self.host.disp(str(data))
49 46
50 def list(self, data): 47 def list(self, data):
107 class Json(object): 104 class Json(object):
108 """outputs in json format""" 105 """outputs in json format"""
109 106
110 def __init__(self, host): 107 def __init__(self, host):
111 self.host = host 108 self.host = host
112 host.register_output(C.OUTPUT_TEXT, JSON, self.dump) 109 host.register_output(C.OUTPUT_TEXT, C.OUTPUT_NAME_JSON, self.dump)
113 host.register_output(C.OUTPUT_LIST, JSON, self.dump_pretty) 110 host.register_output(C.OUTPUT_LIST, C.OUTPUT_NAME_JSON, self.dump_pretty)
114 host.register_output(C.OUTPUT_LIST, JSON_RAW, self.dump) 111 host.register_output(C.OUTPUT_LIST, C.OUTPUT_NAME_JSON_RAW, self.dump)
115 host.register_output(C.OUTPUT_DICT, JSON, self.dump_pretty) 112 host.register_output(C.OUTPUT_DICT, C.OUTPUT_NAME_JSON, self.dump_pretty)
116 host.register_output(C.OUTPUT_DICT, JSON_RAW, self.dump) 113 host.register_output(C.OUTPUT_DICT, C.OUTPUT_NAME_JSON_RAW, self.dump)
117 host.register_output(C.OUTPUT_LIST_DICT, JSON, self.dump_pretty) 114 host.register_output(C.OUTPUT_LIST_DICT, C.OUTPUT_NAME_JSON, self.dump_pretty)
118 host.register_output(C.OUTPUT_LIST_DICT, JSON_RAW, self.dump) 115 host.register_output(C.OUTPUT_LIST_DICT, C.OUTPUT_NAME_JSON_RAW, self.dump)
119 host.register_output(C.OUTPUT_DICT_DICT, JSON, self.dump_pretty) 116 host.register_output(C.OUTPUT_DICT_DICT, C.OUTPUT_NAME_JSON, self.dump_pretty)
120 host.register_output(C.OUTPUT_DICT_DICT, JSON_RAW, self.dump) 117 host.register_output(C.OUTPUT_DICT_DICT, C.OUTPUT_NAME_JSON_RAW, self.dump)
121 host.register_output(C.OUTPUT_MESS, JSON, self.dump_pretty) 118 host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_JSON, self.dump_pretty)
122 host.register_output(C.OUTPUT_MESS, JSON_RAW, self.dump) 119 host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_JSON_RAW, self.dump)
123 host.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty) 120 host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_JSON, self.dump_pretty)
124 host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump) 121 host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_JSON_RAW, self.dump)
125 122
126 def dump(self, data): 123 def dump(self, data):
127 self.host.disp(json.dumps(data, default=str)) 124 self.host.disp(json.dumps(data, default=str))
128 125
129 def dump_pretty(self, data): 126 def dump_pretty(self, data):