Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since there's really no way to <em>programmatically</em> track the progress of rsync, I think your best bet is to "screen scrape" its output and try to "guess" at its progress somehow.</p> <p>The first thing you should do is use <code>subprocess</code> instead of <code>commands.getstatusoutput</code> because you'll get much more control over screen scraping rsync's stdout to track its progress. One solution might be to execute rsync with the <code>-v</code> option, which will print each file transferred followed by a newline (plus some other cruft that you don't really need). A simple way to guess at the progress of rsync then, would be to do something like:</p> <pre><code>import subprocess p = subprocess.Popen(['rsync', '-v', ..other rsync args..], shell=True, stdout=subprocess.PIPE, close_fds=True) while p.stdout.readline(): ... # rsync has just "completed" an operation, i.e. it probably # transferred a file. now would be a good time to update the # ProgressBar. there are some options here, see below... ... ret = p.wait() print "Rsync exited with code %d" % ret </code></pre> <p>This reads the output of <code>rsync -v ...</code> one line at a time, and in the <code>while</code> loop you would update the <code>ProgressBar</code> as appropriate. The question then becomes, what kind of update? <code>ProgressBar</code> really has two modes - one that "pings" back and forth indicating progress towards some indeterminate goal, and one that moves the bar from left to right based on an increment towards a known goal.</p> <p>You could try to "guess" the number of files rsync will transfer by obtaining a file list before hand (with <code>--list-only</code> or <code>-vn</code>) and use that as the goal, but this is inherently error-prone because you run the risk of the sender's file list changing in between the time you gather the list and when you actually execute rsync. A better solution is probably just to call <code>pulse()</code> on the <code>ProgressBar</code> in the <code>while</code> loop to indicate that things are happening in the background. If you want to display more information, you could read the output of <code>p.stdout.readline()</code> and update a <code>gtk.Label</code> somewhere to indicate which files are being transferred.</p> <p>(Note: the code above doesn't take into account error conditions when executing rsync, which you should probably do)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload