ASCII码关系图
2020-05-04 本文已影响0人
六十三63
契机
最近在梳理k8s描述文件的关系,用excel画图太累了,而且xls的格式虽不能说不通用,但还是有局限性,所以找出来用ascii码画图的想法
用ascii码画关系图产生的结果直接打印在字符界面上,同时也可以重定向到普通的文本文件,兼容性肯定是大于excel的,虽然说能显示的东西不多,但梳理层次和普通的关系还是可以看看的,当然需要读图的人理解
脚本
以下就是我用python写的脚本,其实没有多少东西
需要的参数仅仅是 文件路径和分隔符
#!/usr/bin/python3
#coding=utf-8
import os
import sys
def precheck_argc(argc):
if len(argc) != 3:
print("使用方法 main.py [文件路径] [分隔符{逗号|空格|etc}")
sys.exit(1)
def precheck_path(filepath):
if not os.path.isfile(filepath):
print("该文件["+ filepath + "]不存在,请查询路径")
sys.exit(1)
def xlistget(xlist):
fullname = ""
xheadtail = ""
for ele in xlist:
shapename = "|" + ele + "|"
shapeht = "+" + len(ele) * "-" + "+"
if ele == xlist[-1]:
fullname = fullname + shapename
xheadtail = xheadtail + shapeht
else:
fullname = fullname + shapename + "->"
xheadtail = xheadtail + shapeht + " "
xlinestr = xheadtail + "\n" + fullname + "\n" + xheadtail
return(xlinestr)
if __name__ == '__main__':
argc = sys.argv
precheck_argc(argc)
filepath = sys.argv[1]
precheck_path(filepath)
conline = " |\n v"
listfile = open(filepath,"r")
content = listfile.read()
listfile.close()
requestlist = content.split('\n')
splitsym = sys.argv[2]
for ele in requestlist:
if ele == requestlist[-1]:
xlist = ele.split(splitsym)
shapefull = xlistget(xlist)
print(shapefull)
else:
xlist = ele.split(splitsym)
shapefull = xlistget(xlist) + "\n" + conline
print(shapefull)
输入文件
关系文件如下
可以看到只有两个维度的东西
即y轴是各描述文件的名
x轴是各描述文件对一些其他资源的依赖
你可以自定义自己的分隔符,我这个例子用了逗号
PS C:\Users\rikug\Desktop\workdir\oldschoolart> gc testlist
svc: nginx-test-svc
deploy: nginx-test,configmap: nginxcm,pvc: cephfspvc
configmap: nginxcm,data: rootindex.conf
运行效果
运行效果如下
PS C:\Users\rikug\Desktop\workdir\oldschoolart> python .\simplemakeosa.py testlist ","
+-------------------+
|svc: nginx-test-svc|
+-------------------+
|
v
+------------------+ +------------------+ +--------------+
|deploy: nginx-test|->|configmap: nginxcm|->|pvc: cephfspvc|
+------------------+ +------------------+ +--------------+
|
v
+------------------+ +--------------------+
|configmap: nginxcm|->|data: rootindex.conf|
+------------------+ +--------------------+