<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Help me rewrite some repetitive scripts</title>
	<atom:link href="http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/</link>
	<description>Programming, gardening, economics, life in Cleveland Heights</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:03:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Guangzhou Tour</title>
		<link>http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/comment-page-1/#comment-2962</link>
		<dc:creator>Guangzhou Tour</dc:creator>
		<pubDate>Mon, 30 Nov 2009 02:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=489#comment-2962</guid>
		<description>That Sounds interesting, I agree with you.Please keep at your good work, I would come back often.*</description>
		<content:encoded><![CDATA[<p>That Sounds interesting, I agree with you.Please keep at your good work, I would come back often.*</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lhasa Tours</title>
		<link>http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/comment-page-1/#comment-2888</link>
		<dc:creator>Lhasa Tours</dc:creator>
		<pubDate>Mon, 09 Nov 2009 05:12:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=489#comment-2888</guid>
		<description>That Sounds interesting, I agree with you.Please keep at your good work, I would come back often.*</description>
		<content:encoded><![CDATA[<p>That Sounds interesting, I agree with you.Please keep at your good work, I would come back often.*</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: allied problems</title>
		<link>http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/comment-page-1/#comment-2762</link>
		<dc:creator>allied problems</dc:creator>
		<pubDate>Sat, 24 Oct 2009 16:40:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=489#comment-2762</guid>
		<description>Know of any good sources for code samples to automate 3270 scripts through Access VBA?</description>
		<content:encoded><![CDATA[<p>Know of any good sources for code samples to automate 3270 scripts through Access VBA?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/comment-page-1/#comment-2729</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Mon, 19 Oct 2009 14:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=489#comment-2729</guid>
		<description>Linus, thanks for the idea!  I like the idea of using hooks that get specified for each case.</description>
		<content:encoded><![CDATA[<p>Linus, thanks for the idea!  I like the idea of using hooks that get specified for each case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Linus</title>
		<link>http://blog.tplus1.com/index.php/2009/10/18/help-me-rewrite-some-repetitive-scripts/comment-page-1/#comment-2728</link>
		<dc:creator>Linus</dc:creator>
		<pubDate>Mon, 19 Oct 2009 08:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=489#comment-2728</guid>
		<description>One approach could be the &quot;Template&quot;-pattern (or &quot;Self-Delegation&quot;, as it is sometimes called). Do a Base class &quot;ScriptBase&quot; like that:&lt;br&gt;&lt;br&gt;----------&lt;br&gt;class ScriptBase(object):&lt;br&gt;    def __init__(self):&lt;br&gt;        self._p = optparse.OptionParser()&lt;br&gt;&lt;br&gt;        self._p.add_option(&#039;--version&#039;, action=&#039;store_true&#039;,&lt;br&gt;             help=&#039;Print the version and exit&#039;)&lt;br&gt;&lt;br&gt;    def set_parser_usage(self, usage):&lt;br&gt;        self._p.set_usage(usage)&lt;br&gt;&lt;br&gt;    def pre_load_project_hook(self):&lt;br&gt;        pass&lt;br&gt;&lt;br&gt;    def post_load_project_hook(self):&lt;br&gt;        pass&lt;br&gt;&lt;br&gt;    def run():&lt;br&gt;        self._options, self._args = self._p.parse_args()&lt;br&gt;        if self.options.version:&lt;br&gt;            print_version()&lt;br&gt;            return&lt;br&gt;        self.pre_load_project_hook()&lt;br&gt;&lt;br&gt;        pitzdir = Project.find_pitzdir(options.pitzdir)&lt;br&gt;        self._proj = Project.from_pitzdir(pitzdir)&lt;br&gt;        self._proj.find_me()&lt;br&gt;&lt;br&gt;        self.post_load_project_hook()&lt;br&gt;        proj.save_entities_to_yaml_files()&lt;br&gt;&lt;br&gt;# and a script inherits from it:&lt;br&gt;&lt;br&gt;class PitzAttachFile(ScriptBase):&lt;br&gt;    def __init__(self):&lt;br&gt;        self.set_parser_usage(&quot;%prog entity file-to-attach&quot;)&lt;br&gt;    def pre_load_project_hook(self):&lt;br&gt;        if len(self._args) != 2:&lt;br&gt;        self._p.print_usage()&lt;br&gt;        return&lt;br&gt;    def post_load_project_hook(self):&lt;br&gt;        e, filepath = self._proj[args[0]], args[1]&lt;br&gt;        e.save_attachment(filepath)&lt;br&gt;&lt;br&gt;# and here we run the script:&lt;br&gt;pitz_attach_file = PitzAttachFile()&lt;br&gt;pitz_attach_file.run()&lt;br&gt;&lt;br&gt;-------&lt;br&gt;&lt;br&gt;Note that this is totally untested and written in the comment field, so indentation might be wrong etc., but I hope to get across what this is all about - it&#039;s a &quot;script framework&quot; (Hollywood-principle: Don&#039;t call us, we call you).&lt;br&gt;&lt;br&gt;You can make a hook mandatory by raising a NotImplementedError in the base class.</description>
		<content:encoded><![CDATA[<p>One approach could be the &#8220;Template&#8221;-pattern (or &#8220;Self-Delegation&#8221;, as it is sometimes called). Do a Base class &#8220;ScriptBase&#8221; like that:</p>
<p>&#8212;&#8212;&#8212;-<br />class ScriptBase(object):<br />    def __init__(self):<br />        self._p = optparse.OptionParser()</p>
<p>        self._p.add_option(&#39;&#8211;version&#39;, action=&#39;store_true&#39;,<br />             help=&#39;Print the version and exit&#39;)</p>
<p>    def set_parser_usage(self, usage):<br />        self._p.set_usage(usage)</p>
<p>    def pre_load_project_hook(self):<br />        pass</p>
<p>    def post_load_project_hook(self):<br />        pass</p>
<p>    def run():<br />        self._options, self._args = self._p.parse_args()<br />        if self.options.version:<br />            print_version()<br />            return<br />        self.pre_load_project_hook()</p>
<p>        pitzdir = Project.find_pitzdir(options.pitzdir)<br />        self._proj = Project.from_pitzdir(pitzdir)<br />        self._proj.find_me()</p>
<p>        self.post_load_project_hook()<br />        proj.save_entities_to_yaml_files()</p>
<p># and a script inherits from it:</p>
<p>class PitzAttachFile(ScriptBase):<br />    def __init__(self):<br />        self.set_parser_usage(&#8220;%prog entity file-to-attach&#8221;)<br />    def pre_load_project_hook(self):<br />        if len(self._args) != 2:<br />        self._p.print_usage()<br />        return<br />    def post_load_project_hook(self):<br />        e, filepath = self._proj[args[0]], args[1]<br />        e.save_attachment(filepath)</p>
<p># and here we run the script:<br />pitz_attach_file = PitzAttachFile()<br />pitz_attach_file.run()</p>
<p>&#8212;&#8212;-</p>
<p>Note that this is totally untested and written in the comment field, so indentation might be wrong etc., but I hope to get across what this is all about &#8211; it&#39;s a &#8220;script framework&#8221; (Hollywood-principle: Don&#39;t call us, we call you).</p>
<p>You can make a hook mandatory by raising a NotImplementedError in the base class.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

