Changeset 2 in tailor


Ignore:
Timestamp:
06/01/04 16:05:59 (9 years ago)
Author:
lele@…
Hash name:
20040601140559-97f81-b669594864cb35290fbe4848e6645e73057a8caf
Message:

Svn log parser with test

Location:
cvsync
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • cvsync/svn.py

    r1 r2  
    101101 
    102102class SvnLog(SystemCommand): 
    103     COMMAND = "svn log --quiet --revision %(startrev)s:HEAD %(source)s" 
     103    COMMAND = "svn log %(quiet)s %(xml)s --revision %(startrev)s:%(endrev)s %(source)s" 
     104     
     105    def __call__(self, output=None, dry_run=False, **kwargs): 
     106        quiet = kwargs.get('quiet', True) 
     107        if quiet == True: 
     108            kwargs['quiet'] = '--quiet' 
     109        elif quiet == False: 
     110            kwargs['quiet'] = '' 
     111             
     112        xml = kwargs.get('xml', False) 
     113        if xml: 
     114            kwargs['xml'] = '--xml' 
     115            output = True 
     116        else: 
     117            kwargs['xml'] = '' 
     118 
     119        startrev = kwargs.get('startrev') 
     120        if not startrev: 
     121            kwargs['startrev'] = 'BASE' 
     122 
     123        endrev = kwargs.get('endrev') 
     124        if not endrev: 
     125            kwargs['endrev'] = 'HEAD' 
     126 
     127        output = SystemCommand.__call__(self, output=output, 
     128                                        dry_run=dry_run, **kwargs) 
     129 
     130        if xml: 
     131            # parse the output and return the result 
     132            pass 
     133 
     134        return output 
    104135 
    105136 
     
    110141def getHeadRevision(source, baserev): 
    111142    """Using ``svn log`` determine the HEAD revision of a source.""" 
     143 
     144    # XXX: this is, by any means, the worst of all the possible ways 
     145    #      of getting this kind of information from the svn server, 
     146    #      but I did not manage to get any of the others actually work. 
    112147     
    113148    svnlog = SvnLog() 
     
    119154    return head 
    120155 
     156 
    121157class SvnWorkingDir(object): 
    122158    """Represent a SVN working directory.""" 
     
    137173        else: 
    138174            return mayberel 
     175 
     176    def log(self): 
     177        """Return an object representation of the ``svn log`` thru HEAD.""" 
     178 
     179        svnlog = SvnLog(working_dir=self.root) 
     180        out = svnlog(quiet='--verbose', output=True, xml=True, source='.') 
     181 
     182        from xml.sax import parseString 
     183        from xml.sax.handler import ContentHandler 
     184 
     185        class SvnRevisionLogEntry(object): 
     186            def __init__(self): 
     187                self.revision = 0 
     188                self.author = '' 
     189                self.date = '' 
     190                self.msg = '' 
     191                self.paths = [] 
     192 
     193        class SvnXMLLogHandler(ContentHandler): 
     194            def __init__(self): 
     195                self.revisions = [] 
     196                self.current = None 
     197                self.current_field = [] 
     198 
     199            def startElement(self, name, attributes): 
     200                if name == 'logentry': 
     201                    self.current = SvnRevisionLogEntry() 
     202                    self.current.revision = int(attributes['revision']) 
     203                elif name in ['author', 'date', 'msg']: 
     204                    self.current_field = [] 
     205                elif name == 'path': 
     206                    self.current_field = [] 
     207                    if attributes.has_key('copyfrom-path'): 
     208                        self.current_path_action = (attributes['action'], 
     209                                                    attributes['copyfrom-path'], 
     210                                                    attributes['copyfrom-rev']) 
     211                    else: 
     212                        self.current_path_action = attributes['action'] 
     213                         
     214 
     215            def endElement(self, name): 
     216                if name == 'logentry': 
     217                    self.revisions.append(self.current) 
     218                    self.current = None 
     219                elif name in ['author', 'date', 'msg']: 
     220                    setattr(self.current, name, ''.join(self.current_field)) 
     221                elif name == 'path': 
     222                    self.current.paths.append( (''.join(self.current_field), 
     223                                                self.current_path_action) ) 
     224 
     225            def characters(self, data): 
     226                self.current_field.append(data) 
     227 
     228        handler = SvnXMLLogHandler() 
     229        parseString(out.getvalue(), handler) 
     230        return handler.revisions 
    139231         
    140232    def update(self): 
  • cvsync/tests/__init__.py

    r1 r2  
    1111from cvs import * 
    1212from bice import * 
     13from svn import * 
    1314 
    1415SystemCommand.VERBOSE = False 
Note: See TracChangeset for help on using the changeset viewer.