Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

suggesting a launcher wrapper script for portable python

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


gelonida at gmail

Aug 11, 2012, 5:49 PM

Post #1 of 5 (183 views)
Permalink
suggesting a launcher wrapper script for portable python

I just started looking at portable Python and was rather surprised, that
I didn't find any recommended method in the documentation of how to
launch scripts with portable python.
Creating py2exe scripts on ones own USB drive seems to be kind of overkill.

So here my own thoughts / suggestsions.
I'm interestted in feedback of how others use portable pythons
and how they run their scripts from a USB stick.


Let's assume I install portable python on my USB drive and then I'd like
to store self written python scripts on this drive.

It would of course be greate if I could just click on the script and
they'd be started.


However under windows this would not be the case.
The python script would either not be started at all or if the PC had
his own python installed, then the script would be started with the PC's
version of python.

Thus a tiny wrapper script would be needed.


Suggestion:
--------------
The current directory structore for portable python (2.7) is (assuming
that %PP% is the base directory)

%PP%/Python-Portable.exe # launches the python interactive shell
%PP%/PyScripter-Portable.exe # launches some IDE
%PP%/App

Let's assume I add two more directories:
%PP%/myscripts # location of all callable scripts
%PP%/launchers # location with icons one can click on
# to start the scripts in myscripts




if I wrote a script named %PP%/myscripts/test1.py,
and I created an aproprriate named %PP%/launchers/test1.bat

then I could just click on test1.bat and the Python script test1.py
would be started. If the wrapper script is written properly, then it can
look at its own base name and call the related python script.

If I dragged and dropped some filenames on the bat file, then they would
be passed to sys.argv of the script.

Running the script from command line would also work and the present
working directory would be preserved (which might be useful in some cases)

If the script name would not be .py, but .pyw then it woudl be started
with pythonw.
T

Below suggested script:



@echo off
REM
=========================================================================
REM script to start a python file with portable python
REM
=========================================================================

REM basepath of this .bat file
set basepath=%~dp0

REM create the name of the python file related to this bat file
REM Unfortunately I do not know how to normalyze %pyfile%,
REM so we got stuck with the '..'
set pyfile=%basepath%..\myscripts\%~n0.py

If EXIST "%pyfile%" (
REM a normal console python file with .py suffix
"%basepath%\..\App\python.exe" "%pyfile%" %*
) ELSE (
If EXIST "%pyfile%w" (
REM a non console python file with .pyw suffix
start "" "%basepath%\..\App\pythonw.exe" "%pyfile%w" %*
) ELSE (
REM found neither a .py nor a .pyw file
echo found no python file %pyfile%
)
)
REM
=========================================================================
REM end of script
REM
=========================================================================


One minor drawback of my suggested script would be, that a console
window pops up for a few seconds when starting a .pyw file.

This could be avoided by using either a small compiled C-file (which
sounds like overkill though)
or by writing a windows scripting host .wsf file.
However I don't know this well enough to replicate my batch file.
AN article on SO mentions how to write such a script.
However it does not parse command line arguments nor does it
automatically determine the scripts file name.
So any help for creating a .wsf file starting a .pyw file with command
line arguments would be appreciated.



An alternativce approach could be to provide a scipt named
mk_wrapper.bat
If one drags and drops a python script on it, then an apropriate wrapper
file would be created in the launcher directory.

If well done, then this could be implemented such, that the script may
be located in an arbitrary location on the same USB drive.



I think it would be great if the official portable python release
contained some upport for launching scripts.
Perhaps it exists alrady and I just didn't find it?

If not,then I wouldn't mind if my script or a similiar sand a related
README.txt cript were added to the official release








--
http://mail.python.org/mailman/listinfo/python-list


t at jollybox

Aug 12, 2012, 12:05 PM

Post #2 of 5 (175 views)
Permalink
Re: suggesting a launcher wrapper script for portable python [In reply to]

On 08/12/2012 02:49 AM, Gelonida N wrote:
>
> One minor drawback of my suggested script would be, that a console
> window pops up for a few seconds when starting a .pyw file.

