樹狀顯示dts設備樹文件之間的包含關係(設備樹樹狀圖顯示)(圖形化顯示設備樹)

效果

dts

使用步驟

$ cd <dts所在目錄> //切換路徑
$ cp DeviceTreeMap.py <dts所在目錄> //路徑切換後,把py腳本也複製到該目錄
$ python DeviceTreeMap.py xxxx.dts //執行py腳本,並把xxx.dts文件名作爲參數傳進去

注意:
.dts是所有.dtsi的根,想要看項目中完整的設備樹結構,必須要傳入.dts
如果只是想查看部分樹狀結構,則需傳入對應的.dtsi即可

下載地址:https://github.com/daoshuti/dst_store/blob/master/python/DeviceTreeMap.py

源碼

#!/usr/bin/env python
# -*- coding=utf8 -*-
"""
# Author: wanghan
# Created Time : Sun 07 Jan 2018 06:27:32 PM CST
# File Name: DeviceTreeMap.py
# Description: Get Devices Tree Map
"""

import sys
import os

class DeviceTreeMap(object):
    def __init__(self, name, parent = None, level = 0):
        self.name = name
        self.level = level
        self.parent = parent
        self.child = []

    def printChild(self):
        n = 0
        if not self.level == 0:
            if self.level > 1:
                while self.level > n:
                    if len(self.parent.parent.child) > self.parent.parent.child.index(self.parent)+1:
                        if self.level != n+1 :
                            print "|",
                    else:
                        if self.level != n+1 :
                            print " ",
                    n = n + 1
            print "L " + self.name
        else:
            print self.name
        n = 0
        while len(self.child) > n:
            self.child[n].printChild()
            n = n + 1

    def printMap(self):
        print ""
        print "-----------------------------------"
        print ""
        self.printChild()

    def createTreeMap(self, childLevel = 1):
        theChild = None
        for line in open(self.name):
            if line.startswith("#include"):
                dtsiName = line.split()[1].strip('\"')
                theChild = DeviceTreeMap(dtsiName, self, childLevel)
                if not dtsiName.endswith(".h>"):
                    self.child.append(theChild)
                    theChild.createTreeMap(childLevel+1)

if __name__ == '__main__':
    argv = sys.argv[1:]
    if len(argv) <= 0:
        print "Input dts file, please."
        exit(1);
    rootDeviceTree = DeviceTreeMap(argv[0])
    rootDeviceTree.createTreeMap()
    rootDeviceTree.printMap()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章