Changeset 5392


Ignore:
Timestamp:
12/06/09 14:58:21 (10 years ago)
Author:
cbyrom
Message:

Add method to svnClient to remove files - to remove tests to tidy up
the repository of any test files added + fix checkin/checkout problem
due to potential mismatch of SVN clients.

Location:
ndgCommon/trunk/ndg/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/clients/svn/svnclient.py

    r5380 r5392  
    1111    Provides a simple SVN client 
    1212    ''' 
    13     DEFAULT_LOCAL_DIR = '.%sSVN_DATA' %(os.sep) 
     13    # NB, the subdirectory is there for a reason: if we do an extract 
     14    # into a dir which is currently in svn, the top level .svn may conflict 
     15    # with the extracted one - if a version mismatch of system/python svn 
     16    # clients occurs - having the subdir, 'tmp' avoids this problem 
     17    DEFAULT_LOCAL_DIR = '.%sSVN_DATA%stmp' %(os.sep, os.sep) 
    1418    STANDARD_CHECKIN_MESSAGE = "Automatic checkin of files by svnclient" 
     19    STANDARD_SVN_MESSAGE = "Automatic SVN operation by svnclient" 
    1520 
    16     def __init__(self, proxyServer = None, localDir = DEFAULT_LOCAL_DIR): 
    17         ''' 
    18         Constructor for client 
    19         @keyword proxyServer: a string representing a proxy server url to use 
    20         when opening an http request  
    21         ''' 
     21    ''' 
     22    Constructor for client 
     23    @keyword proxyServer: a string representing a proxy server url to use 
     24    when opening an http request 
     25    @keyword localDir: dir to which SVN files are extracted 
     26    @keyword userID: userID to use when authentication is needed 
     27    @keyword pw: password to use when authentication is needed 
     28    ''' 
     29    def __init__(self, proxyServer = None, localDir = DEFAULT_LOCAL_DIR,  
     30                 userID = None, pw = None): 
    2231        logging.debug("Instantiating SVNClient") 
    2332        if proxyServer: 
     
    2736        else: 
    2837            proxyHandler = urllib2.ProxyHandler({}) 
     38 
     39        self.userID = userID 
     40        self.pw = pw 
    2941         
    3042        self.opener = urllib2.build_opener(proxyHandler) 
     
    3244        self.localDir = localDir 
    3345        self.client = pysvn.Client() 
     46 
     47        def login(*args): 
     48            return True, self.userID, self.pw, False 
     49        self.client.callback_get_login = login         
     50 
     51        def get_log_message(): 
     52            return True, self.STANDARD_SVN_MESSAGE 
     53        self.client.callback_get_log_message = get_log_message         
    3454         
    3555        logging.debug("SVNClient instantiated") 
     
    4666        ''' 
    4767        logging.debug("Getting revision numbers for url: %s" %svnURL) 
    48         logs = self.client.log(svnURL) 
     68        logs = self.client.log(svnURL, limit = 0) 
    4969         
    5070        revisions = [] 
    5171        for log in logs: 
    5272            revisions.append(log['revision'].number) 
    53  
     73             
    5474        logging.debug("- found %s revisions" %len(revisions)) 
    5575        return revisions 
     
    7999        logging.debug("- file retrieved successfully - returning this now") 
    80100        return file 
    81          
     101 
     102 
     103    def removeFile(self, svnURL): 
     104        ''' 
     105        Remove the file at the SVN url 
     106        @param svnURL: path to the file to remove in SVN 
     107        @raise pysvn.ClientError: if problems encountered - e.g. removing non-existent file   
     108        @return True, if successful, False otherwise 
     109        ''' 
     110        logging.debug("Removing SVN file at %s" %svnURL) 
     111        tst = self.client.remove(svnURL) 
     112        logging.debug("- file successfully removed") 
     113        return True 
     114     
    82115         
    83116    def checkinFile(self, fileContents, svnURL): 
     
    108141        svnDir = '/'.join(bits[0:-1]) 
    109142        self.client.checkout(svnDir, self.localDir, recurse = False) 
    110         import pdb 
    111         pdb.set_trace() 
    112143             
    113144        # now update the file contents on the file system 
     
    119150        if isNew: 
    120151            logging.debug("Creating new file in SVN") 
    121             #self.client.add(fileName) 
     152            self.client.add(fileName) 
    122153 
    123154        logging.debug("Checking in file, '%s' to SVN" %fileName) 
    124         #self.client.checkin([fileName], self.STANDARD_CHECKIN_MESSAGE) 
     155        self.client.checkin([fileName], self.STANDARD_CHECKIN_MESSAGE) 
    125156 
    126157        return True 
  • ndgCommon/trunk/ndg/common/unittests/clients/svn/testsvnclient.py

    r5380 r5392  
    4141         
    4242         
    43     def testValidCheckinFile(self): 
    44         self.client.checkinFile(tc.TEST_FILE_CONTENTS, tc.VALID_TEMP_FILE) 
     43    # NB, this causes the SVN revision number to be incremented by two each time it is 
     44    # ran - probably not important, but ideally the tests would be ran against their own repository 
     45    # additionally, authentication details are required to allow this update to work  
     46    def OFFtestValidCheckinFile(self): 
     47        self.assertTrue(self.client.checkinFile(tc.TEST_FILE_CONTENTS, tc.VALID_TEMP_FILE)) 
     48        self.assertTrue(self.client.removeFile(tc.VALID_TEMP_FILE)) 
     49         
     50    def testInValidRemoveFile(self): 
     51        self.assertRaises(pysvn.ClientError, self.client.removeFile, tc.VALID_TEMP_FILE) 
    4552         
    4653if __name__=="__main__": 
Note: See TracChangeset for help on using the changeset viewer.