コード例 #1
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)
コード例 #2
0
	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))
コード例 #3
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
コード例 #4
0
 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))
コード例 #5
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
コード例 #6
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)  # 数据导出插件根目录
コード例 #7
0
def dmsg(*msgs):
	"""
	打印字符串后换行
	msg 必须与 python 编码一致
	"""
	msg = ", ".join([str(m) for m in msgs])
	msg = script2sys(msg)
	if ProgressRecord.running:
		_msg_cache.append(msg)
	else:
		print msg
コード例 #8
0
    def close(self, save=False):
        """
		关闭 excel 程序
		"""
        if save:
            for fileName, wbook in self.__wbooks.iteritems():
                try:
                    wbook.save(script2sys(fileName))
                except Exception, err:
                    raise ExcelFixException("errSave",
                                            file=fileName,
                                            msg=err.message)
コード例 #9
0
def catmsg(*msgs):
	"""
	打印字符串后不换行
	msg 必须与 python 编码一致
	"""
	msg = ", ".join([str(m) for m in msgs])
	msg = script2sys(msg)
	if ProgressRecord.running:
		if len(_msg_cache) and type(_msg_cache[-1]) is list:
			_msg_cache[-1].append(msg)
		else:
			_msg_cache.append([msg])
	else:
		print msg,
コード例 #10
0
    def getSheet(self, fileName, encoding):
        """
		获取一个 CSV 表格
		fileName 的编码必须与本程序脚本使用的编码一致
		"""
        fileName = Path.normalizePath(fileName)
        sysFileName = script2sys(fileName)
        if fileName in self.__sheets:
            return self.__sheets[fileName]
        if not os.path.exists(sysFileName):
            raise CSVFixException("errUnexist", file=fileName)
        try:
            file = open(sysFileName, "rb")
        except Exception, err:
            raise DataSourceException(sys2script(err.__str__()))
コード例 #11
0
    def getWorkbook(self, fileName, encoding):
        """
		获取 Excel 工作簿
		Excel 文件不存在,或者 Excel 在操作中,则引起 ExcelComException
		fileName 的编码必须与本程序脚本使用的编码一致
		"""
        fileName = Path.normalizePath(fileName)
        if fileName in self.__wbooks:
            return self.__wbooks[fileName]
        sysFileName = script2sys(fileName)
        sysFileName = Path.normalizePath(sysFileName)
        if not os.path.exists(sysFileName):
            raise ExcelFixException("errUnexist", file=fileName)
        try:
            wbook = xlrd.open_workbook(sysFileName)
            self.__wbooks[fileName] = wbook
            return wbook
        except xlrd.XLRDError, err:
            raise ExcelFixException("errUnexist", file=fileName)
コード例 #12
0
def dynImport(mname):  # 动态加载一个模块
    from libs import SmartImport
    return SmartImport.dynImport(script2sys(mname))
コード例 #13
0
 def syscodeDstPluginRoot(self):
     root = self.__cfgSect["paths"].readString("dstPluginRoot")
     return script2sys(Path.realToExecutePath(root))
コード例 #14
0
def _dsystext(_key, _name, **args):
	"""
	提取语言配置中的文本,并转换为系统编码
	"""
	return script2sys(Local().formatLocalText(_key, _name, **args))
コード例 #15
0
			def __call__(self, msg):							# msg 编码必须与 python 脚本编码一致
				cx = ProgressRecord.cx
				cy = ProgressRecord.cy
				Console.inst().setCursorPos(cx, cy)
				print fmt % script2sys(msg)
コード例 #16
0
 def syscodeDstRoot(self):
     return script2sys(dstRoot)
コード例 #17
0
 def syscodeTplRoots(self):
     roots = []
     for root in self.tplRoots:
         roots.append(script2sys(root))
     return roots
コード例 #18
0
    def syscodeSrcPluginRoot(self):
        """
		数据源插件(相对可执行文件的路径)
		"""
        root = self.__cfgSect["paths"].readString("srcPluginRoot")
        return script2sys(Path.realToExecutePath(root))