通过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()
相关推荐
唐装鼠6 小时前
Nginx + Gunicorn + Python Web 应用 架构(Claude)
python·nginx·gunicorn
梦想三三6 小时前
【PYthon词频统计与文本向量化】苏宁易购评论分析实战
开发语言·python
biter down7 小时前
9:JSONSchema
python
日晨难再7 小时前
C语言&Python&Bash&Tcl:全局变量和局部变量
c语言·python·bash·tcl
麻雀飞吧7 小时前
期货量化主连和具体合约怎么切:天勤 KQ.m 与 KQ.i 用法
python·区块链
先吃饱再说7 小时前
Python List 切片与 LLM Prompt 设计:从数据结构到接口调用
python
一只专注api接口开发的技术猿7 小时前
OpenClaw 对接淘宝商品 API,低成本实现全天候选品监控|附可运行 Python 实操代码
大数据·开发语言·数据库·python
xingpanvip7 小时前
星盘接口开发文档:马盘次限盘接口指南
android·开发语言·python·php·lua
FBI HackerHarry浩7 小时前
第二阶段Day07【Python生成器、yield关键字、property、正则表达式】
开发语言·python·正则表达式
梦想不只是梦与想7 小时前
Python 中的 4 种作用域
python·作用域