<?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: CherryPy, The Deploy Script</title>
	<atom:link href="http://www.techraving.com/2008/09/28/cherrypy-the-deploy-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techraving.com/2008/09/28/cherrypy-the-deploy-script/</link>
	<description>An Opinion is a Terrible Thing To Waste</description>
	<lastBuildDate>Thu, 21 Jan 2010 16:59:47 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jeremiah</title>
		<link>http://www.techraving.com/2008/09/28/cherrypy-the-deploy-script/comment-page-1/#comment-637</link>
		<dc:creator>Jeremiah</dc:creator>
		<pubDate>Thu, 23 Oct 2008 03:31:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.techraving.com/?p=131#comment-637</guid>
		<description>Prior to reading this post, I was doing a really clunky shelve before commit/merge unshelve afterwards thing to handle different environments. After I read this post I felt awfully silly for a second :). 

What I ended up doing was using a command-line switch and dicts to abstract away the manual switching I was doing before:


if __name__ == &#039;__main__&#039;:
    current_dir = os.path.dirname(os.path.abspath(__file__))
    
    opts = OptionParser()
    opts.add_option(&#039;-e&#039;, &#039;--environment&#039;,
                    dest=&#039;environment&#039;, default=&#039;development&#039;)

    options, args = opts.parse_args()
    
    engine = cherrypy.engine

    base_config = {
        &#039;log.access_file&#039;: &#039;site_access.log&#039;,
        &#039;log.error_file&#039;: &#039;site_errors.log&#039;,
        &#039;log.screen&#039;: True
        }

    
    #functions for setting up different environments.
    def development():
        base_config.update({&#039;server.socket_port&#039;: 3030})
    def production():
        base_config.update({&#039;server.socket_port&#039;: 80,
                            &#039;server.socket_host&#039;: &#039;0.0.0.0&#039;})
        dp = plugins.DropPrivileges(engine,
                                    uid=&quot;nobody&quot;,
                                    gid=&quot;nogroup&quot;)

        dp.subscribe()

    #dispatch based on environment
    environments = {&#039;development&#039;: development,
                    &#039;dev&#039;: development,
                    &#039;production&#039; : production,
                    &#039;prod&#039;: production}
    try:
        environments[options.environment]()
    except KeyError:
        print &quot;&quot;&quot;You specified an invalid environment option\n valid options are
    ([development &#124; dev] &#124; [production &#124; prod])&quot;&quot;&quot;
        sys.exit(1)

    cherrypy.config.update(base_config)


Thanks for the helpful article(s)!</description>
		<content:encoded><![CDATA[<p>Prior to reading this post, I was doing a really clunky shelve before commit/merge unshelve afterwards thing to handle different environments. After I read this post I felt awfully silly for a second <img src='http://www.techraving.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>What I ended up doing was using a command-line switch and dicts to abstract away the manual switching I was doing before:</p>
<p>if __name__ == &#8216;__main__&#8217;:<br />
    current_dir = os.path.dirname(os.path.abspath(__file__))</p>
<p>    opts = OptionParser()<br />
    opts.add_option(&#8217;-e&#8217;, &#8216;&#8211;environment&#8217;,<br />
                    dest=&#8217;environment&#8217;, default=&#8217;development&#8217;)</p>
<p>    options, args = opts.parse_args()</p>
<p>    engine = cherrypy.engine</p>
<p>    base_config = {<br />
        &#8216;log.access_file&#8217;: &#8217;site_access.log&#8217;,<br />
        &#8216;log.error_file&#8217;: &#8217;site_errors.log&#8217;,<br />
        &#8216;log.screen&#8217;: True<br />
        }</p>
<p>    #functions for setting up different environments.<br />
    def development():<br />
        base_config.update({&#8217;server.socket_port&#8217;: 3030})<br />
    def production():<br />
        base_config.update({&#8217;server.socket_port&#8217;: 80,<br />
                            &#8217;server.socket_host&#8217;: &#8216;0.0.0.0&#8242;})<br />
        dp = plugins.DropPrivileges(engine,<br />
                                    uid=&#8221;nobody&#8221;,<br />
                                    gid=&#8221;nogroup&#8221;)</p>
<p>        dp.subscribe()</p>
<p>    #dispatch based on environment<br />
    environments = {&#8217;development&#8217;: development,<br />
                    &#8216;dev&#8217;: development,<br />
                    &#8216;production&#8217; : production,<br />
                    &#8216;prod&#8217;: production}<br />
    try:<br />
        environments[options.environment]()<br />
    except KeyError:<br />
        print &#8220;&#8221;"You specified an invalid environment option\n valid options are<br />
    ([development | dev] | [production | prod])&#8221;"&#8221;<br />
        sys.exit(1)</p>
<p>    cherrypy.config.update(base_config)</p>
<p>Thanks for the helpful article(s)!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ScottK</title>
		<link>http://www.techraving.com/2008/09/28/cherrypy-the-deploy-script/comment-page-1/#comment-581</link>
		<dc:creator>ScottK</dc:creator>
		<pubDate>Sun, 12 Oct 2008 17:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.techraving.com/?p=131#comment-581</guid>
		<description>@Robert I like how you&#039;re updating with a dict. It&#039;s so much better than making separate update calls to the cherrypy.config. 

I&#039;ll definitely look more into this.</description>
		<content:encoded><![CDATA[<p>@Robert I like how you&#8217;re updating with a dict. It&#8217;s so much better than making separate update calls to the cherrypy.config. </p>
<p>I&#8217;ll definitely look more into this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Brewer</title>
		<link>http://www.techraving.com/2008/09/28/cherrypy-the-deploy-script/comment-page-1/#comment-462</link>
		<dc:creator>Robert Brewer</dc:creator>
		<pubDate>Sun, 28 Sep 2008 20:00:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.techraving.com/?p=131#comment-462</guid>
		<description>Great series so far. Thanks for the step-by-step.

There&#039;s a slightly easier way to do the above: change or add a new entry in _cp_config.environments:

thisdir = os.path.abspath(&quot;.&quot;)
from cherrypy import _cp_config
_cp_config.environments[&#039;production&#039;].update({
    &#039;error_page.default&#039;: &quot;%s/public/index.html&quot; % thisdir,
    &#039;error_page.401&#039;: &quot;%s/public/errors/401.html&quot; % thisdir,
    &#039;error_page.404&#039;: &quot;%s/public/errors/404.html&quot; % thisdir,
    &#039;error_page.500&#039;: &quot;%s/public/errors/500.html&quot; % thisdir,
    &#039;log.error_file&#039;: &quot;%s/logs/production_error.log&quot; % thisdir,
    &#039;log.access_file&#039;: &quot;%s/logs/production_access.log&quot; % thisdir,
    })

The _cp_config.environments dict works like a set of macros, allowing you to apply a set of config entries via a single config entry; that is, given the above, you may apply them all now via the single config entry: {&#039;environment&#039;: &#039;production&#039;}, or via the -e argument to cherryd.

Even though _cp_config looks private (since it starts with an underscore), this is the recommended way to collect entries together and name them. No need to invent your own environments on top of this system--it&#039;s all there already.

Once you have created your own _cp_config.environments, then cherryd really can be used as a single point of entry.</description>
		<content:encoded><![CDATA[<p>Great series so far. Thanks for the step-by-step.</p>
<p>There&#8217;s a slightly easier way to do the above: change or add a new entry in _cp_config.environments:</p>
<p>thisdir = os.path.abspath(&#8221;.&#8221;)<br />
from cherrypy import _cp_config<br />
_cp_config.environments['production'].update({<br />
    &#8216;error_page.default&#8217;: &#8220;%s/public/index.html&#8221; % thisdir,<br />
    &#8216;error_page.401&#8242;: &#8220;%s/public/errors/401.html&#8221; % thisdir,<br />
    &#8216;error_page.404&#8242;: &#8220;%s/public/errors/404.html&#8221; % thisdir,<br />
    &#8216;error_page.500&#8242;: &#8220;%s/public/errors/500.html&#8221; % thisdir,<br />
    &#8216;log.error_file&#8217;: &#8220;%s/logs/production_error.log&#8221; % thisdir,<br />
    &#8216;log.access_file&#8217;: &#8220;%s/logs/production_access.log&#8221; % thisdir,<br />
    })</p>
<p>The _cp_config.environments dict works like a set of macros, allowing you to apply a set of config entries via a single config entry; that is, given the above, you may apply them all now via the single config entry: {&#8217;environment&#8217;: &#8216;production&#8217;}, or via the -e argument to cherryd.</p>
<p>Even though _cp_config looks private (since it starts with an underscore), this is the recommended way to collect entries together and name them. No need to invent your own environments on top of this system&#8211;it&#8217;s all there already.</p>
<p>Once you have created your own _cp_config.environments, then cherryd really can be used as a single point of entry.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
