# -*- coding: cp949 -*- import traceback, os.path, sys # fit a long text string to length def fit_string(input, length, omit_str = u'...'): input_len = len(input) if input_len <= length: return input omit_len = len(omit_str) lpos = (length-omit_len)/2 if (length-omit_len)%2 == 1: lpos += 1 rpos = input_len-lpos+1 return input[:lpos] + omit_str + input[rpos:] # 빡세게 에러 출력 MANIADB_DETAILED_TRACE = False def trace_error(errmsg, err): if MANIADB_DETAILED_TRACE == True: exc_type, exc_obj, exc_tb = sys.exc_info() file_name = os.path.basename(exc_tb.tb_frame.f_code.co_filename) print >> sys.stderr, u'%s %s' % (errmsg, err) print >> sys.stderr, u'' print >> sys.stderr, u'Exception at %s line %d, type %s' % (file_name, exc_tb.tb_lineno, exc_type.__name__) print >> sys.stderr, u'' print >> sys.stderr, u'Call Stack:' for item in traceback.extract_stack(): print >> sys.stderr, u'> File: %s, line: %d, function: %s, code: %s' % (item[0], item[1], item[2], item[3]) else: print >> sys.stderr, u'%s %s' % (errmsg, err) if __name__ == '__main__': print fit_string(u'a'*90, 80)