Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jfeilbach/c9653c41d7089af88b414e41574a98cb to your computer and use it in GitHub Desktop.
Save jfeilbach/c9653c41d7089af88b414e41574a98cb to your computer and use it in GitHub Desktop.
rsync
rsync -P -avz user@host:/onefolder otherfolder/ | python $basename.py
import progressbar
import sys
def read_stdin():
line = ''
while sys.stdin:
try:
c = sys.stdin.read(1)
except IOError as e:
print e
continue
if c == '\r':
# line is being updated
yield line
line = ''
elif c == '\n':
# line is done
yield line
line = ''
elif c == '':
break
else:
line += c
first_update = None
widgets = [progressbar.Percentage(), None, progressbar.Bar(), progressbar.ETA(), None]
pbar = None
for line in read_stdin():
parts = line.split()
if len(parts) == 6 and parts[1].endswith('%') and parts[-1].startswith('to-check='):
# file progress -P
file_progress = parts[1]
file_speed = parts[2]
file_eta = parts[3]
istr, ntotalstr = parts[-1][len('to-check='):-1].split('/')
ntotal = int(ntotalstr)
i = int(istr)
j = ntotal - i
total_progress = j * 100. / int(ntotal)
widgets[1] = '|%s/%s' % (i, ntotal)
widgets[-1] = '|File:%s|%s|%s|%s' % (file_progress, short_file_name, file_eta, file_speed.rjust(10))
if pbar is None:
first_update = j
pbar = progressbar.ProgressBar(widgets=widgets,
maxval=ntotal - first_update).start()
pbar.maxval = ntotal - first_update
pbar.update(j - first_update)
#sys.stderr.write('Total:%.1f%%|File:%s|%s|%s|%s|\r' % (total_progress, file_progress,
# short_file_name, file_eta, file_speed))
#sys.stderr.flush()
elif not line.startswith(' '):
# total progress
file_name = line
if len(parts) == 6: print parts[1].endswith('%'), parts[-1].startswith('to-check='),
if len(file_name) > 40:
short_file_name = file_name[:12] + '...' + file_name[-(28-3):]
else:
short_file_name = file_name
pbar.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment