python代码上传测试

#encoding=utf-8
import os,re




def checkline(path, str):
#print(str)


result = res(str)
if result is 1:
fileobj = open(path+"\\codestatistic.html", 'r', encoding='utf-8')
elif result is 2:
fileobj = open(path+"\\complex.html", 'r', encoding='utf-8')
elif result is 3:
fileobj = open(path+"\\ftCoverage.html", 'r', encoding='utf-8')
elif result is 4:
fileobj = open(path+"\\pclint.html", 'r', encoding='utf-8')
else:
fileobj = None
return fileobj
'''
if str == detail:
print(1)
fileobj = open(path, "codestatistic.html", 'r', encoding='utf-8')
elif str == comparison:
print(2)
fileobj = open(path, "complex.html", 'r', encoding='utf-8')
elif str == result:
print(3)
fileobj = open(path, "ftCoverage.html", 'r', encoding='utf-8')
elif str == audit:
print(4)
fileobj = open(path, "ftCoverage.html", 'r', encoding='utf-8')
else:
'''




def readandrewrite(path, filename):
abspath = os.path.join(path, filename)
print(path)
fileobj = open(path + "\\TempletHtml.html", 'r', encoding='utf-8')
lines = fileobj.readlines()
fileobj2 = open(path + "\\temp.html", "w", encoding='utf-8')
for line in lines:
flag = checkline(path, line)
if flag != None:
contents = flag.readlines()
fileobj2.writelines("<div>")
for content in contents:
print("content is" + content)
fileobj2.write(content)
fileobj2.writelines("</div>")
flag.close()
else:
fileobj2.writelines(line)
fileobj2.close()
fileobj.close()
#os.remove(path + "temp.html")
return


def res(str1):
detail = "<div>FailureDetails</div>"
comparison = "<div>ZDBcomparison</div"
result = "<div>CheckScriptResult</div>"
audit = "<div>AuditResult</div>"
pattern = re.compile(detail)
match = pattern.match(str1)
if match:
return 1
pattern = re.compile(comparison)
match = pattern.match(str1)
if match:
return 2
pattern = re.compile(result)
match = pattern.match(str1)
if match:
return 3
pattern = re.compile(audit)
match = pattern.match(str1)
if match:
return 4
return None
'''
if line is "<div>FailureDetails</div>":
fileobj3 = open(path,"codestatistic.html")
contents = fileobj3.readlines()
for content in contents:
fileobj2.writelines(content)
fileobj3.close()
elif line is "<div>ZDBcomparison</div>":
fileobj3 = open(path,"complex.html")
contents = fileobj3.readlines()
for content in contents:
fileobj2.writelines(content)
fileobj3.close()
elif line is "<div>CheckScriptResult</div>":
fileobj3 = open(path,"ftCoverage.html")
contents = fileobj3.readlines()
for content in contents:
fileobj2.writelines(content)
fileobj3.close()
elif line is "<div>AuditResult</div>":
fileobj3 = open(path,"pclint.html")
contents = fileobj3.readlines()
for content in contents:
fileobj2.writelines(content)
fileobj3.close()
else:
fileobj2.writelines(line)
'''




def main():
readandrewrite("E:\\scripts", "TempletHtml.html")




if __name__ == "__main__":
main()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值