(I'm no expert but) This should be avoidable if you use the Windows
Script Host instead of DOS command scripts to write the launchers.
I.e. use JScript or VBScript to do exactly the same thing. I don't know
much about Windows shortcut (*.lnk) files; if they can contain relative
paths, you could just create shortcuts that launch portable python with
the script.

Thomas


--
http://mail.python.org/mailman/listinfo/python-list


breamoreboy at yahoo

Aug 12, 2012, 12:52 PM

Post #3 of 5 (175 views)
Permalink
Re: suggesting a launcher wrapper script for portable python [In reply to]

On 12/08/2012 01:49, Gelonida N wrote:
> I just started looking at portable Python and was rather surprised, that
> I didn't find any recommended method in the documentation of how to
> launch scripts with portable python.
> Creating py2exe scripts on ones own USB drive seems to be kind of overkill.
>
> So here my own thoughts / suggestsions.
> I'm interestted in feedback of how others use portable pythons
> and how they run their scripts from a USB stick.
>
>
> Let's assume I install portable python on my USB drive and then I'd like
> to store self written python scripts on this drive.
>
> It would of course be greate if I could just click on the script and
> they'd be started.
>
>
> However under windows this would not be the case.
> The python script would either not be started at all or if the PC had
> his own python installed, then the script would be started with the PC's
> version of python.
>
> Thus a tiny wrapper script would be needed.
>
>
> Suggestion:
> --------------
> The current directory structore for portable python (2.7) is (assuming
> that %PP% is the base directory)
>
> %PP%/Python-Portable.exe # launches the python interactive shell
> %PP%/PyScripter-Portable.exe # launches some IDE
> %PP%/App
>
> Let's assume I add two more directories:
> %PP%/myscripts # location of all callable scripts
> %PP%/launchers # location with icons one can click on
> # to start the scripts in myscripts
>
>
>
>
> if I wrote a script named %PP%/myscripts/test1.py,
> and I created an aproprriate named %PP%/launchers/test1.bat
>
> then I could just click on test1.bat and the Python script test1.py
> would be started. If the wrapper script is written properly, then it can
> look at its own base name and call the related python script.
>
> If I dragged and dropped some filenames on the bat file, then they would
> be passed to sys.argv of the script.
>
> Running the script from command line would also work and the present
> working directory would be preserved (which might be useful in some cases)
>
> If the script name would not be .py, but .pyw then it woudl be started
> with pythonw.
> T
>
> Below suggested script:
>
>
>
> @echo off
> REM
> =========================================================================
> REM script to start a python file with portable python
> REM
> =========================================================================
>
> REM basepath of this .bat file
> set basepath=%~dp0
>
> REM create the name of the python file related to this bat file
> REM Unfortunately I do not know how to normalyze %pyfile%,
> REM so we got stuck with the '..'
> set pyfile=%basepath%..\myscripts\%~n0.py
>
> If EXIST "%pyfile%" (
> REM a normal console python file with .py suffix
> "%basepath%\..\App\python.exe" "%pyfile%" %*
> ) ELSE (
> If EXIST "%pyfile%w" (
> REM a non console python file with .pyw suffix
> start "" "%basepath%\..\App\pythonw.exe" "%pyfile%w" %*
> ) ELSE (
> REM found neither a .py nor a .pyw file
> echo found no python file %pyfile%
> )
> )
> REM
> =========================================================================
> REM end of script
> REM
> =========================================================================
>
>
> One minor drawback of my suggested script would be, that a console
> window pops up for a few seconds when starting a .pyw file.
>
> This could be avoided by using either a small compiled C-file (which
> sounds like overkill though)
> or by writing a windows scripting host .wsf file.
> However I don't know this well enough to replicate my batch file.
> AN article on SO mentions how to write such a script.
> However it does not parse command line arguments nor does it
> automatically determine the scripts file name.
> So any help for creating a .wsf file starting a .pyw file with command
> line arguments would be appreciated.
>
>
>
> An alternativce approach could be to provide a scipt named
> mk_wrapper.bat
> If one drags and drops a python script on it, then an apropriate wrapper
> file would be created in the launcher directory.
>
> If well done, then this could be implemented such, that the script may
> be located in an arbitrary location on the same USB drive.
>
>
>
> I think it would be great if the official portable python release
> contained some upport for launching scripts.
> Perhaps it exists alrady and I just didn't find it?
>
> If not,then I wouldn't mind if my script or a similiar sand a related
> README.txt cript were added to the official release
>

This might be a complete waste of time but can you use the new windows
launcher described here http://www.python.org/dev/peps/pep-0397/ ???


--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


gelonida at gmail

Aug 12, 2012, 4:02 PM

Post #4 of 5 (175 views)
Permalink
Re: suggesting a launcher wrapper script for portable python [In reply to]

Hi Thomas,

On 08/12/2012 09:05 PM, Thomas Jollans wrote:
> On 08/12/2012 02:49 AM, Gelonida N wrote:
>>
>> One minor drawback of my suggested script would be, that a console
>> window pops up for a few seconds when starting a .pyw file.
>
> (I'm no expert but) This should be avoidable if you use the Windows
> Script Host instead of DOS command scripts to write the launchers.
> I.e. use JScript or VBScript to do exactly the same thing. I don't know
> much about Windows shortcut (*.lnk) files; if they can contain relative
> paths, you could just create shortcuts that launch portable python with
> the script.
>

You're absolutely right and I was rather sure, that I posted a link to
an SO article with a wsf script avoiding this problem.

Only drawback of this script was, that it did not detect the name of
it's own script and that it did not pass command line arguments down to
the python script.

Well here is the link: http://preview.tinyurl.com/bu9rda5

The suggested script was:

<job>
<script language="VBScript">
set WshShell = WScript.CreateObject("WScript.Shell")
CMDFile = "App\\pythonw.exe App\\gui.py"
WshShell.Run CMDFile, 1
</script>
</job>

The question is how to extend it such, that it detects it's own name
(nice to have) and that it passes command line args down to python
(essential)

I know absolutely nothing about windows scripting.







>
>


--
http://mail.python.org/mailman/listinfo/python-list


gelonida at gmail

Aug 12, 2012, 4:05 PM

Post #5 of 5 (176 views)
Permalink
Re: suggesting a launcher wrapper script for portable python [In reply to]

On 08/12/2012 09:52 PM, Mark Lawrence wrote:
> On 12/08/2012 01:49, Gelonida N wrote:
>>
>>
>>
>> I think it would be great if the official portable python release
>> contained some upport for launching scripts.
>> Perhaps it exists alrady and I just didn't find it?
>>
>> If not,then I wouldn't mind if my script or a similiar sand a related
>> README.txt cript were added to the official release
>>
>
> This might be a complete waste of time but can you use the new windows
> launcher described here http://www.python.org/dev/peps/pep-0397/ ???
>
>
This might be interesting and I have to read a little more.

However on a very first glance I'd assume it had to be stalled on the
PC, so it would not really be a portable solution (meaning self
contained on a USB key),that can be executed on any WIndows host.

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.