通过python获取svn状态

复制代码
# -*- coding:utf-8 -*-

import subprocess
import xml.dom.minidom

ST_MISSING = "missing"
ST_MODIFIED = "modified"
ST_UNVERSIONED = "unversioned"

cmds = {ST_MISSING :"svn del \"{}\"",ST_UNVERSIONED:"svn add \"{}\""}

def runCmd(command):
    ret = subprocess.run(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,timeout=1)
    return ret

def svnCommit():
    ret = runCmd("svn status  --xml")
    DOMTree = xml.dom.minidom.parseString(ret.stdout)
    collection = DOMTree.documentElement
    es = collection.getElementsByTagName("entry")
    for entry in es:
        statusNode = entry.getElementsByTagName("wc-status")[0]
        filePath = entry.getAttribute("path") 
        status=statusNode.getAttribute("item")
        # print(filePath + " = " + status)
        if status in cmds:
            cmd = cmds[status].format(filePath)
            print(cmd)
            runCmd(cmd)
    runCmd("svn commit -m \"auto commit by python\" ")

svnCommit()
相关推荐
MYX_3096 分钟前
第七章 完整的模型训练
pytorch·python·深度学习·学习
新子y23 分钟前
【小白笔记】岛屿数量
笔记·python
CLubiy28 分钟前
【研究生随笔】Pytorch中的线性代数
pytorch·python·深度学习·线性代数·机器学习
reasonsummer31 分钟前
【办公类-115-02】20251018信息员每周通讯上传之文字稿整理(PDF转docx没有成功)
python·pdf
材料科学研究38 分钟前
深度学习物理神经网络(PINN)!
python·深度学习·神经网络·pinn
兰文彬43 分钟前
Pytorch环境安装指南与建议
人工智能·pytorch·python
哦你看看1 小时前
学习Python 03
开发语言·windows·python
后端小张1 小时前
[AI 学习日记] 深入解析MCP —— 从基础配置到高级应用指南
人工智能·python·ai·开源协议·mcp·智能化转型·通用协议
天青色等烟雨..1 小时前
AI+Python驱动的无人机生态三维建模与碳储/生物量/LULC估算全流程实战技术
人工智能·python·无人机
新子y1 小时前
【小白笔记】岛屿的周长(Island Perimeter)
笔记·python