def onEndLoadDataSource(loadTracer): """ 数据源加载结束后调用 """ Printer.uncapPrinter() global _cappedPrint _cappedPrint = None
def _printTplMsg(tplFileName): """ 打印模板信息 """ Printer.printNewline() Printer.printBlockHead( None, [Printer.dtext("theme", "tipsTplFile", file=tplFileName)])
def _initExportTpl(tplFile): """ 初始化导出模板 """ exists = False for root in CustomConfig().tplRoots: fullName = os.path.join(root, tplFile) if os.path.exists(script2sys(fullName)): exists = True break if not exists: Printer.dout("theme", "errTplFileUnxist", tpl=tplFile) engine.exit(1) else: _printTplMsg(fullName) tplFile = os.path.splitext(tplFile)[0] tplFile = tplFile.replace("\\", ".").replace("/", ".") try: tplFile = script2sys(tplFile) tplModule = __import__(tplFile, globals(), locals(), [tplFile]) # 导出模板 return tplModule except BaseException, err: if not _isDebug(): print err.sysMsg else: sys.excepthook(BaseException, err, sys.exc_traceback) messageBox(err.scriptMsg, "ERROR", MB_OK, MB_ICONSTOP)
def onBeginWriteConfigItem(writeTracer): """ 写入配置选项 """ Printer.printNewline() name = writeTracer.owner.outItemInfo.name Printer.dout("export", "tipsWriteOut", name=name) if CustomConfig().query("custom/showProgress", bool): global _cappedPrint _cappedPrint = Printer.capPrinter(False)
def _printAppMsg(): """ 打印程序信息 """ Printer.printBlockHead( Printer.dtext("theme", "tipsProgramInfo"), [ "program: TableExporter.exe", "version: %s" % engine.VERSION, "author : huangyongwei", "date : 2011/09/20", ], )
def onBeginLoadDataSource(loadTracer): """ 开始加载数据源时被调用 """ Printer.dout("theme", "tipsLoadDataSource", src=loadTracer.getSrcText()) if CustomConfig().query("custom/showProgress", bool): global _cappedPrint _cappedPrint = Printer.capPrinter(True) pbarLen = CustomConfig().query("custom/pbarLen", int) _cappedPrint.pbarLen = pbarLen _cappedPrint.pbarChr = CustomConfig().query("custom/pbarChar") _cappedPrint.fmt = Printer.dtext("theme", "tipsLoadDataSourceProgress", pbarLen=pbarLen)
def onBeginScanDataSource(dsrcTracer): """ 开始扫描数据源 """ global _firstScanData if _firstScanData: _firstScanData = False else: Printer.printNewline() srcText = dsrcTracer.dsrc.getSrcText() Printer.dout("export", "tipsScanSrcData", path=srcText) if CustomConfig().query("custom/showProgress", bool): global _cappedPrint _cappedPrint = Printer.capPrinter(False)
def onBeginExportConfigItem(exportItemTracer): """ 开始导出一个配置选项时调用 """ global _firstScanData _firstScanData = True exportTracer = exportItemTracer.owner if len(exportTracer.exportItemTracers) > 1: outItemInfo = exportItemTracer.outItemInfo Printer.printBlockHead( None, [ Printer.dtext( "theme", "tipsBeginExportItem", dname=outItemInfo.name) ], width=CustomConfig().query("custom/blockWidth", int) - 10, blockChr="-")
def onAppExit(exitCode): """ 程序退出时调用 """ if exitCode == 0: Printer.dout("theme", "tipsExportSuccess") else: Printer.printNewline() Printer.dout("theme", "tipsExportFail")
def enter(): """ argv[1] 导出模板路径 """ args = sys.argv[1:] if len(args) < 1 or len(args[0]) == 0: Printer.dout("theme", "errorArgs") engine.exit(1) tplRoot = sys2script(args[0]) # 初始化环境变量 _initEnvironment() # 打印版本信息 _printAppMsg() # 初始化导出模板 tplModule = _initExportTpl(tplRoot) try: exporter.export(tplModule) except BaseException, err: if not _isDebug(): print err.sysMsg else: sys.excepthook(BaseException, err, sys.exc_traceback) messageBox(err.scriptMsg, "ERROR", MB_OK, MB_ICONSTOP) engine.exit(1)
def onEndScanDataSource(dsrcTracer): """ 结束一个数据源的扫描 """ if CustomConfig().query("custom/showProgress", bool): Printer.uncapPrinter() global _cappedPrint _cappedPrint = None # 打印空行(键) if len(dsrcTracer.emptyRows): Printer.printNewline() Printer.dout("export", "warnEmptyRows", rows=dsrcTracer.emptyRows)
def onBeginExportConfig(exportTracer): """ 开始导出一个模板中的其中一个配置 """ # 数据源信息 outInfo = exportTracer.outInfo srcMsgs = [Printer.dtext("export", "tipsSrcData")] for outItemInfo in outInfo.outItemInfos: for text in outItemInfo.dsrcTextList: text = " " + text if text not in srcMsgs: srcMsgs.append(text) # 导出配置信息 dstMsgs = [Printer.dtext("export", "tipsDstFile", file=outInfo.dstFile)] Printer.printNewline() Printer.printBlockHead(Printer.dtext("export", "tipsExporedInfo"), srcMsgs + dstMsgs)
def onInfo(msg): """ 提示信息回调 """ Printer.dmsg("Info: %s" % msg)
def onError(msg): """ 错误信息回调 """ Printer.dmsg("Error: %s" % msg)
def onLocalMsg(key, tag, **attrs): """ 语言配置中信息回调 """ Printer.dout(key, tag, **attrs)
def onEndExportConfigItem(exportItemTracer): """ 结束一个配置的导出 """ # 打印重复键 if len(exportItemTracer.dbKeys): Printer.printNewline() s = "" for key, count in exportItemTracer.dbKeys.iteritems(): s += "[%s(%i)] " % (key, count) Printer.dout("export", "warnDBKey", keys=s) # 打印记录数 Printer.printNewline() Printer.dout("export", "tipsRowCount", count=exportItemTracer.outItemInfo.rowCount) # 记录总数 Printer.dout("export", "tipsEmptyRowCount", count=exportItemTracer.emptyCount) # 空行数(包括空键) Printer.dout("export", "tipsDBRowCount", count=len(exportItemTracer.dbKeys)) # 重复键的行数 Printer.dout("export", "tipsIgnorCount", count=exportItemTracer.ignorCount) # 忽略的行数 Printer.dout("export", "tipsValidCount", count=len(exportItemTracer.datas)) # 有效行数 # 打印导出时间 writeTracer = exportItemTracer.writeTracer Printer.dout("theme", "tipsReadTableWaste", v=exportItemTracer.loadDSrcsTime) # 加载数据耗时 Printer.dout("theme", "tipsExplainWaste", v=exportItemTracer.scanDSrcsTime) # 扫描数据耗时 Printer.dout("theme", "tipsWriteOutWaste", v=exportItemTracer.writeTime) # 写入配置耗时 Printer.dout("theme", "tipsTotalWaste", v=exportItemTracer.wasteTime) # 总耗时 Printer.printNewline()
def onEndWriteOutItem(writeTracer): """ 结束一个数据源的扫描 """ if CustomConfig().query("custom/showProgress", bool): Printer.uncapPrinter()
def onWarning(msg): """ 警告信息回调 """ Printer.dmsg("Warning: %s" % msg)