通过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()
相关推荐
_.Switch39 分钟前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
一个闪现必杀技1 小时前
Python入门--函数
开发语言·python·青少年编程·pycharm
小鹿( ﹡ˆoˆ﹡ )1 小时前
探索IP协议的神秘面纱:Python中的网络通信
python·tcp/ip·php
卷心菜小温2 小时前
【BUG】P-tuningv2微调ChatGLM2-6B时所踩的坑
python·深度学习·语言模型·nlp·bug
陈苏同学2 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
唐家小妹2 小时前
介绍一款开源的 Modern GUI PySide6 / PyQt6的使用
python·pyqt
羊小猪~~3 小时前
深度学习项目----用LSTM模型预测股价(包含LSTM网络简介,代码数据均可下载)
pytorch·python·rnn·深度学习·机器学习·数据分析·lstm
Marst Code3 小时前
(Django)初步使用
后端·python·django
985小水博一枚呀3 小时前
【对于Python爬虫的理解】数据挖掘、信息聚合、价格监控、新闻爬取等,附代码。
爬虫·python·深度学习·数据挖掘
立秋67893 小时前
Python的defaultdict详解
服务器·windows·python