On 09/12/2015 09:29 PM, William Bader wrote: >> To: scribus at lists.scribus.net >> From: gpittman at iglou.com >> Date: Sat, 12 Sep 2015 20:03:23 -0400 >> Subject: Re: [scribus] Patch submitted for Command Line Arguments to be >> passed to python script >> >> I wonder if someone could manage to write some documentation on how to >> use this new capability. >> >> It seems that entering -someargv value1 as parameters is not very >> helpful instructions. >> >> What is it that the script is expecting? >> >> Do scripts have to have this 'def main(argv)' structure in order to work? >> >> Not all of us are using this routinely. Python certainly doesn't require it. >> >> Greg > I posted a small example a while ago at > http://bugs.scribus.net/view.php?id=13311#c36071 (the python script is > attached to the mantis page). > Berteh's patch lets you pass arbitrary flags and arguments to the python > script. > For example, my example script inserts text into a text frame in an SLA file. > Instead of hard-coding the name of the text file in the script, you can pass > it on the command line with "scribus -g -py storydeptharg.py --python-arg > -storyfile sample.txt depthtemplate.sla" (I'm not sure about the final syntax > that they settled on.) > The python script the sees an argv that contains "-storyfile" and > "sample.txt". > The command line options are very useful for anyone who is trying to script > Scribus from another program, perhaps to create documents or to export > documents to PDF. > Without the command line patch, you have to hard-code the file names or you > have to generate a customized script each time or you have to pass arguments > through environment variables. > I think that the command line comes from sys.argv, so you might be able to > use "def main():" and then look at sys.argv. > My example has > def main(argv): > ... > if __name__ == '__main__': > main(sys.argv) >
Here's my failed example: I have a script which requires a variable S (which in this case is a Zip code). It previously got this from a valueDialog. I commented out the valueDialog line. I tried to run it with scribus -g -py postnet.py --python-arg -S 40207 and when it runs it tells me there is no value for S. Maybe I don't understand what a 'python-arg' is. Greg
