Exemple #1
0
def getConfigEncoding(extention):
    """
	获取配置中设置的编码
	"""
    ext = CustomConfig().query("dataSource/encodings/%s" % extention, str)
    if ext == "":
        return CustomConfig().query("dataSource/encodings" % extention, str)
    return ext
Exemple #2
0
def _initEnvironment():
    """
	初始化环境变量
	"""
    sys.path.append(script2sys(Path.executeDirectory()))  # 将程序根目录添加到环境变量
    for root in CustomConfig().syscodeTplRoots:  # 将配置文件所在路径加入环境变量
        sys.path.append(root)
    if CustomConfig().syscodeSrcPluginRoot != "":
        sys.path.append(CustomConfig().syscodeSrcPluginRoot)  # 数据源插件根目录
    if CustomConfig().syscodeDstPluginRoot != "":
        sys.path.append(CustomConfig().syscodeDstPluginRoot)  # 数据导出插件根目录
Exemple #3
0
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)
Exemple #4
0
def printBlockHead(title, lines, width=None, blockChr=None):
	"""
	打印一个区块头
	"""
	if width is None:
		width = CustomConfig().query("custom/blockWidth", int)
	if blockChr is None:
		blockChr = CustomConfig().query("custom/blockSplitter")
	splitter = blockChr * width
	print "# %s" % splitter
	if title is not None:
		print "# %s" % script2sys(title)
		print "# %s" % ('-' * width)
	for line in lines:
		print "# %s" % script2sys(line)
	print "# %s" % splitter
Exemple #5
0
	def dstFile(self):
		"""
		导出文件路径
		"""
		if self.__dstFile is None: return None
		path = os.path.join(CustomConfig().dstRoot, self.__dstFile)
		return Path.normalizePath(path)
Exemple #6
0
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)
Exemple #7
0
class TarsWriter(ExportWriter):
	__escs = {
	'<': "&lt;",
	'>': "&gt;",
	'\t': "&#x09;",
	'\n': "&#x0a;",
	'\r': "&#x0d;",}
	chrs = []
	for ch in __escs:
		chrs.append("(%s)" % ch)
	__reptnESCs = re.compile("|".join(chrs))
	del chrs

	def __init__(self, exportTracer):
		ExportWriter.__init__(self, exportTracer)
		fileName = self.outInfo.dstFile
		path = os.path.split(fileName)[0]
		if not os.path.exists(script2sys(path)):
			raise ExportFixException("errSaveFilePath", path=path)
		try:
			self.__file = open(script2sys(fileName), "w")
		except Exception, err:
			raise ExportFixException("errSaveFileName", file=fileName, msg=sys2script(err.message))
		self.__encoding = self.outInfo.encoding
		self.__nl = CustomConfig().dstNewline
Exemple #8
0
    def query(self, attrName, attrType):
        """
		获取额外属性
		"""
        if attrName not in self.__attrs:
            self.__attrs[attrName] = CustomConfig().query(
                "dataSource/%s" % attrName, attrType)
        return self.__attrs[attrName]
Exemple #9
0
    def query(self, attrName, attrType):
        """
		获取构造函数中传入的额外属性值,如果这些属性值不存在,则会从 outItemInfo 的 query 中取
		"""
        value = self.__extras.get(attrName, self.INNER)
        if value is not self.INNER: return value
        value = CustomConfig().query("explainer/%s" % attrName, attrType)
        self.__extras[attrName] = value
        return value
Exemple #10
0
 def __init__(self, outInfo):
     self.__outInfo = outInfo
     if isinstance(outInfo.dstFile, basestring):
         self.__writer = outInfo.exportWriter
         if outInfo.isWriteHeader:
             self.__writer.writeText(outInfo.header)
             self.__writer.writeText(CustomConfig().dstNewline)
         outInfo.onBeginWriteOut(self.__writer)
     else:
         self.__writer = None
Exemple #11
0
def getSrcFullName(srcFile):
    """
	获取数据源文件全路径
	"""
    for root in CustomConfig().srcRoots:
        fullName = os.path.join(root, srcFile)
        fullName = Path.normalizePath(fullName)
        if os.path.exists(script2sys(fullName)):
            return fullName
    return srcFile
