|
@@ -6,17 +6,13 @@ import json
|
|
|
# 字典不排序;
|
|
|
from collections import OrderedDict
|
|
|
from xlwt import XFStyle, Pattern
|
|
|
-from UIT_treeConstant import TreeConst
|
|
|
-from UIT_log import info,debug,error
|
|
|
+from xlsConst import xlsConst as xlsc
|
|
|
+from BaseLog import CBaseLog
|
|
|
|
|
|
-INFO =True
|
|
|
-DEBUG =True
|
|
|
-ERROR = True
|
|
|
|
|
|
-class CExcelParser():
|
|
|
- cls = "CExcelParser"
|
|
|
- def __init__(self, xls_path=None,UITree=None):
|
|
|
- self.UITree = UITree
|
|
|
+class CExcelParser(CBaseLog):
|
|
|
+ def __init__(self, xls_path=None, optionExcel=None):
|
|
|
+ self.__optionExcel = optionExcel
|
|
|
if type(xls_path) == str:
|
|
|
xls_path = xls_path.decode('utf-8')
|
|
|
self.xls_path = xls_path
|
|
@@ -37,24 +33,11 @@ class CExcelParser():
|
|
|
for sh_name in wb.sheet_names():
|
|
|
sheet = wb.sheet_by_name(sh_name)
|
|
|
self.parse_excel(sheet, False)
|
|
|
-
|
|
|
- # print "self.valueParams.values:", self.valueParams.values, type(self.valueParams.values)
|
|
|
- # print "self.pathParams.paths:", self.pathParams.paths, type(self.pathParams.paths)
|
|
|
-
|
|
|
- # try:
|
|
|
- # print json.dumps(self.pathParams.paths)
|
|
|
- # print '\r\n'
|
|
|
- # print json.dumps(self.valueParams.values)
|
|
|
- # print '\r\n'
|
|
|
- # # print self.pathParams.paths,'\r\n', self.valueParams.values
|
|
|
- # except Exception, e:
|
|
|
- # print e
|
|
|
-
|
|
|
# endfun
|
|
|
|
|
|
def parse_excel(self, sheet, bpath=True):
|
|
|
pKeys = sheet.row_values(0)
|
|
|
- info(self.cls,"parse_excel","params sheet %s keys: %s"%(sheet.name,str(pKeys)),INFO)
|
|
|
+ self.info(u"params sheet %s keys: %s"%(sheet.name,str(pKeys)))
|
|
|
parentName = None
|
|
|
if u"Value" == sheet.name:
|
|
|
for i in range(1, sheet.nrows):
|
|
@@ -64,20 +47,20 @@ class CExcelParser():
|
|
|
for index in range(oneRow.__len__()):
|
|
|
item = oneRow[index]
|
|
|
rowDict[pKeys[index]] = item
|
|
|
- if rowDict[TreeConst.Value_Name] is None or rowDict[TreeConst.Value_Name].__len__() < 1:
|
|
|
+ if rowDict[xlsc.value_name] is None or rowDict[xlsc.value_name].__len__() < 1:
|
|
|
if parentName is None:
|
|
|
- error(self.cls, "parse_excel", "Level %s error row %s:" % (sheet.name, str(oneRow)), ERROR)
|
|
|
+ self.error(u"Level %s error row %s:" % (sheet.name, str(oneRow)))
|
|
|
break
|
|
|
else:
|
|
|
- rowDict[TreeConst.Value_Name] = parentName
|
|
|
- self.UITree.valueParams.addOption(rowDict)
|
|
|
- elif rowDict[TreeConst.Value_Name].__len__() > 0:
|
|
|
- parentName = rowDict[TreeConst.Value_Name]
|
|
|
- self.UITree.valueParams.addParent(rowDict)
|
|
|
+ rowDict[xlsc.value_name] = parentName
|
|
|
+ self.__optionExcel.valueParams.addOption(rowDict)
|
|
|
+ elif rowDict[xlsc.value_name].__len__() > 0:
|
|
|
+ parentName = rowDict[xlsc.value_name]
|
|
|
+ self.__optionExcel.valueParams.addParent(rowDict)
|
|
|
elif "Dialog" == sheet.name:
|
|
|
- self.parsePath(sheet, pKeys, self.UITree.dialogParams)
|
|
|
+ self.parsePath(sheet, pKeys, self.__optionExcel.dialogParams)
|
|
|
else: # 路径;
|
|
|
- self.parsePath(sheet,pKeys, self.UITree.pathParams)
|
|
|
+ self.parsePath(sheet,pKeys, self.__optionExcel.pathParams)
|
|
|
|
|
|
|
|
|
def parsePath(self, sheet,pKeys, treeParams):
|
|
@@ -89,15 +72,15 @@ class CExcelParser():
|
|
|
for index in range(oneRow.__len__()):
|
|
|
item = oneRow[index]
|
|
|
rowDict[pKeys[index]] = item
|
|
|
- if rowDict[TreeConst.Parent_Name] is None or rowDict[TreeConst.Parent_Name].__len__() < 1:
|
|
|
+ if rowDict[xlsc.parent] is None or rowDict[xlsc.parent].__len__() < 1:
|
|
|
if parentName is None:
|
|
|
- error(self.cls, "parse_excel", "Level %s error row %s:" % (sheet.name, str(oneRow)), ERROR)
|
|
|
+ self.error(u"Level %s error row %s:" % (sheet.name, str(oneRow)))
|
|
|
break
|
|
|
else:
|
|
|
- rowDict[TreeConst.Parent_Name] = parentName
|
|
|
+ rowDict[xlsc.parent] = parentName
|
|
|
treeParams.addOption(sheet.name, rowDict)
|
|
|
- elif rowDict[TreeConst.FLevel_Params[0]].__len__() > 0:
|
|
|
- parentName = rowDict[TreeConst.Parent_Name]
|
|
|
+ elif rowDict[xlsc.FLevel_Params[0]].__len__() > 0:
|
|
|
+ parentName = rowDict[xlsc.parent]
|
|
|
treeParams.addParent(sheet.name, rowDict)
|
|
|
|
|
|
# endfun
|
|
@@ -229,89 +212,4 @@ class CExcelParser():
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- # path = r'E:\svn\SAT\项目资料\第四期-推广使用和画面检测\06-设计文档\01-蓝图设计\UiTree3.0方案\MenuTree_MS6586_EU.xls'
|
|
|
- # path = r'E:\SAT\resource\MenuTree\MS3663\DVB-T2 panasonic\MenuTree.xls'
|
|
|
- # path = r'E:/SAT/resource\MenuTree\MS6586\ATSC\MenuTree.xls'
|
|
|
- path = r'E:\SAT\resource\MenuTree\MS6586\ATSC\MenuTree_DVBT.xls'
|
|
|
- # path = r'E:\MenuTree.xls'
|
|
|
- # path = r'E:\SAT\resource\MenuTree\6586\MS6586_ATSC\MenuTree.xls'
|
|
|
- # path = getMenuTree3SelectedProjectCfgPath() + '\\MenuTree.xls'
|
|
|
- parser = CExcelParser(path)
|
|
|
- parser.read_excel()
|
|
|
- dataDict = parser.get_parent_ocr_dict("network")
|
|
|
- print "dataDict:", dataDict, type(dataDict)
|
|
|
- # parent = "source"
|
|
|
- # option = "atv"
|
|
|
- # parser.getOptionTextList(parent, option)
|
|
|
- # value_name = "source"
|
|
|
- # value = "atv"
|
|
|
- # parser.getValueTextList(value_name, value)
|
|
|
- # SubValueList1 = parser.getSubValueList("source")
|
|
|
- # SubValueList2 = parser.getSubValueList("backlight")
|
|
|
- # parent = "picture"
|
|
|
- # parent = "manual_tuning"
|
|
|
- # parser.getSubOptionList(parent)
|
|
|
- # optionList = []
|
|
|
- # paths = parser.pathParams.paths
|
|
|
- #
|
|
|
- # for level in paths:
|
|
|
- # if paths[level].has_key(parent):
|
|
|
- # optionDictList = paths[level][parent]["value"]
|
|
|
- # for optionDict in optionDictList:
|
|
|
- # optionList.append(optionDict["option"])
|
|
|
- # print "optionList:", optionList, type(optionList)
|
|
|
-
|
|
|
- # print parser.get_value("source", "")
|
|
|
- # checkOptionPathExcelData = parser.getCheckOptionPathExcelData()
|
|
|
- # print "checkOptionPathExcelData:", checkOptionPathExcelData
|
|
|
- # repeatOptionList = parser.getRepeatOptionList()
|
|
|
- # isSaveExcelTrue = parser.saveExcelData(checkOptionPathExcelData, repeatOptionList,
|
|
|
- # r'E:\MenuTree_Check_Option_Result.xls')
|
|
|
- # path = r'E:\SAT\resource\MenuTree\6586\MS6586_ATSC\MenuTree.xls'
|
|
|
- # path = getMenuTree3SelectedProjectCfgPath() + '\\MenuTree.xls'
|
|
|
-
|
|
|
- # print "isSaveExcelTrue:", isSaveExcelTrue
|
|
|
- # valueSheetOptionList = parser.getValueSheetOptionList()
|
|
|
-
|
|
|
- # repeatValueName_ValueSheet = parser.getRepeatValueName_ValueSheet()
|
|
|
- # repeatOption_otherSheet = parser.getRepeatOption_otherSheet()
|
|
|
-
|
|
|
- # optionPath, optionPathResult = parser.checkOptionPath("picture_preset11")
|
|
|
- # print "optionPath:", optionPath, type(optionPath)
|
|
|
- # print "optionPathResult:", optionPathResult, type(optionPathResult)
|
|
|
- # optionPath, optionPathResult = parser.checkOptionPath("instant_power_on")
|
|
|
- # print "optionPath:", optionPath, type(optionPath)
|
|
|
- # print "optionPathResult:", optionPathResult, type(optionPathResult)
|
|
|
-
|
|
|
- # path_params = parser.get_option_paths("picture_preset")
|
|
|
- # print "path_params:", path_params, type(path_params)
|
|
|
-
|
|
|
- # print "path_params[0][0]:",path_params[0][0]
|
|
|
- # print parser.get_option_paths('picture')
|
|
|
- # print parser.get_option('picture')
|
|
|
- # print parser.get_value('backlight',10)
|
|
|
- # print parser.get_parent_ocr_dict('source_hdmi1')
|
|
|
- # print parser.get_parent_ocr_list('channel')
|
|
|
- # print parser.get_parent_ocr_dict('channel')
|
|
|
- # print parser.get_parent_ocr_dict('other_setting')
|
|
|
- # print parser.get_parent_ocr_list('5khz')
|
|
|
- # print parser.get_parent_ocr_dict('picture_preset', True)
|
|
|
- # print parser.get_pair_values('picture_preset', False)
|
|
|
- # print parser.get_pair_values('source')
|
|
|
- # print parser.get_ocr_list('Second','picture','picture_preset')
|
|
|
- # vp, pp = parser.get_menu_paths("auto_volume_control", "off")
|
|
|
- # print vp
|
|
|
- # vp, pp = parser.get_menu_paths("picture_preset", "dynamic")
|
|
|
- # print vp
|
|
|
- # pp = parser.get_option_paths('picture_preset')
|
|
|
- # print pp.__len__(), pp[g_level[0]]
|
|
|
- # print "\r\nvp:", vp, type(vp)
|
|
|
- # print "\r\npp:", pp, type(pp)
|
|
|
- # # print json.dumps(pp)
|
|
|
- # revpp = reversed(pp)
|
|
|
- # for item in revpp:
|
|
|
- # print item, pp[item]
|
|
|
-
|
|
|
- # print 'value:\r\n'
|
|
|
- # print vp
|
|
|
- # # print "revpp:", revpp, type(revpp)
|
|
|
+ pass
|