Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Python - RE: Run pyc file without specifying python path ?

 
Thread Tools Search this Thread
Old 08-02-2009, 09:45 AM   #1
Default RE: Run pyc file without specifying python path ?




> -----Original Message-----
> From: Dave Angel [private.php?do=newpm&u=]
> Sent: Thursday, July 30, 2009 20:08
> To: Barak, Ron
> Cc: 'python-'
> Subject: Re: Run pyc file without specifying python path ?
>
> Barak, Ron wrote:
> > Hi Dave,
> >
> > On second thoughts, I may have a problem implementing the

> wrapper solution, because my actual test_pyc.pyc, needs to
> parse its command line.
> > Namely, the actual call to test_pyc.pyc looks something like this:
> >
> > $ python test_pyc.py -U dave -PpasswoRD -C CreateMcGroupOnVolume
> > --SVMs_IPs '10.1.1.1 , 10.1.1.2' -n "host1,host2" -g gn -j

> jn -s svn
> > -t tvn -p pool1 -l -c
> >
> > And I don't know of a way to add these parameters to the "import
> > test_pyc" in wrapper
> >
> > Is there a way to pass information to an imported module ?

> (Sorry if there's an obvious answer, I just cannot figure it out).
> >
> > Bye,
> > Ron.
> >
> >
> >> -----Original Message-----
> >> From: Dave Angel [private.php?do=newpm&u=]
> >> Sent: Thursday, July 30, 2009 16:03
> >> To: Barak, Ron
> >> Cc: 'Dave Angel'; 'python-'
> >> Subject: RE: Run pyc file without specifying python path ?
> >>
> >> Barak, Ron wrote:
> >>
> >>>> -----Original Message-----
> >>>> From: Dave Angel [private.php?do=newpm&u=]
> >>>> Sent: Wednesday, July 29, 2009 21:05
> >>>> To: Barak, Ron
> >>>> Cc: 'python-'
> >>>> Subject: Re: Run pyc file without specifying python path ?
> >>>>
> >>>> Barak, Ron wrote:
> >>>>
> >>>>
> >>>>> Hi,
> >>>>>
> >>>>> I wanted to make a python byte-code file executable,
> >>>>>
> >>>>>
> >>>> expecting to be able to run it without specifying

> "python" on the
> >>>> (Linux bash) command line.
> >>>>
> >>>>
> >>>>> So, I wrote the following:
> >>>>>
> >>>>> [root@VMLinux1 python]# cat test_pyc.py #!/usr/bin/env python
> >>>>>
> >>>>> print "hello"
> >>>>> [root@VMLinux1 python]#
> >>>>>
> >>>>> and made its pyc file executable:
> >>>>>
> >>>>> [root@VMLinux1 python]# ls -ls test_pyc.pyc
> >>>>> 4 -rwxr-xr-x 1 root root 106 Jul 29 14:22 test_pyc.pyc
> >>>>> [root@VMLinux1 python]#
> >>>>>
> >>>>> So, I see:
> >>>>>
> >>>>> [root@VMLinux1 python]# file test_pyc.py*
> >>>>> test_pyc.py: a python script text executable
> >>>>> test_pyc.pyc: python 2.3 byte-compiled
> >>>>> [root@VMLinux1 python]#
> >>>>>
> >>>>> If I try to do the following, no problem:
> >>>>>
> >>>>> [root@VMLinux1 python]# python test_pyc.pyc hello
> >>>>> [root@VMLinux1 python]#
> >>>>>
> >>>>> However, the following fails:
> >>>>>
> >>>>> [root@VMLinux1 python]# ./test_pyc.pyc
> >>>>> -bash: ./test_pyc.pyc: cannot execute binary file
> >>>>> [root@VMLinux1 python]#
> >>>>>
> >>>>> Is there a way to run a pyc file without specifying the
> >>>>>
> >>>>>
> >>>> python path ?
> >>>>
> >>>>
> >>>>> Bye,
> >>>>> Ron.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>> I don't currently run Unix, but I think I know the problem.
> >>>>
> >>>> In a text file, the shell examines the first line, and if
> >>>>
> >> it begins
> >>
> >>>> #!
> >>>> it's assumed to point to the executable of an

> interpreter for that
> >>>> text file. Presumably the same trick doesn't work for a

> .pyc file.
> >>>>
> >>>> Why not write a trivial wrapper.py file, don't compile

> it, and let
> >>>> that invoke the main code in the .pyc file?
> >>>>
> >>>> Then make wrapper.py executable, and you're ready to go.
> >>>>
> >>>> DaveA
> >>>>
> >>>>
> >>>>
> >>>>
> >>> Hi Dave,
> >>> Your solution sort of defeats my intended purpose (sorry
> >>>
> >> for not divulging my 'hidden agenda').
> >>
> >>> I wanted my application to "hide" the fact that it's a
> >>>
> >> python script, and look as much as possible like it's a compiled
> >> program.
> >>
> >>> The reason I don't just give my user a py file, is that I
> >>>
> >> don't want a cleaver user to change the innards of the script.
> >>
> >>> On the other hand, I don't want to make a compiled
> >>>
> >> (freezed?) version of the application, because it'll grow the
> >> resulting file significantly, and I don't have the

> experience to know
> >> how it will run on different Linuxes.
> >>
> >>> Bye,
> >>> Ron.
> >>>
> >>>
> >> Most of the other answers basically paraphrased my suggestion of
> >> making a wrapper file, not compiling it, and making it

> executable.
> >> With that
> >> approach, the user just types "wrapper.py" on his command line.
> >>
> >> And wrapper.py only needs two lines, a shebang, and an

> import, no big
> >> deal if the user modifies it. The rest of your code can be .pyc
> >> files.
> >>
> >> Steven makes some good points. You have to define what level of
> >> clever you're protecting from. A determined hacker will get in no
> >> matter what you do, unless you want to ship the program in a
> >> proprietary embedded system, encased in epoxy.
> >> Further, if you have an extension of .py or .pyc, a knowledgeable
> >> hacker will know it's probably python.
> >>
> >> You imply you want it to run unmodifed on multiple unknown Linux
> >> versions. I think that lets out binfmt solutions.
> >> That means you need to test and support not only multiple Linux
> >> implementations, but multiple Python versions, because who

> knows what
> >> the user may have installed. I think you need to rethink your
> >> support strategy. And maybe concentrate on being able to detect
> >> change, rather than prevent it.
> >>
> >> DaveA
> >>
> >>
> >>
> >>

> (Please don't top-post. It puts responses out of order)
>
> You don't have to do anything special. Any module can import
> sys, and parse sys.argv, as long as it wasn't yet modified.
>
> DaveA
>


Hi Dave,

It seems like I don't understand your solution.
I use the (appatched) soapAPI.py as the wrapper to parsing.pyc.
However, if I do (for instance):

$ python -u parsing.pyc -U aaa

The last line of the output is (as expected):

return_code: 12 ; params: {'username': 'aaa'}

But, if I try the following:

$ soapAPI.py -U aaa

I don't get this line. Only the output to stderr gets printed to the screen..

Bye,
Ron.



Barak, Ron
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Cgi Webserver sagar123 Software 1 04-23-2009 06:32 PM
Monty Python and the Holy Grail SE DVD questions Mark DVD Video 0 04-11-2005 05:29 PM
Monty Python Meaning of Life DVD hotline problems Robert Kaiser DVD Video 3 05-11-2004 06:38 AM
Help regarding damaged Monty Python DVD? Bex DVD Video 5 04-16-2004 02:11 AM
Universal Python Meaning Of Life reply Peter Williams DVD Video 31 09-27-2003 09:13 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46