[Tutor] Progress Bar

Rance Hall ranceh at gmail.com
Tue Nov 8 17:28:01 CET 2011

On Tue, Nov 8, 2011 at 9:42 AM, Nikunj Badjatya
<nikunjbadjatya at gmail.com> wrote:
> Hi All,
> I am writing an installer in Python and Powershell which will be used to
> install Virtual Machines at specific locations.
> The main script is in Python and main.py inturn calls Powershell scripts
> (.PS1).
> It is complete console based and no gui.
> I am using Python 2.7
> I was thinking to have a progress bar in my installer. similar to the way
> when we install something in linux via console and a progress bar comes as
> "[#####                 ] 40% "
> etc.
> I also saw and ran couple of examples based in Python on the net.
> http://code.google.com/p/python-progressbar/source/browse/examples.py
> My question is, How do I integrate it with Powershell scripts.?
> I am using popen() to run powershell scripts.

The easiest way to do this is manually advance your progress bar with
each powershell script completion.

for example if there are four *ps1 scripts, then completing each
represents an additional 25% completion.

popen(ps script 1)
advance progress meter to 25%
popen(ps script 2)
advance progress meter to 50%

to get anything more sophisticated you have to have the powershell
scripts report something back to the main python script but I don't
have a feel for how easy/hard that would be.  I doubt that the popen
call allows much more than waiting for the called script to exit.

You could have the power shell scripts keep track of their own
progress with a log file or some such and then a thread in your python
installer could watch those log files and manually advance your
progress meter based on log file entries.



More information about the Tutor mailing list