SVN+HOOK - 구성 관리 갈고리
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys , os
#lockFlag = False
'''
@summary:
'''
class errorCode:
Successed =0000 #
InteralFailed = 0001 #
LogLengthError = 0002 #
DirectoryChangeError = 0003 #
fileTypeError = 0004 #
fileTooLarge = 0005 #
SvnLock = 9999 #SVN
'''
@summary:
'''
class svnChange:
addDirectory = 0001
addFile = 0002
removeDirectory = 0003
removeFile = 0004
modiFile = 0005
normal = 0006
class constValue:
commitLogLength = 10
maxFileLength = 1024*1024*100
lockFlag = False
superUser = ('cshuang','manageruser')
fliterFile = ('ZIP','EXE','TAR','RAR','GZ','RPM')
managerIp = '192.168.4.50'
class userInfo:
def __init__(self,name,aliasName):
self.name=name
self.Alias = aliasName
@staticmethod
def initAllUser():
usrList = list()
return usrList
class svnCommitHook:
'''
classdocs
'''
svnLookPath=r'/usr/local/subversion/bin/svnlook '
svnAdminPath=r''
def __init__(self):
'''
Constructor
'''
self.DeposityLocation = None
self.RTNS = None
self.logerMinLength = 10
self.fileList = list()
'''
@summary: , MIN-LOG-LENGTH
'''
def checkLogsLength (self):
cmd = svnCommitHook.svnLookPath + ' log -t "%s" "%s"'% (self.RTNS, self.DeposityLocation)
logmessage = ''#!/usr/bin/env python
for line in os.popen(cmd,'r').readlines():
logmessage = logmessage + line.replace('
','')
if(len(logmessage) > 10):
return errorCode.Successed
else:
return errorCode.LogLengthError
return errorCode.Successed
def isSpecialFile(self,filename):
if filename == None:
return False
splitStrList = filename.split('.')
if len(splitStrList) < 2:
return False
if splitStrList[-1] in constValue.fliterFile:
return True
return False
def checkChange(self):
cmd1 = svnCommitHook.svnLookPath + ' author -t "%s" "%s"'% (self.RTNS, self.DeposityLocation)
p1 = os.popen(cmd1,'r')
author = p1.read()
author = author.lstrip()
author = author.rstrip()
if author in constValue.superUser:
return errorCode.Successed
cmd2 = svnCommitHook.svnLookPath + ' changed -t "%s" "%s"'% (self.RTNS, self.DeposityLocation)
p2 = os.popen(cmd2,'r')
changeList = list()
for one in p2.readlines():
changeT,filename = self.getChangeType(one)
if changeT == svnChange.addDirectory or changeT == svnChange.removeDirectory:
return errorCode.DirectoryChangeError
if changeT == svnChange.addFile:
strFilename = filename.upper()
if self.isSpecialFile(strFilename):
return errorCode.fileTypeError
#continue
if changeT == svnChange.addFile or changeT == svnChange.modiFile:
cmd1 = svnCommitHook.svnLookPath + ' cat -t %s %s %s' % (self.RTNS, self.DeposityLocation,filename)
pChange = os.popen(cmd1,'r')
result = len(pChange.read())
if result > constValue.maxFileLength:
return errorCode.fileTooLarge
return errorCode.Successed
def packetBlanck(self,src,str = ' '):
rtn = None
if src == None:
return rtn
rtn = src.lstrip()
rtn = rtn.rstrip()
ilen = 0
ilenEx = len(rtn)
while ilen != ilenEx:
ilen = ilenEx
rtn = rtn.replace(str*2 ,str)
ilenEx = len(rtn)
return rtn
'''
@summary: svn
'''
def getChangeType(self,oneChange):
oneChange = self.packetBlanck(oneChange, ' ')
splitStr = oneChange.split(' ')
if len(splitStr) <> 2:
return svnChange.normal,None
#
if splitStr[0] == 'A':
if splitStr[1][-1] == '/' or splitStr[1][-1] == '\\':
return svnChange.addDirectory,splitStr[1]
else :
self.fileList.append(splitStr[1])
return svnChange.addFile,splitStr[1]
#
if splitStr[0] == 'U':
self.fileList.append(splitStr[1])
return svnChange.modiFile,splitStr[1]
#
if splitStr[0] == 'D':
if splitStr[1][-1] == '/' or splitStr[1][-1] == '\\':
return svnChange.removeDirectory,splitStr[1]
else :
return svnChange.removeFile,splitStr[1]
'''
@summary:
'''
def checkFileInfo(self):
return errorCode.Successed
'''
@summary: svn
'''
def lockSvn(self):
#global lockFlag
if constValue.lockFlag:
return errorCode.SvnLock
return errorCode.Successed
def main():
svnHook = svnCommitHook()
svnHook.DeposityLocation = sys.argv[1]
svnHook.RTNS = sys.argv[2]
if svnHook.checkLogsLength() <> errorCode.Successed:
sys.stderr.write(" : , 10 , ")
exit(1)
result = svnHook.checkChange()
if result <> errorCode.Successed:
if result == errorCode.DirectoryChangeError:
sys.stderr.write(" : 、 、 , , , 。 !")
elif result == errorCode.fileTypeError:
sys.stderr.write(" : , !")
elif result == errorCode.fileTooLarge:
sys.stderr.write(" : ---100 !")
exit(1)
if svnHook.lockSvn() <> errorCode.Successed:
sys.stderr.write("SVN : , , 。 !")
exit(1)
'''fileTooLarge
@summary: checkChange
'''
#if svnHook.checkFileInfo() <> errorCode.Successed:
#sys.stderr.write("SVN : , , 。 !")
# exit(1)
exit(0)
if __name__ == '__main__':
main()
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
svn 팁1. SVN 서버 IP 교체 2.특정 버전 가져오기 3.한 버전의 파일을 업데이트합니다. * svn: E155036: Working copy is too old (format 10, created by Subvers...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.