通过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()
相关推荐
YuanDaima204816 分钟前
基于 LangChain 1.0 的检索增强生成(RAG)实战
人工智能·笔记·python·langchain·个人开发·langgraph
RopenYuan1 小时前
FastAPI -API Router的应用
前端·网络·python
听风吹等浪起1 小时前
用Python和Pygame从零实现坦克大战
开发语言·python·pygame
书到用时方恨少!1 小时前
Python Pandas 使用指南:数据分析的瑞士军刀
python·数据分析·pandas
智算菩萨2 小时前
【Pygame】第8章 文字渲染与字体系统(支持中文字体)
开发语言·python·pygame
:mnong2 小时前
全图纸语义理解升级分析
python·openvino·paddleocr·qt6.3·paddleocr-vl
qh0526wy2 小时前
pathlib 核心功能一览
python
Hello eveybody3 小时前
PyCharm性能调优避坑录
python·pycharm
¥-oriented3 小时前
【Python桌面应用开发环境搭建指南】
开发语言·python
Etherious_Young3 小时前
用u2写一个实况足球图像识别自动化脚本(3)
python·自动化·游戏自动化