123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- # -*- coding:utf-8 -*-
- from ssat_sdk.UATree.UAT_data import UATData
- from UAT_tree import UATTree
- from UAT_treeConstant import TreeConst
- from ssat_sdk.utils.string_util import strcmp
- from UAT_log import error,info,debug
- import os, sys, time
- DEBUG = True
- INFO = True
- ERROR = True
- class UATPathManage():
- def __init__(self):
- self.uatData = UATData()
- self.levelList = self.uatData.UATree.treeDict.keys()
- '''
- 构建一条从first parent到目标option路径。
- path最后一个元素,是目标option
- :return result,path. result:-1 代表option异常;0 代表路径中断异常;1 代表路径完整,找到了first parent
- '''
- def getOptionPath(self, option, parent = None):
- path = []
- if option is None and parent is None:
- error(str(self.__class__), "getOptionPath", "getPath Error:Param option is None!!", ERROR)
- return -1, path
- #获取option所在的parent
- elif parent is None:
- parent = self.uatData.getParentByOption(option)
- if parent is None:
- error(str(self.__class__), "getOptionPath",
- "getPath Error:option%s's parent not found!!" % (option[UATTree.TAB_NAME]), ERROR)
- return -1, path
- path.append(option)
- self.addPrevParentPath(parent, path)
- if path.__len__() == 0:
- result = -1
- elif strcmp(path[-1]["level"], "first") is False:
- error(str(self.__class__), "getOptionPath", "getPath Error:option%s path interrupt!!"%(option[UATTree.TAB_NAME]), ERROR)
- result = 0
- else:
- result = 1
- return result, path
- def addPrevParentPath(self, parent, path):
- if parent is None:
- return
- path.append(parent)
- prevParent = parent[UATTree.TAB_PREV_PARENT]
- if prevParent is None:
- return
- else:
- self.addPrevParentPath(prevParent, path)
- def info(self,path):
- for item in path:
- if item is not None:
- info(str(self.__class__), "info", "Path: " + item[UATTree.TAB_NAME], INFO)
- else:
- info(str(self.__class__), "info", "Path: " + str(item), INFO)
- '''
- 构建一条当前parent到option的路径。
- 如果当前电视页面分析,不在UATree中,则构建一条first parent到目标option中的目录。
- :return backPath, forwardPath. backPath是返回路径,forwardPath是去往目标option的路径。
- 注意:backPath路径是顺序执行, forwardPath的路径是要反过来逐步执行。
- backPath格式:[currentOption, currentParent, parent1, parent2, ..., FirstParent]
- forwardPath格式: [targetOption, targetParent, parent1, parent2, ..., FirstParent]
- forwardPath路径为空:表示路径异常。
- forwardPath路径包含option和parent:表示在路径最后一个parent所在页面,或者表示需要从first parent进入
- 1 如果backPath为空,则表示forwardPath从First parent重新进入。
- 2 如果backPath包含option和parent,则表示在backPath的option所在页面,需要返回到forwardPath最后一个parent所在页面。
- backPath返回到forwardPath最后一个parent所在页面:
- 注意:backPath和forwardPath的最后一个parent,一定会一样。
- 1 backPath,返回到最后一个parent页面。
- 2 在backPath最后一个parent页面,即forwardPath最后一个parent页面,再依次递进,进入targetParent页面,选中targetOption。
- '''
- def genOptionSmartPath(self, curParent, option):
- backPath = []
- forwardPath = []
- if curParent is None:
- result,forwardPath = self.getOptionPath(option)
- return backPath,forwardPath
- # print "genOptionSmartPath:curParent:", curParent
- curOptionDict = curParent[UATTree.TAB_OPTION]
- if curOptionDict.__len__() > 0:
- curOption = curOptionDict[curOptionDict.keys()[0]]
- else:
- curOption = None
- resutl1, toFirstPath = self.getOptionPath(curOption, parent=curParent)
- print "toFirstPath:",self.info(toFirstPath)
- resutl2, targetOptionPath = self.getOptionPath(option)
- print "targetOptionPath:",self.info(targetOptionPath)
- if resutl1 < 1 and resutl2 == 1:
- forwardPath = targetOptionPath
- return backPath, forwardPath
- elif resutl1 < 1:
- return backPath, forwardPath
- #levelMin代表parent的个数,所以要去掉option计数
- fLen = toFirstPath.__len__()
- tLen = targetOptionPath.__len__()
- levelMin = min(fLen, tLen) - 1
- for i in range(levelMin): #仅核对parent部分
- print toFirstPath[fLen-1-i][UATTree.TAB_NAME],targetOptionPath[tLen-1-i][UATTree.TAB_NAME]
- #从first parent开始核对,找到第一个不同点
- if toFirstPath[fLen-1-i][UATTree.TAB_NAME] <> targetOptionPath[tLen-1-i][UATTree.TAB_NAME]:
- if i == 0: #first parent不吻合。toFirstPath和targetOptionPath路径没有交点
- print "<> i == 0:", i
- forwardPath = targetOptionPath
- else: #toFirstPath和targetOptionPath路径是相交关系
- print "<> else:", i
- backPath = toFirstPath[0:fLen-i+1] #取到上一个相同的parent。
- forwardPath = targetOptionPath[0:tLen-i+1] # 取到上一个相同的parent。
- break
- if i == levelMin-1:#toFirstPath和targetOptionPath路径是包含关系
- print "i == levelMin:", i
- backPath = toFirstPath[0:fLen-i] # 包含关系,取到当前相同parent
- forwardPath = targetOptionPath[0:tLen-i] #包含关系,取到当前相同parent
- return backPath, forwardPath
- if __name__ == '__main__':
- uatPathManage = UATPathManage()
- parentName = "av_devices_settings"
- curParent = uatPathManage.uatData.getParentDict(parentName)
- print "curParent:", curParent
- option = uatPathManage.uatData.getOption("av_vivid")
- backPath, forwardPath = uatPathManage.genOptionSmartPath(curParent,option)
- print "option:", option
- print "backPath:"
- uatPathManage.info(backPath)
- print "forwardPath:"
- uatPathManage.info(forwardPath)
|