Sections
Timeline
Browse Source
New Ticket
Sub-Sections
Download
Comma-delimited Text
Tab-delimited Text
RSS Feed
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Ticket #16 (closed enhancement: fixed)

Opened 11 months ago

Last modified 8 weeks ago

Allow command line options to called scripts

Reported by: anonymous Owned by: gak
Priority: major Component: general
Version: 0.5.0 Keywords:
Cc:

Description

I was amazed at how simple it was to install and use pycallgraph. Just one suggestion.

It would be very helpful if you could specify sys.argv to the called script on the command line. That way I wouldn't have to make a new script file for every set of options. If you put the output filename before the scriptfile you could feed the rest of the command line to the called script. For example:

pycallgraph-dot.py test1.png myscript.py --spam=42 ham.txt eggs.txt

Attachments

Change History

Changed 5 months ago by anonymous

Hi,

you can achieve this by the following:

change:

execfile(args[0])

to:

saveargs = sys.argv # save sys.argv sys.argv = [args[0]] + args[2:] # store custom sys.argv execfile(args[0]) sys.argv = saveargs # restore sys.argv in case it is needed later...

in scripts/pycallgraph-dot.py (version 0.4.1).

Then you can supply arguments to the script after stopping argument processing with '--'.

Example: pycallgraph-dot.py which pycallgraph-dot.py /tmp/test.png -- -h

The -h option is then passed to the exec'd version of pycallgraph-dot.py.

Best, Staal

Changed 5 months ago by anonymous

Sorry about the formatting in the above comment. Forgot to preview... So, the hack (it is a hack) should have looked like this:

Change lines 109-110 in pycallgraph-dot.py (version 0.4.1):

execfile(args[0])
pycallgraph.make_dot_graph(args[1], options.format, options.tool)

to

_my_saveargs = sys.argv
sys.argv = [args[0]] + args[2:]
_my_imagefile = args[1]
_my_options_format = options.format
_my_options_tool = options.tool
execfile(args[0])
sys.argv = _my_saveargs
pycallgraph.make_dot_graph(_my_imagefile, _my_options_format, _my_options_tool)

For this to work, we hope that the code in args[0] does not alter any globals that are needed by pycallgraph, in particular the globals that start with '_my_'.

Best, Staal

Changed 8 weeks ago by gak

  • status changed from new to closed
  • resolution set to fixed

Changed 8 weeks ago by gak

  • reporter g98g67a02@… deleted

Changed 8 weeks ago by gak

  • version set to 0.5.0

Add/Change #16 (Allow command line options to called scripts)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.