Exemple #12
0
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)
Exemple #13
0
	def __init__(self, dstFile, *outItemInfos, **attrs):
		"""
		dstFile 允许为 None,如果为 None,则只解释表格,不将表格导出到配置文件
		"""
		self.__attrs = attrs
		self.__exportTracer = None										# 导出信息追踪器(实现将导出过程反馈给 UI)
		self.__dstFile = dstFile												# 导出文件(可以传入 None,如果传入 None,将不写出文件)
		self.__outItemInfos = outItemInfos								# 导出字典列表
		self.__encoding = attrs.get("dstEncoding", \
			CustomConfig().query("outInfo/dstEncoding", str))
		self.__isWriteHeader = attrs.get("isWriteHeader", True)			# 写出配置中,是否有注释头
		self.comment = attrs.get("comment", "")							# 导出模块的注释
Exemple #14
0
class PyDictWriter(ExportWriter):
	__typeWriters = {}

	def __init__(self, exportTracer):
		ExportWriter.__init__(self, exportTracer)
		fileName = self.outInfo.dstFile
		try:
			self.__file = open(script2sys(fileName), "w")
		except Exception, err:
			raise ExportFixException("errSaveFileName", file=fileName, msg=sys2script(err.message))
		self.__encoding = self.outInfo.encoding
		self.__nl = CustomConfig().dstNewline
Exemple #15
0
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)
Exemple #16
0
class JsonWriter:
    __typeWriters = {}

    def __init__(self, path, encoding="utf-8"):
        try:
            self.__file = open(script2sys(path), "w")
        except Exception, err:
            raise ExportFixException("errSaveFileName",
                                     file=path,
                                     msg=sys2script(err.message))
        self.__warps = 1
        self.__warp = 0
        self.__encoding = encoding
        self.__nl = CustomConfig().dstNewline
Exemple #17
0
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)
Exemple #18
0
 def run(self):
     writer = self.__writer
     exportTracer = self.__outInfo.exportTracer
     exportTracer.onBeginExportConfig()
     count = len(exportTracer.exportItemTracers)
     for exportItemTracer in exportTracer.exportItemTracers:
         OutItemExporter(exportItemTracer).export(writer)
         count = count - 1
         if count > 0 and writer:
             writer.writeText(CustomConfig().dstNewline)
     if writer:
         self.__outInfo.onWritenOut(writer)
         writer.close()
         self.__outInfo.onWriteClosed()
     exportTracer.onEndExportConfig()
Exemple #19
0
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="-")
Exemple #20
0
def onEndWriteOutItem(writeTracer):
    """
	结束一个数据源的扫描
	"""
    if CustomConfig().query("custom/showProgress", bool):
        Printer.uncapPrinter()
Exemple #21
0
 def __init__(self, key, ecount=0, defValue=ex_base.INNER, **extras):
     dds = extras.get("decimalDigits",
                      CustomConfig().query("explainer/decimalDigits", int))
     ex_onetype_array_col.__init__(self, key, xfloat[dds], ecount, defValue,
                                   **extras)
Exemple #22
0
 def __init__(self, key, defValue=0.0, **extras):
     dds = extras.get("decimalDigits",
                      CustomConfig().query("explainer/decimalDigits", int))
     if type(defValue) is float:
         self.defValue_ = xfloat[dds](defValue)
     ex_value_col_base.__init__(self, key, xfloat[dds], defValue, **extras)
Exemple #23
0
"""
实现一些给导出模板用的规范化类

writen by hyw -- 2014.04.15
"""

import time
import socket
from TableExporter import OrderDict
from config.CustomConfig import CustomConfig
from exporter.OutInfo import OutItemInfo
from exporter.OutInfo import OutInfo
from JsonWriter import JsonWriter
from JsonScanner import JsonScanner

_nl = CustomConfig().dstNewline


# ---------------------------------------------------------------------------------------
# 导出选项,每个选项对应一个导出配置中的数据字典。对应多个 DataSourceInfo
# attrs:
#    isWriteTips: 表示是否要写出导出配置数据源提示
#    warps: 表示导出的配置字典中,前面几层嵌套会换行(最小值为 1)
#           如果不传入,则为 1
#    writers: 传入一组类型写出回调:{类型: 写出函数}
#        写出函数包含三个参数:writeTracer, value, fnStreamWriter
# ---------------------------------------------------------------------------------------
class JsonOutItemInfo(OutItemInfo):
    """
	从数据源中检索数据的导出选项
	"""
Exemple #24
0
def printBlockSplitter():
	"""
	打印区块分割线
	"""
	print "# %s" % (CustomConfig().query("custom/blockWidth", int) * \
		CustomConfig().query("custom/blockSplitter"))