[Tutor] Calling Python Functions from Powershell scripts

2011-10-05 Thread Nikunj Badjatya
Howdy All,

To give an overview of the problem,
I have an installer. It is used to install virtual machines at specific
location.
The installer is written in Powershell and Python. The topmost script is in
Python ( install.py ) which internally calls other .py and .PS1 ( powershell
) scripts using popen() .
I am working on having a file based logging mechanism for this installer.
i.e both for .py and .PS1 scripts.

Q1. I want to use python logging module. But then how do I integrate it with
powershell scripts. ?
One option would be to write into a .log file using logging module in all
.py scripts. Use that ( .log ) file
in powershell scripts by using its own logging module ( dnt knw if it exists
! )

Q2. Can we call / run  .py from inside .PS1. ?

Please suggest suitable methods for effective logging mechanism.

Thanks

Nikunj
Bangalore
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling Python Functions from Powershell scripts

2011-10-05 Thread bodsda
You can run .py files from powershell, just like you would run any other 
command - 'python myfile.py'

I don't have any experience of the logging modules, but what I do when using 
multiple languages is have them all write to the same plain text log file and 
just prepend [scriptname] to the beginning of each line - that way I can 
track execution order and follow error/info messages all in one file.

That's just how I prefer to do it.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Nikunj Badjatya nikunjbadja...@gmail.com
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Wed, 5 Oct 2011 13:02:23 
To: tutortutor@python.org
Subject: [Tutor]  Calling Python Functions from Powershell scripts

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling Python Functions from Powershell scripts

2011-10-05 Thread Christian Witts

On 2011/10/05 09:32 AM, Nikunj Badjatya wrote:


Howdy All,

To give an overview of the problem,
I have an installer. It is used to install virtual machines at 
specific location.
The installer is written in Powershell and Python. The topmost script 
is in
Python ( install.py ) which internally calls other .py and .PS1 ( 
powershell ) scripts using popen() .
I am working on having a file based logging mechanism for this 
installer. i.e both for .py and .PS1 scripts.


Q1. I want to use python logging module. But then how do I integrate 
it with powershell scripts. ?
One option would be to write into a .log file using logging module in 
all .py scripts. Use that ( .log ) file
in powershell scripts by using its own logging module ( dnt knw if it 
exists ! )


Q2. Can we call / run  .py from inside .PS1. ?

Please suggest suitable methods for effective logging mechanism.

Thanks

Nikunj
Bangalore




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


PowerShell has built-in cmdlets for logging that use the verb write.  
Running the command get-command write* will list those commands for 
you (and a couple of other ones).  Each one is controlled by a shell 
variable that ends with Preference. For example, to turn the warning 
messages up, then set the variable $WarningPreference to Continue. 
Other options are Stop, Inquire, and SilentlyContinue. To turn down 
logging, set each of the $*Preference session variables to 
SilentlyContinue. To turn up logging, then set them all to Continue.


Here are some references for automatic logging [1] and a script template 
with a logging function [2]


[1] http://jdhitsolutions.com/blog/2011/03/powershell-automatic-logging/
[2] http://powershell.com/cs/media/p/3950.aspx

--

Christian Witts
Python Developer

//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor