log:
背景
通过扫描项目工程,自动匹配部分内容,完成测试
思路
- 获取项目根目录
- 通过os.walk获取 文件路径、文件夹、文件
- 匹配继续遍历
- 通过macet.grout()获取需要的内容
# !/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Author : yyq
import os
import re
def path():
return os.path.dirname(os.path.abspath(__file__))
def readUrl():
global serviceUrl, versionUrl
f = open(path() + '/.service.yml', 'r')
for i in f:
service = re.match('\sname:\s(.*)', str(i))
version = re.match('\sapiVersion:\s"(.*)"', str(i))
if service:
serviceUrl = service.group(1)
if version:
versionUrl = version.group(1)
f.close()
return str(serviceUrl + '/' + versionUrl)
def readJava():
allData = []
import os
files = path()
for root, dirs, file in os.walk(files):
for fil in file:
javaFile = re.match('(.*?)java$', str(fil))
if javaFile:
aa = str(root) + '/' + str(javaFile.group())
f = open(aa, 'r')
allData.append(interfaceUrl(f))
f.close()
allData = sum(allData, [])
return allData
def interfaceUrl(dataFile):
data = []
aa = {}
for filedata in dataFile:
macet = re.search('@(.*)Mapping\("(.*)"\)$', str(filedata))
if macet:
a = macet.group(1)
b = macet.group(2)
a = str(a) + str(len(filedata))
aa[a] = b
if aa:
reqk = [k for k in aa.keys()][0]
reqv = [v for v in aa.values()][0]
reqk_count = len([k for k in aa.keys()])
if 'Request' in reqk and reqk_count>1:
aa.pop(reqk)
for k, v in aa.items():
data.append(readUrl() + reqv + v)
elif 'Request' in reqk and reqk_count == 1:
aa.pop(reqk)
data.append(readUrl() + reqv)
else:
for k, v in aa.items():
data.append(readUrl() + v)
else:
pass
return data
print("sacnStart:", readJava(), "scanEnd")