<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ediaz &#124; iamedu &#187; Open Source</title>
	<atom:link href="http://ediaz.me/tag/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://ediaz.me</link>
	<description>Technology, Music, Development, Science</description>
	<lastBuildDate>Thu, 03 Jun 2010 23:28:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>repoze.bfg on a standard java webapp</title>
		<link>http://ediaz.me/2010/01/repoze-bfg-on-a-standard-java-webapp/</link>
		<comments>http://ediaz.me/2010/01/repoze-bfg-on-a-standard-java-webapp/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 14:49:09 +0000</pubDate>
		<dc:creator>iamedu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[repoze.bfg]]></category>

		<guid isPermaLink="false">http://ediaz.me/?p=149</guid>
		<description><![CDATA[Ok thanks to Chris McDonough and the repoze community things are now much easier than they were on my last post, in this one I&#8217;ll explain how to install repoze.bfg with the jinja2 templating environment, and after that how to use it inside your java webapp, this is very interesting because you can use any [...]]]></description>
			<content:encoded><![CDATA[<p>Ok thanks to Chris McDonough and the repoze community things are now much easier than they were on my <a href="http://ediaz.me/2010/01/repoze-bfg-on-jython-2-5/">last post</a>, in this one I&#8217;ll explain how to install repoze.bfg with the jinja2 templating environment, and after that how to use it inside your java webapp, this is very interesting because you can use any resource from your application server from bfg!! how cool is that?</p>
<p>Ok, so first set up your virtualenv you can check how to do that on my last post if you don&#8217;t know (just follow it up to the &#8220;source sys/bin/activate&#8221;) command.</p>
<p>Now there are two ways to install repoze.bfg, the first one is:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code8'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1498"><td class="code" id="p149code8"><pre class="bash" style="font-family:monospace;">easy_install <span style="color: #660033;">-i</span> http:<span style="color: #000000; font-weight: bold;">//</span>dist.repoze.org<span style="color: #000000; font-weight: bold;">/</span>bfg<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.2</span><span style="color: #000000; font-weight: bold;">/</span>simple repoze.bfg.jinja2</pre></td></tr></table></div>

<p>and the second one is to install it from <a href="http://pypi.python.org/pypi">pypi</a> which is almost the same:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code9'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1499"><td class="code" id="p149code9"><pre class="bash" style="font-family:monospace;">easy_install repoze.bfg.jinja2</pre></td></tr></table></div>

<p>Cool isn&#8217;t it?</p>
<p>Now to create your repoze.bfg app use paster like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code10'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14910"><td class="code" id="p149code10"><pre class="bash" style="font-family:monospace;">paster create <span style="color: #660033;">-t</span> bfg_jinja2_starter bfgapp</pre></td></tr></table></div>

<p>And set it up as a development egg</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code11'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14911"><td class="code" id="p149code11"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> bfgapp
jython setup.py devel</pre></td></tr></table></div>

<p>You can test it if you want, running</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code12'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14912"><td class="code" id="p149code12"><pre class="bash" style="font-family:monospace;">paster serve bfgapp.ini</pre></td></tr></table></div>

<p>And that&#8217;s it!! Much easier isn&#8217;t it?</p>
<p>Now, let&#8217;s look how to put this inside our java webapp, for this we are going to use a WSGI java servlet which is included with jython, it&#8217;s called <a href="http://opensource.xhaus.com/projects/show/modjy">modjy</a>.</p>
<p>First of all copy the jython.jar file inside your WEB-INF/lib directory.</p>
<p>Next add the servlet to your WEB-INF/web.xml file, here is my example web.xml</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code13'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14913"><td class="code" id="p149code13"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;3.0&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>BFGApp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modjy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.xhaus.modjy.ModjyJServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>python.home<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/home/iamedu/BFG/sys<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cache_callables<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>reload_on_mod<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>log_level<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>debug<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>load_site_packages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>python.executable<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/home/iamedu/BFG/sys/bin/jython<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DefaultServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.catalina.servlets.DefaultServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>listings<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modjy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DefaultServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/static/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-timeout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            30
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-timeout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Here there are two important initial parameters for the modjy servlet:</p>
<ul>
<li><strong>python.home</strong> This one should point to your virtualenv</li>
<li><strong>python.executable</strong> This one should point to your virtualenv&#8217;s jython executable</li>
</ul>
<p>You can see I also defined a &#8220;default&#8221; servlet, this is because there&#8217;s a problem with the modjy servlet managing static resources, and it&#8217;s probably faster to manage them directly with the default servlet.</p>
<p>Now to make the static resources accessible to the default servlet, just copy them from the templates/static directory in your BFG app to the web directory inside your java webapp, just copy the default.css file and the images directory don&#8217;t copy the whole static directory, unless you want to change your links to something like: &#8220;static/static/default.css&#8221;</p>
<p>Now we just need to add the wrapper between the modjy servlet and bfg, this is quite easy, create an application.py file inside your web directory with the following contents:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code14'); return false;">View Code</a> PYTHON</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14914"><td class="code" id="p149code14"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">site</span>
<span style="color: #ff7700;font-weight:bold;">from</span> repoze.<span style="color: black;">bfg</span>.<span style="color: black;">paster</span> <span style="color: #ff7700;font-weight:bold;">import</span> get_app
&nbsp;
handler = get_app<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/home/iamedu/BFG/MyProject/MyProject.ini'</span>, <span style="color: #483d8b;">'main'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>And now deploy your app and voila!, you have repoze.bfg on you favorite servlet container, you can call your java classes from bfg as it is running in the same Java VM.</p>
<p>We use import site, because the modjy servlet doesn&#8217;t load site-packages automatically, and it&#8217;s probably a bad idea to write the complete path in the get_app, you should copy it to your webapp&#8217;s web directory and get the current work directory.</p>
<p>If you want to package your bfg app inside your java webapp you can copy it to the web directory, everything inside that directory is also in your pythonpath.</p>
<p>Hope this helps somebody!</p>
]]></content:encoded>
			<wfw:commentRss>http://ediaz.me/2010/01/repoze-bfg-on-a-standard-java-webapp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>repoze.bfg on jython 2.5</title>
		<link>http://ediaz.me/2010/01/repoze-bfg-on-jython-2-5/</link>
		<comments>http://ediaz.me/2010/01/repoze-bfg-on-jython-2-5/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 04:44:20 +0000</pubDate>
		<dc:creator>iamedu</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[repoze.bfg]]></category>

		<guid isPermaLink="false">http://ediaz.me/?p=120</guid>
		<description><![CDATA[I&#8217;m going to be honest, I don&#8217;t really like Java for the frontend, but it is very widely used and I find it very nice for whatever&#8217;s not the frontend.
There must be a lot of java guys who think the same and there are projects like Groovy and Grails endorsed by Sun,  I was impressed [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to be honest, I don&#8217;t really like Java for the frontend, but it is very widely used and I find it very nice for whatever&#8217;s not the frontend.</p>
<p>There must be a lot of java guys who think the same and there are projects like <a href="http://groovy.codehaus.org/">Groovy</a> and <a href="http://www.grails.org/">Grails</a> endorsed by Sun,  I was impressed to see even a Ruby container in <a href="https://glassfish.dev.java.net/">glassfish v3</a>.</p>
<p>I haven&#8217;t tried ruby yet so I cannot comment on that, and I wanted to try something simple with jython so I decided to try bfg, my first attempts didn&#8217;t work so I asked for help on the bfg developers list, and a loooot of help from Chris McDonough I got it working.</p>
<p>It isn&#8217;t soo nice yet, and zcml configuration doesn&#8217;t work but at least it&#8217;s usable.</p>
<p>Here is how to get it working, since some changes were just made by Chris on the development&#8217;s trunk you need subversion and mercurial to get the repos.</p>
<p>First of all get <a href="http://www.jython.org/">jython</a> I tried this with 2.5.1, it is pretty simple to install it.</p>
<p>Next you need to get setuptools, you can get that from <a href="http://pypi.python.org/pypi/setuptools">pypi</a> make sure to download the source version (the one that ends with .tar.bz2)</p>
<p>To install it uncompress it, get into the directory and run:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code25'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12025"><td class="code" id="p120code25"><pre class="bash" style="font-family:monospace;"><span style="color: #800000;">${JYTHONDIR}</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jython setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Since we are going to be testing a lot it&#8217;s better to install virtualenv do it with</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code26'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12026"><td class="code" id="p120code26"><pre class="bash" style="font-family:monospace;"><span style="color: #800000;">${JYTHONDIR}</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install virtualenv</pre></td></tr></table></div>

<p>Now create a folder where you can start working, in this case I&#8217;ll assume it&#8217;s called BFG</p>
<p>Get into the BFG folder and create a virtual env.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code27'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12027"><td class="code" id="p120code27"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> BFG
<span style="color: #800000;">${JYTHONDIR}</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>virtualenv <span style="color: #660033;">--no-site-packages</span> sys
<span style="color: #7a0874; font-weight: bold;">source</span> sys<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>activate</pre></td></tr></table></div>

<p>After this you&#8217;ll have you virtualenv&#8217;s jython and easy_install in your path.</p>
<p>It&#8217;s time to download latest versions from repos, and also <a href="http://http://pypi.python.org/packages/source/z/zope.schema/zope.schema-3.5.4.tar.gz">http://pypi.python.org/packages/source/z/zope.schema/zope.schema-3.5.4.tar.gz</a> this from pypi</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code28'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12028"><td class="code" id="p120code28"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.repoze.org<span style="color: #000000; font-weight: bold;">/</span>repoze.bfg<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span> repoze.bfg
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.repoze.org<span style="color: #000000; font-weight: bold;">/</span>repoze.bfg.jinja2<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span> repoze.bfg.jinja2
hg clone http:<span style="color: #000000; font-weight: bold;">//</span>dev.pocoo.org<span style="color: #000000; font-weight: bold;">/</span>hg<span style="color: #000000; font-weight: bold;">/</span>jinja2-main jinja2
<span style="color: #c20cb9; font-weight: bold;">tar</span> xfvj zope.schema-3.5.4.tar.gz</pre></td></tr></table></div>

<p>Now we need to change a few things head into the zope.schema-3.5.4 folder and edit this file src/zope/schema/_bootstrapfields.py</p>
<p>In line 31 you should see something like:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code29'); return false;">View Code</a> PYTHON</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12029"><td class="code" id="p120code29"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> ValidatedProperty<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name, check=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>._info = name, check
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__set__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, inst, value<span style="color: black;">&#41;</span>:
        name, check = <span style="color: #008000;">self</span>._info
        <span style="color: #ff7700;font-weight:bold;">if</span> value <span style="color: #66cc66;">!</span>= inst.<span style="color: black;">missing_value</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> check <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span>:
                check<span style="color: black;">&#40;</span>inst, value<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                inst.<span style="color: black;">validate</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
        inst.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span> = value</pre></td></tr></table></div>

<p>Add a __get__ method like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code30'); return false;">View Code</a> PYTHON</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12030"><td class="code" id="p120code30"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> ValidatedProperty<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name, check=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>._info = name, check
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__set__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, inst, value<span style="color: black;">&#41;</span>:
        name, check = <span style="color: #008000;">self</span>._info
        <span style="color: #ff7700;font-weight:bold;">if</span> value <span style="color: #66cc66;">!</span>= inst.<span style="color: black;">missing_value</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> check <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span>:
                check<span style="color: black;">&#40;</span>inst, value<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                inst.<span style="color: black;">validate</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
        inst.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span> = value
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__get__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, inst, owner<span style="color: black;">&#41;</span>:
        name, check = <span style="color: #008000;">self</span>._info
        <span style="color: #ff7700;font-weight:bold;">return</span> inst.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span></pre></td></tr></table></div>

<p>Now install zope.schema with:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code31'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12031"><td class="code" id="p120code31"><pre class="bash" style="font-family:monospace;">jython setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Now get into the jinja2 directory, here you should patch your file with the patch provided below</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code32'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12032"><td class="code" id="p120code32"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">patch</span> <span style="color: #660033;">-p1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; jinja2_jython.patch</pre></td></tr></table></div>

<p>Now for install jinja2, repoze.bfg and repoze.bfg.jinja2 in that order, for each package just go into the directory and run:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code33'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12033"><td class="code" id="p120code33"><pre class="bash" style="font-family:monospace;"><span style="color: #800000;">${JYTHONDIR}</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jython setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>You can create a project with paster now, but it won&#8217;t work right away, because zcml doesn&#8217;t work with jython but you can get it working.</p>
<p>Here is a sample project tweaked to work, just download it and run:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code34'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12034"><td class="code" id="p120code34"><pre class="bash" style="font-family:monospace;">paster serve MyProject.ini</pre></td></tr></table></div>

<p>I hope this works for you and that you find it useful</p>
<p><a href="http://ediaz.me/wp-content/uploads/2010/01/MyProject-jython.tar.bz2">MyProject-jython.tar</a></p>
<p><a href="http://ediaz.me/wp-content/uploads/2010/01/jinja2_jython.patch.bz2">jinja2_jython.patch</a></p>
<p><strong>UPDATE </strong>Chris just told me that zope.schema now passes tests under jython, so it&#8217;s no longer necesarry to change the _bootstrapfields.py file.</p>
<p>Another thing, I forgot to mention that you need to run jython setup.py develop with the MyProject egg.</p>
]]></content:encoded>
			<wfw:commentRss>http://ediaz.me/2010/01/repoze-bfg-on-jython-2-5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Next decade: Gadgets , Web = Desktop, HTML 5</title>
		<link>http://ediaz.me/2009/12/next-decade-gadgets-web-desktop-html-5/</link>
		<comments>http://ediaz.me/2009/12/next-decade-gadgets-web-desktop-html-5/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 19:16:07 +0000</pubDate>
		<dc:creator>iamedu</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://ediaz.me/?p=85</guid>
		<description><![CDATA[Right now I&#8217;m in the middle of an existencial crisis, I&#8217;m about to finish university and I don&#8217;t know what to do. I have worked a little in the past, mostly web development in python and java. I enjoy working on the web, and I would work on it, but I don&#8217;t find it that [...]]]></description>
			<content:encoded><![CDATA[<p>Right now I&#8217;m in the middle of an existencial crisis, I&#8217;m about to finish university and I don&#8217;t know what to do. I have worked a little in the past, mostly web development in python and java. I enjoy working on the web, and I would work on it, but I don&#8217;t find it that interesting.</p>
<p>For my thesis project I&#8217;m designing an embedded system along with some friends, it is designed for the ARM architecture. It&#8217;s going pretty well, we have an <a href="http://code.google.com/p/army-creator/">ARM  simulator</a>, some code and ideas for a microkernel (mostly taken from the <a href="http://os.inf.tu-dresden.de/fiasco/">Fiasco microkernel</a>), and a basic hardware platform.  This is what I really  really like, but&#8230; I need a lot more experience to build high quality things&#8230; so the question is&#8230; what to do the next few years?</p>
<p>So it&#8217;s natural that I&#8217;m curious about what is going to happen in the near future&#8230;</p>
<p>I think that we are going to see more portable devices which run UNIX systems, like iPhone OS and Android, I think there are two main reasons why this will continue to happen.</p>
<ul>
<li>UNIX is a very well known and tested architecture.</li>
<li>LINUX has been ported to nearly every machine architecture, because it&#8217;s Open Source.</li>
</ul>
<p>But that is not the only thing, prices on computer processors are dropping so.. I think we are going to <a href="http://www.popularmechanics.com/blogs/technology_news/4210607.html">embed a computer on everything we can</a>, or wouldn&#8217;t you like your <a href="http://news.cnet.com/8301-17939_109-9844750-2.html">internet fridge </a>to order food from the supermarket when it knows you&#8217;re running low on something. Or imagine if you could get updates for your microwave, so it knew how long it takes to defrost some kind of meat (ok this one is very stupid). Your car could connect to google maps to show you the best route to get home.</p>
<p>And what if you could accomplish all of this with the same technology that drives your phone? Why not? a simple ARM processor costs about 15 dollars! (ARM is important here because it&#8217;s an open standard which the iPhone, Motorola DEXT and many others happen to use).</p>
<p>The problem with all of this? we need to train a ton of new programmers to create apps for your iPhone, your DEXT, your microwave, your fridge, your car, your firefly, your TV&#8230;.. blah blah blah blah.</p>
<p>Well&#8230; it won&#8217;t be that bad&#8230; all of that runs on UNIX doesn&#8217;t it? Well, I think we could get most programmers to do stuff for our gadgets.. how?</p>
<p>Ok this may sound stupid and it probably is&#8230; but what about HTML?</p>
<p>At least for the GUI based gadgets it would be nice&#8230; we have tons of  web programmers, we could bring them to the desktop and beyond, and HTML 5 is the key.</p>
<p>HTML 5 has databases, and interaction it is seen as a replacement for Google Gears, and XUL, and I think it can be seen as a direct competitor for Java&#8217;s SWING, Adobe&#8217;s AIR&#8230;</p>
<p>And think about it, part of the HTML 5 standard is how things are displayed on mobile devices.</p>
<p>With this we are leaving all processing in the cloud, we don&#8217;t need the fastest processors.. at least not for the front ends, at least just in theory we need just a web browser (and whatever is needed to run a web browser). Sounds like <a href="http://en.wikipedia.org/wiki/Google_Chrome_OS">Chrome OS</a> doesn&#8217;t it?</p>
<p>The interesting is that we can build our standard java/python/php/whatever backend, or in the case of your microwave you can interact with your C program that drives the motor&#8230;.</p>
<p>I don&#8217;t really believe all of this, but it would be really nice&#8230; don&#8217;t you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://ediaz.me/2009/12/next-decade-gadgets-web-desktop-html-5/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
