run SVN commands using python
来源:互联网 发布:淘宝大学网店运营专才 编辑:程序博客网 时间:2024/05/22 03:26
# -*- coding:utf-8 -*-import subprocessimport jsonimport osclass SVNCommands(object): userName = 'username' password = 'password' def __init__(self,dirPath='',fileName='',ciMessage='',svnServerUrl=''): self.__dirPath = dirPath if(len(dirPath.strip())): self.setLocalPath(dirPath) self.__fileName = fileName if(len(fileName.strip())): self.setFileName(fileName) self.__svnUrl = svnServerUrl if(len(svnServerUrl.strip())): self.setSVNUrl(svnServerUrl) self.__svnCmd = '' self.__ciMessage = ciMessage if(len(ciMessage.strip())): self.setCiMessage(ciMessage) self.__outInfo = 'ss' self.__errInfo = 'ss' def setLocalPath(self,path): ''' path: local directory path string ''' path = path.replace('\\','/').strip() if(os.path.isdir(path)): if(path.endswith('/') == False): path = path + '/' self.__dirPath = path else: raise TypeError('It must be a real directory') def getLocalPath(self): return self.__dirPath def setFileName(self,file): ''' file whick you want to up,delete,commite,contains the extension ''' self.__fileName = file.strip() def setSVNUrl(self,url): ''' the url in SVN server ''' self.__svnUrl = url.strip() def setCiMessage(self,msg): if(isinstance(msg,str)): self.__ciMessage = msg.strip() else: raise TypeError('It need string type') def svnCheckout(self): if(len(self.__dirPath) and len(self.__svnUrl)): self.__svnCmd = 'svn checkout ' + self.__svnUrl + ' ' + self.__dirPath + ' --username ' + self.userName + ' --password ' + self.password self.displayCmd() # display self.execCmd() else: raise ValueError('Please check the SVN url and local path') def svnUpdate(self): if(len(self.__dirPath)): self.__svnCmd = 'svn up ' + self.__dirPath self.displayCmd() # display self.execCmd() else: raise ValueError('Please check local path') def svnAdd(self): if(os.path.isfile(self.__dirPath + self.__fileName)): self.__svnCmd = 'svn add '+ self.__dirPath + self.__fileName self.displayCmd() # display self.execCmd() else: raise ValueError('Please check you file') def svnDel(self): if(os.path.isfile(self.__dirPath + self.__fileName)): self.__svnCmd = 'svn delete ' + self.__dirPath + self.__fileName self.displayCmd() # display self.execCmd() else: raise ValueError('Please check you file') def svnCommit(self): if(os.path.isfile(self.__dirPath + self.__fileName)): self.__svnCmd = 'svn ci -m "' + self.__ciMessage + '" ' + self.__dirPath + self.__fileName self.displayCmd() # display self.execCmd() elif(os.path.isdir(self.__dirPath)): self.__svnCmd = 'svn ci -m "' + self.__ciMessage + '" ' + self.__dirPath self.displayCmd() # display self.execCmd() else: raise ValueError('Please check you file') def svnCleanup(self): if(len(self.__dirPath)): self.__svnCmd = 'svn cleanup ' + self.__dirPath self.displayCmd() # display self.execCmd() else: raise ValueError('Please check local path') def execCmd(self): p = subprocess.Popen(self.__svnCmd) try: self.__outInfo,self.__errInfo = p.communicate(timeout = 20) except subprocess.TimeoutExpired: p.kill() self.__outInfo,self.__errInfo = p.communicate() def displayInfo(self): print({'Revision':self.__outInfo,'svnErr':self.__errInfo}) def displayCmd(self): print('Command is '+ self.__svnCmd)if __name__ == '__main__': ''' svn = SVNCommands('d:\\tmp\\svn_test1') svn.setSVNUrl('https://xxxxxxxxx') svn.svnCheckout() ''' #exit() svn = SVNCommands() svn.setLocalPath('d:\\tmp\\svn_test1') svn.setFileName('ab.txt') svn.svnAdd() svn.setCiMessage('+ add this file') svn.svnCommit() #svn.displayInfo() exit()
0 0
- run SVN commands using python
- Using SVN Commands
- svn commands
- 101 useful Run Commands
- Using WinDbg - Advanced commands
- Windows 7 Commands(Run Command)
- python mysql 2014 Commands out of sync; you can't run this command now
- python Commands out of sync; you can't run this command now
- SVN update commands
- Linux SVN commands
- linux svn commands
- Terminal svn commands
- SVN Common commands
- Bash Commands - Arithmetic Tests using (( ... ))
- System commands can run from "cmd"
- System commands can run from "cmd"
- pexpect: run interactive remote ssh commands
- Use vbs to batch run commands
- mysql自增主键在大量删除后如何重新设置避免断层
- Picasso 与Listview 可见时加载 快速滑动时候加载
- 字符串算法之字符串循环左移
- c++第五次上机实验—作业
- 设计模式C++学习笔记之十五(Composite组合模式)
- run SVN commands using python
- linux xargs命令及find命令
- 关于myeclipse8.5闪退问题:
- [一起学Hive]之十-Hive中Join的原理和机制
- c++作业5
- LeetCode: Valid Anagram
- 自制动态语言Medusa的解释器
- 知识普及:彻底弄懂css中单位px和em,rem的区别
- oracle 11g 之LogMiner分析重做日志实践