def handle_dmaker(dmk_pattern, info, dmk_type, dmk_name, name_sep_sz, id_src=None): msg = '' msg += colorize("\n |_ {:s}: ".format(dmk_pattern), rgb=Color.FMKINFO) msg += colorize(str(dmk_type).ljust(name_sep_sz, ' '), rgb=Color.FMKSUBINFO) if id_src is None: msg += colorize(" | Name: ", rgb=Color.FMKINFO) msg += colorize(str(dmk_name), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) else: msg += colorize(" | ID source: ", rgb=Color.FMKINFO) msg += colorize(str(id_src), rgb=Color.FMKSUBINFO) if info is not None: info = gr.unconvert_from_internal_repr(info) info = info.split('\n') for i in info: chks = chunk_lines(i, page_width - prefix_sz - 10) for idx, c in enumerate(chks): spc = 1 if idx > 0 else 0 msg += '\n' + colorize(' ' * prefix_sz + '| ', rgb=Color.FMKINFO) + \ colorize(' ' * spc + c, rgb=Color.DATAINFO_ALT) return msg
def handle_dmaker(dmk_pattern, info, dmk_type, dmk_name, name_sep_sz, id_src=None): msg = '' msg += colorize("\n |_ {:s}: ".format(dmk_pattern), rgb=Color.FMKINFO) msg += colorize(str(dmk_type).ljust(name_sep_sz, ' '), rgb=Color.FMKSUBINFO) if id_src is None: msg += colorize(" | Name: ", rgb=Color.FMKINFO) msg += colorize(str(dmk_name), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) else: msg += colorize(" | ID source: ", rgb=Color.FMKINFO) msg += colorize(str(id_src), rgb=Color.FMKSUBINFO) if info is not None: if sys.version_info[0] > 2: info = info.decode("latin_1") else: info = str(info) info = info.split('\n') for i in info: chks = chunk_lines(i, page_width - prefix_sz - 10) for idx, c in enumerate(chks): spc = 1 if idx > 0 else 0 msg += '\n' + colorize(' ' * prefix_sz + '| ', rgb=Color.FMKINFO) + \ colorize(' ' * spc + c, rgb=Color.DATAINFO_ALT) return msg
def display_data_info(self, data_id, with_data=False, with_fbk=False, with_fmkinfo=True, fbk_src=None, limit_data_sz=None, page_width=100, colorized=True, raw=False): colorize = self._get_color_function(colorized) data = self.check_data_existence(data_id=data_id, colorized=colorized) if not data: return prt = sys.stdout.write data_id, gr_id, data_type, dm_name, data_content, size, sent_date, ack_date, tg, prj = data[ 0] steps = self.execute_sql_statement( "SELECT * FROM STEPS " "WHERE DATA_ID == {data_id:d} " "ORDER BY STEP_ID ASC;".format(data_id=data_id)) if not steps: print( colorize( "*** BUG with data ID '{:d}' (data should always have at least 1 step) " "***".format(data_id), rgb=Color.ERROR)) return if fbk_src: feedback = self.execute_sql_statement( "SELECT SOURCE, DATE, STATUS, CONTENT FROM FEEDBACK " "WHERE DATA_ID == ? AND SOURCE REGEXP ? " "ORDER BY SOURCE ASC;", params=(data_id, fbk_src)) else: feedback = self.execute_sql_statement( "SELECT SOURCE, DATE, STATUS, CONTENT FROM FEEDBACK " "WHERE DATA_ID == {data_id:d} " "ORDER BY SOURCE" " ASC;".format(data_id=data_id)) comments = self.execute_sql_statement( "SELECT CONTENT, DATE FROM COMMENTS " "WHERE DATA_ID == {data_id:d} " "ORDER BY DATE ASC;".format(data_id=data_id)) fmkinfo = self.execute_sql_statement( "SELECT CONTENT, DATE, ERROR FROM FMKINFO " "WHERE DATA_ID == {data_id:d} " "ORDER BY ERROR DESC;".format(data_id=data_id)) line_pattern = '-' * page_width data_id_pattern = " Data ID #{:d} ".format(data_id) msg = colorize("[".rjust((page_width - 20), '='), rgb=Color.NEWLOGENTRY) msg += colorize(data_id_pattern, rgb=Color.FMKHLIGHT) msg += colorize("]".ljust( page_width - (page_width - 20) - len(data_id_pattern), "="), rgb=Color.NEWLOGENTRY) msg += colorize("\n Project: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(prj), rgb=Color.FMKSUBINFO) msg += colorize(" | Target: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(tg), rgb=Color.FMKSUBINFO) status_prefix = " Status: " msg += colorize('\n' + status_prefix, rgb=Color.FMKINFO) src_max_sz = 0 for idx, fbk in enumerate(feedback): src, tstamp, status, _ = fbk src_sz = len(src) src_max_sz = src_sz if src_sz > src_max_sz else src_max_sz if status is None: continue msg += colorize("{!s}".format(status), rgb=Color.FMKSUBINFO) + \ colorize(" by ", rgb=Color.FMKINFO) + \ colorize("{!s}".format(src), rgb=Color.FMKSUBINFO) if idx < len(feedback) - 1: msg += colorize(",\n".format(src) + ' ' * len(status_prefix), rgb=Color.FMKINFO) msg += '\n' sentd = sent_date.strftime( "%d/%m/%Y - %H:%M:%S") if sent_date else 'None' ackd = ack_date.strftime("%d/%m/%Y - %H:%M:%S") if ack_date else 'None' msg += colorize(" Sent: ", rgb=Color.FMKINFO) + colorize( sentd, rgb=Color.DATE) msg += colorize("\n Received: ", rgb=Color.FMKINFO) + colorize( ackd, rgb=Color.DATE) msg += colorize("\n Size: ", rgb=Color.FMKINFO) + colorize( str(size) + ' Bytes', rgb=Color.FMKSUBINFO) msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) def handle_dmaker(dmk_pattern, info, dmk_type, dmk_name, name_sep_sz, id_src=None): msg = '' msg += colorize("\n |_ {:s}: ".format(dmk_pattern), rgb=Color.FMKINFO) msg += colorize(str(dmk_type).ljust(name_sep_sz, ' '), rgb=Color.FMKSUBINFO) if id_src is None: msg += colorize(" | Name: ", rgb=Color.FMKINFO) msg += colorize(str(dmk_name), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) else: msg += colorize(" | ID source: ", rgb=Color.FMKINFO) msg += colorize(str(id_src), rgb=Color.FMKSUBINFO) if info is not None: info = gr.unconvert_from_internal_repr(info) info = info.split('\n') for i in info: chks = chunk_lines(i, page_width - prefix_sz - 10) for idx, c in enumerate(chks): spc = 1 if idx > 0 else 0 msg += '\n' + colorize(' ' * prefix_sz + '| ', rgb=Color.FMKINFO) + \ colorize(' ' * spc + c, rgb=Color.DATAINFO_ALT) return msg msg = '' first_pass = True prefix_sz = 7 name_sep_sz = len(data_type) for _, _, dmk_type, _, _, _, _ in steps: dmk_type_sz = 0 if dmk_type is None else len(dmk_type) name_sep_sz = dmk_type_sz if dmk_type_sz > name_sep_sz else name_sep_sz sid = 1 for _, step_id, dmk_type, dmk_name, id_src, ui, info in steps: if first_pass: if dmk_type is None: assert (id_src is not None) continue else: first_pass = False msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) if dmk_type != data_type: msg += colorize("\n |_ Generator: ", rgb=Color.FMKINFO) msg += colorize(str(data_type), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) sid += 1 msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, len(data_type)) else: msg += handle_dmaker('Generator', info, dmk_type, dmk_name, name_sep_sz, id_src=id_src) else: msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, name_sep_sz) sid += 1 msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, com in enumerate(comments, start=1): content, tstamp = com date_str = tstamp.strftime( "%d/%m/%Y - %H:%M:%S") if tstamp else 'None' msg += colorize("\n Comment #{:d}: ".format(idx), rgb=Color.FMKINFOGROUP) + \ colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width - 10) for c in chks: msg += '\n' + colorize(' ' * 2 + '| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if comments: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, info in enumerate(fmkinfo, start=1): content, tstamp, error = info if not with_fmkinfo and not error: continue date_str = tstamp.strftime( "%d/%m/%Y - %H:%M:%S") if tstamp else 'None' if error: msg += colorize("\n FMK Error: ", rgb=Color.ERROR) else: msg += colorize("\n FMK Info: ", rgb=Color.FMKINFOGROUP) msg += colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width - 10) for c in chks: color = Color.FMKHLIGHT if error else Color.DATAINFO_ALT msg += '\n' + colorize(' ' * 2 + '| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=color) if msg: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' if with_data: msg += colorize("\n Sent Data:\n", rgb=Color.FMKINFOGROUP) data_content = gr.unconvert_from_internal_repr(data_content) data_content = self._handle_binary_content(data_content, sz_limit=limit_data_sz, raw=raw, colorized=colorized) msg += data_content msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) if with_fbk: for src, tstamp, status, content in feedback: formatted_ts = None if tstamp is None else tstamp.strftime( "%d/%m/%Y - %H:%M:%S") msg += colorize("\n Status(", rgb=Color.FMKINFOGROUP) msg += colorize("{!s}".format(src), rgb=Color.FMKSUBINFO) msg += colorize(" | ", rgb=Color.FMKINFOGROUP) msg += colorize("{!s}".format(formatted_ts), rgb=Color.FMKSUBINFO) msg += colorize(")", rgb=Color.FMKINFOGROUP) msg += colorize(" = {!s}".format(status), rgb=Color.FMKSUBINFO) if content: content = gr.unconvert_from_internal_repr(content) content = self._handle_binary_content( content, sz_limit=limit_data_sz, raw=raw, colorized=colorized) chks = chunk_lines(content, page_width - 4) for c in chks: c_sz = len(c) for i in range(c_sz): c = c[:-1] if c[-1] == '\n' else c break msg += colorize('\n' + ' ' * 2 + '| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if feedback: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg + '\n')
def display_data_info(self, data_id, with_data=False, with_fbk=False, with_fmkinfo=True, fbk_src=None, limit_data_sz=None, page_width=100, colorized=True, raw=False): colorize = self._get_color_function(colorized) data = self.check_data_existence(data_id=data_id, colorized=colorized) if not data: return prt = sys.stdout.write data_id, gr_id, data_type, dm_name, data_content, size, sent_date, ack_date, tg, prj = data[0] steps = self.execute_sql_statement( "SELECT * FROM STEPS " "WHERE DATA_ID == {data_id:d} " "ORDER BY STEP_ID ASC;".format(data_id=data_id) ) if not steps: print(colorize("*** BUG with data ID '{:d}' (data should always have at least 1 step) " "***".format(data_id), rgb=Color.ERROR)) return if fbk_src: feedback = self.execute_sql_statement( "SELECT SOURCE, DATE, STATUS, CONTENT FROM FEEDBACK " "WHERE DATA_ID == ? AND SOURCE REGEXP ? " "ORDER BY SOURCE ASC;", params=(data_id, fbk_src) ) else: feedback = self.execute_sql_statement( "SELECT SOURCE, DATE, STATUS, CONTENT FROM FEEDBACK " "WHERE DATA_ID == {data_id:d} " "ORDER BY SOURCE" " ASC;".format(data_id=data_id) ) comments = self.execute_sql_statement( "SELECT CONTENT, DATE FROM COMMENTS " "WHERE DATA_ID == {data_id:d} " "ORDER BY DATE ASC;".format(data_id=data_id) ) fmkinfo = self.execute_sql_statement( "SELECT CONTENT, DATE, ERROR FROM FMKINFO " "WHERE DATA_ID == {data_id:d} " "ORDER BY ERROR DESC;".format(data_id=data_id) ) line_pattern = '-' * page_width data_id_pattern = " Data ID #{:d} ".format(data_id) msg = colorize("[".rjust((page_width - 20), '='), rgb=Color.NEWLOGENTRY) msg += colorize(data_id_pattern, rgb=Color.FMKHLIGHT) msg += colorize("]".ljust(page_width - (page_width - 20) - len(data_id_pattern), "="), rgb=Color.NEWLOGENTRY) msg += colorize("\n Project: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(prj), rgb=Color.FMKSUBINFO) msg += colorize(" | Target: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(tg), rgb=Color.FMKSUBINFO) status_prefix = " Status: " msg += colorize('\n' + status_prefix, rgb=Color.FMKINFO) src_max_sz = 0 for idx, fbk in enumerate(feedback): src, tstamp, status, _ = fbk src_sz = len(src) src_max_sz = src_sz if src_sz > src_max_sz else src_max_sz if status is None: continue msg += colorize("{!s}".format(status), rgb=Color.FMKSUBINFO) + \ colorize(" by ", rgb=Color.FMKINFO) + \ colorize("{!s}".format(src), rgb=Color.FMKSUBINFO) if idx < len(feedback) - 1: msg += colorize(",\n".format(src) + ' '*len(status_prefix), rgb=Color.FMKINFO) msg += '\n' sentd = sent_date.strftime("%d/%m/%Y - %H:%M:%S") if sent_date else 'None' ackd = ack_date.strftime("%d/%m/%Y - %H:%M:%S") if ack_date else 'None' msg += colorize(" Sent: ", rgb=Color.FMKINFO) + colorize(sentd, rgb=Color.DATE) msg += colorize("\n Received: ", rgb=Color.FMKINFO) + colorize(ackd, rgb=Color.DATE) msg += colorize("\n Size: ", rgb=Color.FMKINFO) + colorize(str(size) + ' Bytes', rgb=Color.FMKSUBINFO) msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) def handle_dmaker(dmk_pattern, info, dmk_type, dmk_name, name_sep_sz, id_src=None): msg = '' msg += colorize("\n |_ {:s}: ".format(dmk_pattern), rgb=Color.FMKINFO) msg += colorize(str(dmk_type).ljust(name_sep_sz, ' '), rgb=Color.FMKSUBINFO) if id_src is None: msg += colorize(" | Name: ", rgb=Color.FMKINFO) msg += colorize(str(dmk_name), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) else: msg += colorize(" | ID source: ", rgb=Color.FMKINFO) msg += colorize(str(id_src), rgb=Color.FMKSUBINFO) if info is not None: info = gr.unconvert_from_internal_repr(info) info = info.split('\n') for i in info: chks = chunk_lines(i, page_width - prefix_sz - 10) for idx, c in enumerate(chks): spc = 1 if idx > 0 else 0 msg += '\n' + colorize(' ' * prefix_sz + '| ', rgb=Color.FMKINFO) + \ colorize(' ' * spc + c, rgb=Color.DATAINFO_ALT) return msg msg = '' first_pass = True prefix_sz = 7 name_sep_sz = len(data_type) for _, _, dmk_type, _, _, _, _ in steps: dmk_type_sz = 0 if dmk_type is None else len(dmk_type) name_sep_sz = dmk_type_sz if dmk_type_sz > name_sep_sz else name_sep_sz sid = 1 for _, step_id, dmk_type, dmk_name, id_src, ui, info in steps: if first_pass: if dmk_type is None: assert (id_src is not None) continue else: first_pass = False msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) if dmk_type != data_type: msg += colorize("\n |_ Generator: ", rgb=Color.FMKINFO) msg += colorize(str(data_type), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) sid += 1 msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, len(data_type)) else: msg += handle_dmaker('Generator', info, dmk_type, dmk_name, name_sep_sz, id_src=id_src) else: msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, name_sep_sz) sid += 1 msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, com in enumerate(comments, start=1): content, tstamp = com date_str = tstamp.strftime("%d/%m/%Y - %H:%M:%S") if tstamp else 'None' msg += colorize("\n Comment #{:d}: ".format(idx), rgb=Color.FMKINFOGROUP) + \ colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width - 10) for c in chks: msg += '\n' + colorize(' ' * 2 + '| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if comments: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, info in enumerate(fmkinfo, start=1): content, tstamp, error = info if not with_fmkinfo and not error: continue date_str = tstamp.strftime("%d/%m/%Y - %H:%M:%S") if tstamp else 'None' if error: msg += colorize("\n FMK Error: ", rgb=Color.ERROR) else: msg += colorize("\n FMK Info: ", rgb=Color.FMKINFOGROUP) msg += colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width - 10) for c in chks: color = Color.FMKHLIGHT if error else Color.DATAINFO_ALT msg += '\n' + colorize(' ' * 2 + '| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=color) if msg: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' if with_data: msg += colorize("\n Sent Data:\n", rgb=Color.FMKINFOGROUP) data_content = gr.unconvert_from_internal_repr(data_content) data_content = self._handle_binary_content(data_content, sz_limit=limit_data_sz, raw=raw, colorized=colorized) msg += data_content msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) if with_fbk: for src, tstamp, status, content in feedback: formatted_ts = None if tstamp is None else tstamp.strftime("%d/%m/%Y - %H:%M:%S") msg += colorize("\n Status(", rgb=Color.FMKINFOGROUP) msg += colorize("{!s}".format(src), rgb=Color.FMKSUBINFO) msg += colorize(" | ", rgb=Color.FMKINFOGROUP) msg += colorize("{!s}".format(formatted_ts), rgb=Color.FMKSUBINFO) msg += colorize(")", rgb=Color.FMKINFOGROUP) msg += colorize(" = {!s}".format(status), rgb=Color.FMKSUBINFO) if content: content = gr.unconvert_from_internal_repr(content) content = self._handle_binary_content(content, sz_limit=limit_data_sz, raw=raw, colorized=colorized) chks = chunk_lines(content, page_width - 4) for c in chks: c_sz = len(c) for i in range(c_sz): c = c[:-1] if c[-1] == '\n' else c break msg += colorize('\n' + ' ' * 2 + '| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if feedback: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg + '\n')
def display_data_info(fmkdb, data_id, with_data, with_fbk, without_fmkinfo, limit_data_sz=600): data = handle_data_existence(data_id=data_id) prt = sys.stdout.write data_id, gr_id, data_type, dm_name, data_content, size, sent_date, ack_date, tg, prj = data[ 0] steps = fmkdb.execute_sql_statement( "SELECT * FROM STEPS " "WHERE DATA_ID == {data_id:d} " "ORDER BY STEP_ID ASC;".format(data_id=data_id)) if not steps: print( colorize("*** BUG (data should always have at least 1 step) ***", rgb=Color.ERROR)) sys.exit(-1) feedback = fmkdb.execute_sql_statement( "SELECT SOURCE, STATUS, CONTENT FROM FEEDBACK " "WHERE DATA_ID == {data_id:d} " "ORDER BY SOURCE ASC;".format(data_id=data_id)) comments = fmkdb.execute_sql_statement( "SELECT CONTENT, DATE FROM COMMENTS " "WHERE DATA_ID == {data_id:d} " "ORDER BY DATE ASC;".format(data_id=data_id)) fmkinfo = fmkdb.execute_sql_statement( "SELECT CONTENT, DATE, ERROR FROM FMKINFO " "WHERE DATA_ID == {data_id:d} " "ORDER BY ERROR DESC;".format(data_id=data_id)) line_pattern = '-' * page_width data_id_pattern = " Data ID #{:d} ".format(data_id) msg = colorize("[".rjust((page_width - 20), '='), rgb=Color.NEWLOGENTRY) msg += colorize(data_id_pattern, rgb=Color.FMKHLIGHT) msg += colorize("]".ljust( page_width - (page_width - 20) - len(data_id_pattern), "="), rgb=Color.NEWLOGENTRY) msg += colorize("\n Project: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(prj), rgb=Color.FMKSUBINFO) msg += colorize(" | Target: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(tg), rgb=Color.FMKSUBINFO) msg += colorize("\n Status: ", rgb=Color.FMKINFO) src_max_sz = 0 for idx, fbk in enumerate(feedback): src, status, _ = fbk src_sz = len(src) src_max_sz = src_sz if src_sz > src_max_sz else src_max_sz if status is None: continue msg += colorize("{!s}".format(status), rgb=Color.FMKSUBINFO) + \ colorize(" by ", rgb=Color.FMKINFO) + \ colorize("{!s}".format(src), rgb=Color.FMKSUBINFO) if idx < len(feedback) - 1: msg += colorize(", ".format(src), rgb=Color.FMKINFO) msg += '\n' sentd = sent_date.strftime("%d/%m/%Y - %H:%M:%S") ackd = 'None' if ack_date is None else ack_date.strftime( "%d/%m/%Y - %H:%M:%S") msg += colorize(" Sent: ", rgb=Color.FMKINFO) + colorize( sentd, rgb=Color.DATE) msg += colorize("\n Received: ", rgb=Color.FMKINFO) + colorize( ackd, rgb=Color.DATE) msg += colorize("\n Size: ", rgb=Color.FMKINFO) + colorize( str(size) + ' Bytes', rgb=Color.FMKSUBINFO) msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) def handle_dmaker(dmk_pattern, info, dmk_type, dmk_name, name_sep_sz, id_src=None): msg = '' msg += colorize("\n |_ {:s}: ".format(dmk_pattern), rgb=Color.FMKINFO) msg += colorize(str(dmk_type).ljust(name_sep_sz, ' '), rgb=Color.FMKSUBINFO) if id_src is None: msg += colorize(" | Name: ", rgb=Color.FMKINFO) msg += colorize(str(dmk_name), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) else: msg += colorize(" | ID source: ", rgb=Color.FMKINFO) msg += colorize(str(id_src), rgb=Color.FMKSUBINFO) if info is not None: if sys.version_info[0] > 2: info = info.decode("latin_1") else: info = str(info) info = info.split('\n') for i in info: chks = chunk_lines(i, page_width - prefix_sz - 10) for idx, c in enumerate(chks): spc = 1 if idx > 0 else 0 msg += '\n' + colorize(' '*prefix_sz+'| ', rgb=Color.FMKINFO) + \ colorize(' '*spc+c, rgb=Color.DATAINFO_ALT) return msg msg = '' first_pass = True prefix_sz = 7 name_sep_sz = len(data_type) for _, _, dmk_type, _, _, _, _ in steps: dmk_type_sz = 0 if dmk_type is None else len(dmk_type) name_sep_sz = dmk_type_sz if dmk_type_sz > name_sep_sz else name_sep_sz sid = 1 for _, step_id, dmk_type, dmk_name, id_src, ui, info in steps: if first_pass: if dmk_type is None: assert (id_src is not None) continue else: first_pass = False msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) if dmk_type != data_type: msg += colorize("\n |_ Generator: ", rgb=Color.FMKINFO) msg += colorize(str(data_type), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) sid += 1 msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, len(data_type)) else: msg += handle_dmaker('Generator', info, dmk_type, dmk_name, name_sep_sz, id_src=id_src) else: msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, name_sep_sz) sid += 1 msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, com in enumerate(comments, start=1): content, date = com date_str = sent_date.strftime("%d/%m/%Y - %H:%M:%S") msg += colorize("\n Comment #{:d}: ".format(idx), rgb=Color.FMKINFOGROUP) + \ colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width - 10) for c in chks: msg += '\n' + colorize(' '*2+'| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if comments: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, info in enumerate(fmkinfo, start=1): content, date, error = info if without_fmkinfo and not error: continue date_str = sent_date.strftime("%d/%m/%Y - %H:%M:%S") if error: msg += colorize("\n FMK Error: ", rgb=Color.ERROR) else: msg += colorize("\n FMK Info: ", rgb=Color.FMKINFOGROUP) msg += colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width - 10) for c in chks: color = Color.FMKHLIGHT if error else Color.DATAINFO_ALT msg += '\n' + colorize(' '*2+'| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=color) if msg: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' if with_data: msg += colorize("\n Sent Data:\n", rgb=Color.FMKINFOGROUP) if sys.version_info[0] > 2: data_content = data_content.decode("latin_1") data_content = "{!a}".format(data_content) else: data_content = repr(str(data_content)) if len(data_content) > limit_data_sz: data_content = data_content[:limit_data_sz] data_content = data_content data_content += colorize(' ...', rgb=Color.FMKHLIGHT) else: data_content = data_content msg += data_content msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) if with_fbk: for src, status, content in feedback: msg += colorize("\n Status(", rgb=Color.FMKINFOGROUP) + \ colorize("{:s}".format(src), rgb=Color.FMKSUBINFO) + \ colorize(")", rgb=Color.FMKINFOGROUP) + \ colorize(" = {!s}".format(status), rgb=Color.FMKSUBINFO) if content: if sys.version_info[0] > 2: content = content.decode("latin_1") else: content = str(content) chks = chunk_lines(content, page_width - 4) for c in chks: c_sz = len(c) for i in range(c_sz): c = c[:-1] if c[-1] == '\n' else c break msg += colorize('\n'+' '*2+'| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if feedback: msg += colorize('\n' + line_pattern, rgb=Color.NEWLOGENTRY) prt(msg + '\n')
def display_data_info(fmkdb, data_id, with_data, with_fbk, without_fmkinfo, limit_data_sz=600): data = handle_data_existence(data_id=data_id) prt = sys.stdout.write data_id, gr_id, data_type, dm_name, data_content, size, sent_date, ack_date, tg, prj = data[0] steps = fmkdb.execute_sql_statement( "SELECT * FROM STEPS " "WHERE DATA_ID == {data_id:d} " "ORDER BY STEP_ID ASC;".format(data_id=data_id) ) if not steps: print(colorize("*** BUG (data should always have at least 1 step) ***", rgb=Color.ERROR)) sys.exit(-1) feedback = fmkdb.execute_sql_statement( "SELECT SOURCE, STATUS, CONTENT FROM FEEDBACK " "WHERE DATA_ID == {data_id:d} " "ORDER BY SOURCE ASC;".format(data_id=data_id) ) comments = fmkdb.execute_sql_statement( "SELECT CONTENT, DATE FROM COMMENTS " "WHERE DATA_ID == {data_id:d} " "ORDER BY DATE ASC;".format(data_id=data_id) ) fmkinfo = fmkdb.execute_sql_statement( "SELECT CONTENT, DATE, ERROR FROM FMKINFO " "WHERE DATA_ID == {data_id:d} " "ORDER BY ERROR DESC;".format(data_id=data_id) ) line_pattern = '-'*page_width data_id_pattern = " Data ID #{:d} ".format(data_id) msg = colorize("[".rjust((page_width-20), '='), rgb=Color.NEWLOGENTRY) msg += colorize(data_id_pattern, rgb=Color.FMKHLIGHT) msg += colorize("]".ljust(page_width-(page_width-20)-len(data_id_pattern),"="), rgb=Color.NEWLOGENTRY) msg += colorize("\n Project: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(prj), rgb=Color.FMKSUBINFO) msg += colorize(" | Target: ", rgb=Color.FMKINFO) msg += colorize("{:s}".format(tg), rgb=Color.FMKSUBINFO) msg += colorize("\n Status: ", rgb=Color.FMKINFO) src_max_sz = 0 for idx, fbk in enumerate(feedback): src, status, _ = fbk src_sz = len(src) src_max_sz = src_sz if src_sz > src_max_sz else src_max_sz if status is None: continue msg += colorize("{!s}".format(status), rgb=Color.FMKSUBINFO) + \ colorize(" by ", rgb=Color.FMKINFO) + \ colorize("{!s}".format(src), rgb=Color.FMKSUBINFO) if idx < len(feedback)-1: msg += colorize(", ".format(src), rgb=Color.FMKINFO) msg += '\n' sentd = sent_date.strftime("%d/%m/%Y - %H:%M:%S") ackd = 'None' if ack_date is None else ack_date.strftime("%d/%m/%Y - %H:%M:%S") msg += colorize(" Sent: ", rgb=Color.FMKINFO) + colorize(sentd, rgb=Color.DATE) msg += colorize("\n Received: ", rgb=Color.FMKINFO) + colorize(ackd, rgb=Color.DATE) msg += colorize("\n Size: ", rgb=Color.FMKINFO) + colorize(str(size)+' Bytes', rgb=Color.FMKSUBINFO) msg += colorize('\n'+line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) def handle_dmaker(dmk_pattern, info, dmk_type, dmk_name, name_sep_sz, id_src=None): msg = '' msg += colorize("\n |_ {:s}: ".format(dmk_pattern), rgb=Color.FMKINFO) msg += colorize(str(dmk_type).ljust(name_sep_sz, ' '), rgb=Color.FMKSUBINFO) if id_src is None: msg += colorize(" | Name: ", rgb=Color.FMKINFO) msg += colorize(str(dmk_name), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) else: msg += colorize(" | ID source: ", rgb=Color.FMKINFO) msg += colorize(str(id_src), rgb=Color.FMKSUBINFO) if info is not None: if sys.version_info[0] > 2: info = info.decode("latin_1") else: info = str(info) info = info.split('\n') for i in info: chks = chunk_lines(i, page_width-prefix_sz-10) for idx, c in enumerate(chks): spc = 1 if idx > 0 else 0 msg += '\n' + colorize(' '*prefix_sz+'| ', rgb=Color.FMKINFO) + \ colorize(' '*spc+c, rgb=Color.DATAINFO_ALT) return msg msg = '' first_pass = True prefix_sz = 7 name_sep_sz = len(data_type) for _, _, dmk_type, _, _, _, _ in steps: dmk_type_sz = 0 if dmk_type is None else len(dmk_type) name_sep_sz = dmk_type_sz if dmk_type_sz > name_sep_sz else name_sep_sz sid = 1 for _, step_id, dmk_type, dmk_name, id_src, ui, info in steps: if first_pass: if dmk_type is None: assert(id_src is not None) continue else: first_pass = False msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) if dmk_type != data_type: msg += colorize("\n |_ Generator: ", rgb=Color.FMKINFO) msg += colorize(str(data_type), rgb=Color.FMKSUBINFO) msg += colorize(" | UI: ", rgb=Color.FMKINFO) msg += colorize(str(ui), rgb=Color.FMKSUBINFO) sid += 1 msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, len(data_type)) else: msg += handle_dmaker('Generator', info, dmk_type, dmk_name, name_sep_sz, id_src=id_src) else: msg += colorize("\n Step #{:d}:".format(sid), rgb=Color.FMKINFOGROUP) msg += handle_dmaker('Disruptor', info, dmk_type, dmk_name, name_sep_sz) sid += 1 msg += colorize('\n'+line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, com in enumerate(comments, start=1): content, date = com date_str = sent_date.strftime("%d/%m/%Y - %H:%M:%S") msg += colorize("\n Comment #{:d}: ".format(idx), rgb=Color.FMKINFOGROUP) + \ colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width-10) for c in chks: msg += '\n' + colorize(' '*2+'| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if comments: msg += colorize('\n'+line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' for idx, info in enumerate(fmkinfo, start=1): content, date, error = info if without_fmkinfo and not error: continue date_str = sent_date.strftime("%d/%m/%Y - %H:%M:%S") if error: msg += colorize("\n FMK Error: ", rgb=Color.ERROR) else: msg += colorize("\n FMK Info: ", rgb=Color.FMKINFOGROUP) msg += colorize(date_str, rgb=Color.DATE) chks = chunk_lines(content, page_width-10) for c in chks: color = Color.FMKHLIGHT if error else Color.DATAINFO_ALT msg += '\n' + colorize(' '*2+'| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=color) if msg: msg += colorize('\n'+line_pattern, rgb=Color.NEWLOGENTRY) prt(msg) msg = '' if with_data: msg += colorize("\n Sent Data:\n", rgb=Color.FMKINFOGROUP) if sys.version_info[0] > 2: data_content = data_content.decode("latin_1") data_content = "{!a}".format(data_content) else: data_content = repr(str(data_content)) if len(data_content) > limit_data_sz: data_content = data_content[:limit_data_sz] data_content = data_content data_content += colorize(' ...', rgb=Color.FMKHLIGHT) else: data_content = data_content msg += data_content msg += colorize('\n'+line_pattern, rgb=Color.NEWLOGENTRY) if with_fbk: for src, status, content in feedback: msg += colorize("\n Status(", rgb=Color.FMKINFOGROUP) + \ colorize("{:s}".format(src), rgb=Color.FMKSUBINFO) + \ colorize(")", rgb=Color.FMKINFOGROUP) + \ colorize(" = {!s}".format(status), rgb=Color.FMKSUBINFO) if content: if sys.version_info[0] > 2: content = content.decode("latin_1") else: content = str(content) chks = chunk_lines(content, page_width-4) for c in chks: c_sz = len(c) for i in range(c_sz): c = c[:-1] if c[-1] == '\n' else c break msg += colorize('\n'+' '*2+'| ', rgb=Color.FMKINFOGROUP) + \ colorize(str(c), rgb=Color.DATAINFO_ALT) if feedback: msg += colorize('\n'+line_pattern, rgb=Color.NEWLOGENTRY) prt(msg+'\n')