<s> import re <EOL> import logging <EOL> import subprocess <EOL> from dateutil . parser import parse as parse_date <EOL> from dateutil . tz import tzutc <EOL> from xml . etree import ElementTree as ET <EOL> from django_vcs_watch . utils import strip_timezone , guess_encoding , DiffProcessor <EOL> from django_vcs_watch . settings import REVISION_LIMIT <EOL> def get_updates ( url , last_rev , username = None , password = None ) : <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> command = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if last_rev : <EOL> command += [ '<STR_LIT>' , '<STR_LIT>' % last_rev ] <EOL> command += [ '<STR_LIT>' , '<STR_LIT:%s>' % REVISION_LIMIT ] <EOL> if username : <EOL> command += [ '<STR_LIT>' , username ] <EOL> if password : <EOL> command += [ '<STR_LIT>' , password ] <EOL> command += [ '<STR_LIT>' , url ] <EOL> log . debug ( re . sub ( r"<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:U+0020>' . join ( command ) ) ) <EOL> svn = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> xml , stderr = svn . communicate ( ) <EOL> if svn . returncode != <NUM_LIT:0> or stderr or not xml : <EOL> log . error ( '<STR_LIT>' % ( svn . returncode , stderr ) ) <EOL> raise Exception ( '<STR_LIT:U+0020>' . join ( stderr . splitlines ( ) ) ) <EOL> xml_e = ET . fromstring ( xml ) <EOL> commits = [ ] <EOL> diff_processor = DiffProcessor ( ) <EOL> for entry_e in xml_e . findall ( '<STR_LIT>' ) : <EOL> revision = entry_e . attrib [ '<STR_LIT>' ] <EOL> if revision == last_rev : <EOL> continue <EOL> author = entry_e . find ( '<STR_LIT>' ) . text <EOL> msg = entry_e . find ( '<STR_LIT>' ) . text <EOL> date = parse_date ( entry_e . find ( '<STR_LIT:date>' ) . text ) . astimezone ( tzutc ( ) ) <EOL> command = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:-c>' , str ( revision ) , url ] <EOL> log . debug ( '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( command ) ) <EOL> svn = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> diff , stderr = svn . communicate ( ) <EOL> commits . insert ( <NUM_LIT:0> , dict ( <EOL> revision = revision , <EOL> changes = diff_processor . process ( guess_encoding ( diff ) ) , <EOL> message = msg or u'<STR_LIT>' , <EOL> date = strip_timezone ( date ) , <EOL> author = author <EOL> ) <EOL> ) <EOL> return commits </s>
