Source code for uw.parse.rsync

import re
import sys

from .delimited import removeTrailingNewline

sent_line_re = re.compile ('^sent [0-9]+ bytes  received [0-9]+ bytes')
total_line_re = re.compile ('^total size is [0-9]+  speedup is [0-9]+')

[docs]def list_changed_files (lines): """Parse the output of rsync to determine which files were copied. This expects the output of rsync -v, pre-split into lines, and returns a list of the files which were copied. If the output does not match the expected format, ValueError is thrown. """ done = False lines = iter (lines) try: if next(lines) != 'receiving file list ... done': raise ValueError result = [] for line in lines: if line == '': break result.append (line) if not sent_line_re.match (next(lines)): raise ValueError if not total_line_re.match (next(lines)): raise ValueError done = True next(lines) raise ValueError except StopIteration: if done: return result else: raise ValueError