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()

좋은 웹페이지 즐겨찾기