通过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()
相关推荐
a0023450016 分钟前
python类型转换&深浅拷贝
开发语言·python
星石传说13 分钟前
python绘制年平均海表温度、盐度、ph分布图
python·生信·环境数据·分布图
丁总学Java37 分钟前
Cannot deserialize instance of java.lang.String out of START_ARRAY token
java·windows·python
魔道不误砍柴功3 小时前
Java中的Stream API:从入门到实战
java·windows·python
xinghuitunan4 小时前
时间转换(acwing)c/c++/java/python
java·c语言·c++·python
tekin4 小时前
Python 高级数据结构操作全解析:从理论到实践
数据结构·python·集合set·高级数据结构·集合操作·队列操作·堆操作
关关钧4 小时前
【R语言】绘图
开发语言·python·r语言
m0_748248025 小时前
爬虫自动化(DrissionPage)
爬虫·python·自动化
量化投资技术5 小时前
【量化科普】Arbitrage,套利
python·量化交易·量化·量化投资·qmt·miniqmt
量化投资技术5 小时前
【量化科普】Liquidity,流动性
python·量化交易·量化·量化投资·qmt·miniqmt