我正在尝试使用下面的 pom.xml 创建一个 Python 脚本并验证 pom 是否存在任何语法错误,lxml以进一步确认<version>是 aSNAPSHOT并更新<version>以匹配此格式ci_{git hub org}_{branch name}-SNAPSHOT。project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wsi.devops</groupId> <artifactId>python-test</artifactId> <version>1.0-SNAPSHOT</version></project>这是我目前使用我的解决方案的地方,# For XML validation, importing the etree module from the lxml # package, as well as sys for handling input.from lxml import etreeimport sys#filename as command line argumentsfilename_xml = sys.argv[1]# parse xmltry: doc = etree.parse(sys.argv[1]) print('XML well formed, syntax ok.')# check for XML syntax errorsexcept etree.XMLSyntaxError as err: print('XML Syntax Error, see error_syntax.log') with open('error_syntax.log', 'w') as error_log_file: error_log_file.write(str(err.error_log)) quit()except: print('Unknown error, exiting.') quit()#Update versionfrom xml.etree import ElementTree as ettree = et.parse(sys.argv[1])tree.find('1.0').text = 'ci_{git hub org name}_{branch name}'tree.write(sys.argv[1])只是想为我在脚本中犯的任何错误获得一些帮助。
添加回答
举报
0/150
提交
取消