<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>> To: scribus@lists.scribus.net<br>> From: gpittman@iglou.com<br>> Date: Sat, 12 Sep 2015 20:03:23 -0400<br>> Subject: Re: [scribus] Patch submitted for Command Line Arguments to be passed to python script<br>> <br>> I wonder if someone could manage to write some documentation on how to<br>> use this new capability.<br>> <br>> It seems that entering -someargv value1 as parameters is not very<br>> helpful instructions.<br>> <br>> What is it that the script is expecting?<br>> <br>> Do scripts have to have this 'def main(argv)' structure in order to work?<br>> <br>> Not all of us are using this routinely. Python certainly doesn't require it.<br>> <br>> Greg</div><div><br></div><div>I posted a small example a while ago at <a href="http://bugs.scribus.net/view.php?id=13311#c36071" target="_blank" style="font-size: 12pt;">http://bugs.scribus.net/view.php?id=13311#c36071</a> (the python script is attached to the mantis page).</div><div><br></div><div>Berteh's<span style="font-size: 12pt;"> patch lets you pass arbitrary flags and arguments to the python script.</span></div><div><br></div><div>For example, my example script inserts text into a text frame in an SLA file.</div><div><br></div><div>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.)</div><div><br></div><div>The python script the sees an argv that contains "-storyfile" and "sample.txt".</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>My example has</div><div><br></div><div>def main(argv):</div><div><br></div><div> ...</div><div><br></div><div><div>if __name__ == '__main__':</div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;"> main(sys.argv)</span></div></div><div><br></div><div><br></div><div>Regards,</div><div><br></div><div>William Bader, Director of Research and Development, SCS, http://www.newspapersystems.com</div><div><br></div> </div></body>
</html>