首页 > 编程语言 >python处理pom.xml文件

python处理pom.xml文件

时间:2022-12-05 15:45:04浏览次数:37  
标签:xml http 4.0 python maven pom apache org POM

# coding = utf-8                     
# @author :今夕
# @Time :2022.12.05 10:40
# @file :test.py.py
# @software :PyCharm

import os
import xml.etree.ElementTree as ET

#保留注释信息用
class CommentedTreeBuilder (ET.TreeBuilder):
def comment(self,data):
self.start(ET.Comment,{})
self.data(data)
self.end(ET.Comment)
#获取项目目录
dirs=os.listdir("C:/Disk/gitwork/inaszj/fc-service")
#遍历目录
for dir in dirs:
flag=os.path.isdir("C:/Disk/gitwork/inaszj/fc-service/%s"%dir)
if flag==True:
if dir!='Fc5GcService':#排除不需要的目录
print(dir)
with open("C:/Disk/gitwork/inaszj/fc-service/%s/pom.xml"%dir, 'tr', encoding='utf-8') as rf:
parser = ET.XMLParser(target=CommentedTreeBuilder())
tree = ET.parse(rf, parser=parser)
# tree遍历
for node in tree.findall('.//{http://maven.apache.org/POM/4.0.0}dependency'):
for node in tree.findall('.//{http://maven.apache.org/POM/4.0.0}dependency'):
groupIdNode = node.find('.{http://maven.apache.org/POM/4.0.0}groupId')
artifactNode = node.find('.{http://maven.apache.org/POM/4.0.0}artifactId')
if groupIdNode.text == 'csf':#修改groupid 是csf的依赖版本号
print(groupIdNode.text)
print(artifactNode.text)
node.find('.{http://maven.apache.org/POM/4.0.0}version').text = '3.0'
print(node.find('.{http://maven.apache.org/POM/4.0.0}version').text)
tree.write("C:/Disk/gitwork/inaszj/fc-service/%s/pom.xml"%dir, default_namespace='http://maven.apache.org/POM/4.0.0', encoding='UTF-8')

标签:xml,http,4.0,python,maven,pom,apache,org,POM
From: https://www.cnblogs.com/jinxi7021/p/16952486.html

相关文章

  • python中ImmutableMultiDict嵌套字典的值获取和解决400状态码的问题
    在写接口的过程中遇到了一次请求状态码400原因是用elementupload组件上传照片,后端采用flask的时候用request.form读取上传携带的其他参数,data=request.formtitle=......
  • Ubuntu20.04 编译安装 CPython3.10.8(WSL2)
    CPython,由C编写的python发行版,通过在github下载源代码,通过cmake进行打包安装1.ubuntu安装编译工具:sudoapt-get installlibssl-devzlib1g-devlibbz2-devlibreadl......
  • python-面向对象-类的多态-父类方法重写,继承多态的表现形式
    1.类的多态python面向对象的多态依赖于继承,因为继承,使得子类拥有了父类的方法,子类的方法与父类方法重名时是重写,同一类事物,有多重形态,这就是面向对象概念里的多......
  • python django shell 更新代码后需要重启
    pythondjango 使用pythonmanage.py shell练习时更改代码后,需要重新打开窗口进行练习TRANSLATEwithxEnglishArabicHebrewPolishBulgarianH......
  • Selenium4+Python3系列(十) - Page Object设计模式
    前言​​PageObject(PO)​​​模式,是​​Selenium​​实战中最为流行,并且被自动化测试同学所熟悉和推崇的一种设计模式之一。在设计测试时,把页面元素定位和元素操作方法按照......
  • python + uiautomator2 常用公共方法封装
    前言由于公司UI自动化框架底层用的是Uiautomator2,所以我就用Uiautomator2搭了一套UI自动化框架,思路其实和Appnium一样的。uiautomator2是一个自动化测试开源工具,仅支持an......
  • scrapy3在python2,python3共存下的使用
    因为安装了PYTHON2,PYTHON3,之前的SCRAPY在PYTHON2下是可以的,但在3下运行失败,关联的还是2,原来要在PYTHON3运行的时候,要用全路径:执行scrapy命令(假设......
  • python-容器类型
    容器类型1.通用操作1.1成员运算符(1)语法:数据in容器数据notin容器(2)作用:如果在指定的序列中找到值,返回bool类型。#以字符串str为例,列表l......
  • Python脚本添加参数的几种方法
    之前用python添加参数都是用的input函数,不能添加默认值也不能输入help提示。最近发现了2个更好用的库分享给大家。一、使用input库。这个使用很简单,就不过多描述了。......
  • Python 操作 Excel
    Python操作Excel目录Python操作Excel1安装pandas2pandas中操作Excel的函数2.1loc()2.1.1根据某些条件选择数据2.1.2选择一个行的范围2.1.3根据条件更新列的值......