Django Blueprint

2021-01-06 15:04:38 浏览数 (1)

Runtime and Source Code brief analysis

Django DRF runtime call graph use pygraphviz breakpoint - Detail link

Django Call GraphDjango Call Graph

Source code https://github.com/django/django

代码语言:python代码运行次数:0复制
#!/usr/bin/env python
import os, pygraphviz as pyg

COMA = ','
PERIOD = '.'

def _is_none(x):
    if x is None: return True
    if x == []: return True
    if x == ' ': return True

def _is_exclude(path):
    if path == '__pycache__': return True

def _exclude_path(path):
    if _is_exclude(path): return True
    if 'locale' in path: return True

def _not_pyhtml(name):
    # if name[-3:]=='.py' or name[-5:]=='.html': return False
    if name[-3:]=='.py': return False
    return True

def _comb(a,b): return a PERIOD b

class CodeGraph:

    def __init__(self, root_path='./'):
        self.root = root_path
        self.pfiles = [] # parent.path, file_name
        self.pdirectorys = [] # parent.path, directory
        self.loop_all()
        self.draw_graph()

    def loop_all(self):
        for path, dirs, files in os.walk(self.root):
            if _is_none(path): continue
            if _exclude_path(path): continue
            path = path.replace('./','django.').replace('\',PERIOD).replace('/',PERIOD).replace(' ','')
            [self._record_file(path,file) for file in files]
            [self._record_dirs(path,directory) for directory in dirs]
        print('prepared >> .py %d folders %d total %d' % (len(self.pfiles),len(self.pdirectorys),len(self.pfiles self.pdirectorys)))
        # [print(f) for f in self.pdirectorys]
        # [print(f) for f in self.pfiles]

    def draw_graph(self):
        data = self.pfiles   self.pdirectorys
        nodes, edges = [], []
        graph_obj = pyg.AGraph(directed=False, strict=False, ranksep=0.1, splines="spline", concentrate=True)
        for line in data: # .encode(encoding="utf-8")
            [a,b] = line.split(COMA)
            if PERIOD in b: c = b.split(PERIOD)[-2]
            else: c = b
            if not a in nodes: nodes.append(a); graph_obj.add_node(a, label=a,color="#ffffff", fontname="times bold italic")
            if not b in nodes: nodes.append(b); graph_obj.add_node(b, label=c,color="#ffffff", fontname="times bold italic")
            if not [a,b] in edges: edges.append([a,b]); graph_obj.add_edge(a,b)
        print('Start darwing...')
        graph_obj.layout(prog='fdp')
        graph_obj.draw('django_graph.png')
        print('Done')

    def _record_file(self,path,file):
        if _is_none(file): return
        if _is_exclude(file): return
        if _not_pyhtml(file): return
        if path[-1] == PERIOD: path = path[:-1]
        line = path COMA _comb(path,file)
        if line in self.pfiles: return
        self.pfiles.append(line)

    def _record_dirs(self,path,folder):
        if _is_none(folder): return
        if _is_exclude(folder): return
        if path[-1] == PERIOD: path = path[:-1]
        line = path COMA _comb(path,folder)
        if line in self.pdirectorys: return
        self.pdirectorys.append(line)

if __name__=='__main__': CodeGraph()

django_graph.png

Django Source Code Brief Graph ADjango Source Code Brief Graph A
Django Source Code Brief Graph BDjango Source Code Brief Graph B
Django Source Code Brief Graph CDjango Source Code Brief Graph C

Django 3.2源码,.py文件-706,文件夹-182,总共888个节点

【命名】Django 的名字来源于 Django Reinhardt,一个活跃在1930 年到 1950 年代初期的吉普赛吉他工作室,直到今天,他们依然被认为是史上最好的吉他手之一。

聆听他的音乐. 你会喜欢它的.

Django 发音为 JANG,使用 FANG 来押韵,字母 "D "是不发声的.

我们也记录了一段 发音的音频片段.

0 人点赞