<?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>Joys and rants of a Python programmer</title>
	<atom:link href="http://blog.pow.lt/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pow.lt</link>
	<description>Pow! Wham, bam, kapow!</description>
	<lastBuildDate>Wed, 02 Dec 2009 16:04:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Formatting and processing text in TAL templates</title>
		<link>http://blog.pow.lt/2009/12/02/formatting-and-processing-text-in-tal-templates/</link>
		<comments>http://blog.pow.lt/2009/12/02/formatting-and-processing-text-in-tal-templates/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:58:15 +0000</pubDate>
		<dc:creator>Ignas Mikalajūnas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Zope3]]></category>

		<guid isPermaLink="false">http://blog.pow.lt/?p=92</guid>
		<description><![CDATA[
Marius Gedminas wrote
about a
useful technique for formatting paragraphs &#8212; registering a
view for &#8220;*&#8221; that does the processing for you.



  While developing SchoolTool we
  used a bit more complicated, but slightly more secure technique
  &#8212; adapters implementing IPathAdapter.



  To get the same effect that was described in Marius blog post you do [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://gedmin.as/">Marius Gedminas</a> wrote
about <a href="http://mg.pov.lt/blog/zope3-displaying-multiline-text.html">a
useful technique for formatting paragraphs</a> &mdash; registering a
view for &#8220;*&#8221; that does the processing for you.
</p>

<p>
  While developing <a href="http://schooltool.org">SchoolTool</a> we
  used a bit more complicated, but slightly more secure technique
  &mdash; adapters implementing <code>IPathAdapter</code>.
</p>

<p>
  To get the same effect that was described in Marius blog post you do this:
</p>

<pre class="brush: python;">
import cgi

from zope.interface import implements
from zope.traversing.interfaces import ITraversable
from zope.traversing.interfaces import IPathAdapter
from zope.component import adapts


class TalFiltersPathAdapter(object):
    &quot;&quot;&quot;Collection of filters to be used in views for text processing.&quot;&quot;&quot;

    adapts(None)
    implements(IPathAdapter, ITraversable)

    def __init__(self, context):
        self.context = context

    def traverse(self, name, furtherPath=()):
        handler = getattr(self, name)
        return handler(furtherPath)

    def paragraphs(self, furtherPath=()):
        if self.context is None:
            return ''
        paras = filter(None, [s.strip() for s in self.context.splitlines()])
        return &quot;&quot;.join('&lt;p&gt;%s&lt;/p&gt;\n' % cgi.escape(p)
                        for p in paras)

</pre>

Register it like this:


<pre class="brush: xml;">
   &lt;zope:adapter
       for=&quot;*&quot;
       name=&quot;filter&quot;
       provides=&quot;zope.traversing.interfaces.IPathAdapter&quot;
       factory=&quot;.TalFiltersPathAdapter&quot;
       /&gt;
</pre>

And use it like this:

<pre class="brush: xml; light: true;">
&lt;p tal:replace=&quot;structure object/attribute/filter:paragraphs&quot; /&gt;
</pre>

<p>
The benefits of this technique &#8211; you don&#8217;t have
a <code>zope.Public</code> view registered on all your objects, it
will not &#8220;hog&#8221; &#8216;paragraphs&#8217; view name (view names unless they are
registered for a specific skin are a <em>shared resource</em>) and you
can only access this functionality from TAL templates. The downside
&mdash; it is slightly more complicated and more TAL specific, so if
you are not using TAL templates you can&#8217;t really use this.
</p>
<a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F02%2Fformatting-and-processing-text-in-tal-templates%2F&amp;linkname=Formatting%20and%20processing%20text%20in%20TAL%20templates" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F02%2Fformatting-and-processing-text-in-tal-templates%2F&amp;linkname=Formatting%20and%20processing%20text%20in%20TAL%20templates" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F02%2Fformatting-and-processing-text-in-tal-templates%2F&amp;linkname=Formatting%20and%20processing%20text%20in%20TAL%20templates" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F02%2Fformatting-and-processing-text-in-tal-templates%2F&amp;linkname=Formatting%20and%20processing%20text%20in%20TAL%20templates" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F02%2Fformatting-and-processing-text-in-tal-templates%2F&amp;linkname=Formatting%20and%20processing%20text%20in%20TAL%20templates"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.pow.lt/2009/12/02/formatting-and-processing-text-in-tal-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running browser in the middle of a Pylons test</title>
		<link>http://blog.pow.lt/2009/12/01/running-browser-in-the-middle-of-a-pylons-test/</link>
		<comments>http://blog.pow.lt/2009/12/01/running-browser-in-the-middle-of-a-pylons-test/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:49:15 +0000</pubDate>
		<dc:creator>Ignas Mikalajūnas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Pylons]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.pow.lt/?p=83</guid>
		<description><![CDATA[
  Tests are good! writing tests is good! Sometimes they break and you
  can&#8217;t understand what&#8217;s wrong. Pylons is using webtest.TestApp for functional test and
  TestResponse has a showbrowser method, a method that
  displays the response in your browser, but most of the time it&#8217;s
  just not enough.



  When [...]]]></description>
			<content:encoded><![CDATA[<p>
  Tests are good! writing tests is good! Sometimes they break and you
  can&#8217;t understand what&#8217;s wrong. Pylons is using <code>webtest.TestApp</code> for functional test and
  <code>TestResponse</code> has a <code>showbrowser</code> method, a method that
  displays the response in your browser, but most of the time it&#8217;s
  just not enough.
</p>

<p>
  When I started using Pylons, I missed the ability to start a server
  in the middle of the test so much (I had implemented this
  functionality for Zope3 functional tests before) that I just had to
  add it to my Pylons testing environment. As Pylons is a WSGI
  application, it was even easier than I expected:
</p>

<pre class="brush: python;">
import pylons
import webbrowser
import sys
import urllib2

from webtest import TestApp
from wsgiref.simple_server import make_server


def addPortToURL(url, port):
    &quot;&quot;&quot;Add a port number to the url.

        &gt;&gt;&gt; addPortToURL('http://localhost/foo/bar/baz.html', 3000)
        'http://localhost:3000/foo/bar/baz.html'
        &gt;&gt;&gt; addPortToURL('http://foo.bar.com/index.html?param=some-value', 555)
        'http://foo.bar.com:555/index.html?param=some-value'

        &gt;&gt;&gt; addPortToURL('http://localhost:666/index.html', 555)
        'http://localhost:555/index.html'

    &quot;&quot;&quot;
    (scheme, netloc, url, query, fragment) = urllib2.urlparse.urlsplit(url)
    netloc = netloc.split(':')[0]
    netloc = &quot;%s:%s&quot; % (netloc, port)
    url = urllib2.urlparse.urlunsplit((scheme, netloc, url, query, fragment))
    return url


class ServingTestApp(TestApp):

    request = None

    def do_request(self, req, status, expect_errors):
        self.request = req
        return super(ServingTestApp, self).do_request(req, status, expect_errors)

    def serve(self, page_url=None):
        try:
            if page_url is None:
                page_url = getattr(self.request, 'url', 'http://localhost/')
            # XXX we rely on browser being slower than our server
            webbrowser.open(addPortToURL(page_url, 5001))
            print &gt;&gt; sys.stderr, 'Starting HTTP server...'
            srv = make_server('localhost', 5001, pylons.test.pylonsapp)
            srv.serve_forever()
        except KeyboardInterrupt:
            print &gt;&gt; sys.stderr, 'Stopped HTTP server.'
</pre>

<p>
Now instead of the usual <code>TestApp</code> you just
use <code>ServingTestApp</code>
</p>

<pre class="brush: python;">
class TestController(TestCase):

    def __init__(self, *args, **kwargs):
        if pylons.test.pylonsapp:
            wsgiapp = pylons.test.pylonsapp
        else:
            wsgiapp = loadapp('config:%s' % config['__file__'])
        # Replace:
        # self.app = TestApp(wsgiapp)
        # With
        self.app = ServingTestApp(wsgiapp)
        url._push_object(URLGenerator(config['routes.map'], environ))
        TestCase.__init__(self, *args, **kwargs)
</pre>

<p>
And in your code you can do this:
</p>

<pre class="brush: python;">
from sample.tests import *

class TestHelloController(TestController):

    def test_index(self):
        response = self.app.get(url(controller='hello', action='index'))
        # Test response...
        self.app.serve()
</pre>

<p>
  This is immensely useful when you want to find out what to click
  next, while writing a test for a part of the application that you
  haven&#8217;t worked with for a while. Or browser stress-testing, because
  now you can just use your testing framework to generate thousands of
  throw away objects in a database that will be gone when a test is
  over, and will be there again when you run the test for the second
  time.
</p>

<p>
  I use it a lot when I want to test the UI of deleting objects, or
  when I work on things that have a uni-directional workflow. Testing
  the step number 7 in your browser requires you completing the first
  6 steps, doing that every time you want to look at the transition
  from step 7 to step 8 is just too much work.
</p>
<a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F01%2Frunning-browser-in-the-middle-of-a-pylons-test%2F&amp;linkname=Running%20browser%20in%20the%20middle%20of%20a%20Pylons%20test" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F01%2Frunning-browser-in-the-middle-of-a-pylons-test%2F&amp;linkname=Running%20browser%20in%20the%20middle%20of%20a%20Pylons%20test" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F01%2Frunning-browser-in-the-middle-of-a-pylons-test%2F&amp;linkname=Running%20browser%20in%20the%20middle%20of%20a%20Pylons%20test" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F01%2Frunning-browser-in-the-middle-of-a-pylons-test%2F&amp;linkname=Running%20browser%20in%20the%20middle%20of%20a%20Pylons%20test" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F12%2F01%2Frunning-browser-in-the-middle-of-a-pylons-test%2F&amp;linkname=Running%20browser%20in%20the%20middle%20of%20a%20Pylons%20test"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.pow.lt/2009/12/01/running-browser-in-the-middle-of-a-pylons-test/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Testing your translations for bugs</title>
		<link>http://blog.pow.lt/2009/11/29/testing-your-translations-for-bugs/</link>
		<comments>http://blog.pow.lt/2009/11/29/testing-your-translations-for-bugs/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 22:23:02 +0000</pubDate>
		<dc:creator>Ignas Mikalajūnas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[Pylons]]></category>
		<category><![CDATA[zc.buildout]]></category>

		<guid isPermaLink="false">http://blog.pow.lt/?p=40</guid>
		<description><![CDATA[The problem


We have released the Polish version
of Ututi a week ago, and that taught me
a couple of lessons:



  I18n in Pylons support is lacking
  You must have tests for your translations just as you test your code



There are some flaws in Pylons I18n that got me longing for Zope3 I18n.


  
  [...]]]></description>
			<content:encoded><![CDATA[<h2>The problem</h2>

<p>
We have released the Polish version
of <a href="http://ututi.pl">Ututi</a> a week ago, and that taught me
a couple of lessons:
</p>

<ol>
  <li>I18n in Pylons support is lacking</li>
  <li>You must have tests for your translations just as you test your code</li>
</ol>

<p>
There are some flaws in Pylons I18n that got me longing for Zope3 I18n.

<ul>
  <li>
  There is no &#8216;default&#8217; translation. When I used Zope3 I used to be able to say
  <code>_('ok-button-text', default='OK')</code>. With Pylons I have
  to have an English to English translation, which means that
  translators cannot see the default text, which leads to mistakes
  like <code>'ok-mygtuko-tekstas'</code> instead of <code>'Gerai'</code>
  or <code>'OK'</code>
  </li>
  <li>
  Using Python formatting directives leads to tracebacks if there are
  bugs in the translations. If someone translates <code>'Hi %(fullname)s!'</code>
  into <code>'Labas %(fullname)'</code>, all the pages that try showing this
  message will end up as error pages, because of the missing <code>'s'</code>.
  </li>
  <li>
    Mako templates are very very very translation unfriendly. Simple
    translatable texts look like: <code>${_('Hi!')}</code> and more complex texts
    in our templates end up looking like:
<pre class="brush: plain;">
${_('A new file %(link_to_file)s was uploaded for the subject %(subject_title)s') % dict(
        filename=h.link_to(c.filename, c.file_url),
        subject_title=c.subject_title)}
</pre>

  It looks like perl already, I am not even talking about what happens
  when you have something like an email, with multiple lines of text
  and multiple embedded links, to translate. Though Zope&#8217;ish
<pre class="brush: plain;">
&lt;span i18n:translate=&quot;&quot;&gt;A new file
&lt;a tal:attributes=&quot;href view/file_url&quot; i18n:name=&quot;link_to_file&quot; tal:content=&quot;view/filename&quot; /&gt;
was uploaded for subject
&lt;tal:block i18n:name=&quot;subject_title&quot; tal:content=&quot;view/subject_title&quot; /&gt;
&lt;/span&gt;
</pre>
  is just as ugly for short pieces of text I would surely prefer it
  for something that is more than 2 lines of text. An Emacs macro that
  wraps any selected text in <code>${_('&lt;text here&gt;')}</code>
  helps to reduce the strain, but I&#8217;d prefer dedicated markers for
  translatable text, ones that would be easier on the Shift-pressing
  hand than what we have now.
  </li>
  <li>
  Babel has problems extracting some strings, some times, from Mako
  templates. The workaround -
    <ul>
      <li>run tests (yay almost 100% coverage),</li>
      <li>copy template cache into your &#8217;src&#8217;,</li>
      <li>extract the translations,</li>
      <li>remove the copy.</li>
      <li>And then remove all the fuzzy markers from plural strings
      that are marked as <code>#&nbsp;,python-format</code> by babel, which
      as you can guess is all the plural strings. We don&#8217;t want to
      guess the position of the hours in a sentence like <code>'uploaded
      %(hours)s ago'</code></li>
    </ul>
  I still haven&#8217;t managed to find the time to reduce the problematic
  templates to something that I can fit into a bug report. <em>(Update: Seems like the bug that is causing some (if not all) of the problems was reported 8 months ago in the <a href="http://www.makotemplates.org/trac/ticket/106">mako bug tracker</a>)</em>
  </li>
</ul>
</p>

<h2>The solution</h2>

<p>
Now that we&#8217;re done explaining what&#8217;s wrong, let&#8217;s talk about
something more constructive &#8211; making sure that tracebacks do not
happen, because of typos in translations. First &#8211; we need a nice
translation tester. Candidates:
</p>

<ol>
  <li>potest</li>
  <li>gettext-lint</li>
  <li>pofilter from translate-toolkit</li>
</ol>

<h3>potest</h3>

<p>
Last commit 78 weeks ago. Can&#8217;t parse plural forms. Verdict &mdash; unusable.
</p>

<h3>gettext-lint</h3>

<p>
Seems to be written in Python, but packaging uses autoconf !? which
generates a Makefile that does <strong>nothing</strong>. Seems
cumbersome to use, can&#8217;t check html tags (some translators get this
idea of translating &lt;strong&gt; into the target language), does not
handle %(foo)s syntax.
</p>

<h3>pofilter</h3>

<p>
The tarball has all parts that are needed to package this tool as an
egg, but it is not easy_installable. So what do we do? The same thing
we do every night,
<ul>
  <li><code>extract</code>,</li>
  <li><code>python setup.py sdist</code>,</li>
  <li><code>scp dist/translate-toolkit.tar.gz pow.lt:~/www/eggs/</code></li>
</ul>
</p>

<p>
Now we just make a new virtualenv and
easy_install <em>translate-toolkit</em> in it:
</p>

<pre class="brush: bash;">
virtualenv translations
cd translations
bin/easy_install translate-toolkit --find-links=http://pow.lt/eggs
</pre>

<p>
And test it on one of the projects in my src that has a <strong>lot</strong> of translations &mdash; SchoolTool:
</p>

<pre class="brush: bash;">
bin/pofilter ../trunk/schooltool/src/schooltool/locales \
               -o ./out -t printf -t xmltags -t variables --openoffice
</pre>

<p>
(I pass the <code>--openoffice</code> parameter, so that it would recognize
Zope3 translation markers, like <code>${calendar_title}</code>, as variables)
</p>

<p>
This results in a bunch of PO files in the ./out, each file containing
the errors for the corresponding translation file.
</p>

<pre class="brush: plain;">
# (pofilter) variables: do not translate: ${event_title}
#: /src/schooltool/app/browser/templates/recevent_delete.pt:4
#: /src/schooltool/app/browser/templates/recevent_delete.pt:14
msgid &quot;Deleting a repeating event (${event_title})&quot;
msgstr &quot;Šalinamas pasikartojantis įvykis (${event title}&quot;
</pre>

<p>
Pretty cool, eh? pofilter has most of the functions I need, I just
have to integrate it into my sandbox and extend it a little bit. So
first I add:
</p>

<pre class="brush: plain;">
[test_translations]
find-links = http://pow.lt/eggs/
recipe = zc.recipe.egg
eggs = translate-toolkit
       lxml
entry-points = pofilter=translate.filters.pofilter:main
</pre>

<p>
to my buildout.cfg.
</p>

<p>
 (I added an entry point to the [test_translations] section, because
 all the translate-toolkit scripts seem to be defined as plain scripts
 and not registered as console_script entry points)
</p>

<p>
Customizing pofilter is slightly difficult. I could not find any
defined hooks that would allow me to customize the functionality. And
&#8220;xmltags&#8221; seems to be picking up all the translated &#8220;title&#8221; attributes
on links, which is annoying. So after reporting this as a bug I just
find the &#8220;main&#8221; function in translate.filters.pofilter, copy it and
produce &#8211; this:
</p>

<pre class="brush: python;">
from translate.filters.pofilter import cmdlineparser
from translate.filters.checks import StandardChecker

from translate.filters.checks import CheckerConfig

ututiconfig = CheckerConfig(
    canchangetags = [(&quot;a&quot;, &quot;title&quot;, None)]
    )

class UtutiChecker(StandardChecker):

    def __init__(self, **kwargs):
        checkerconfig = kwargs.get(&quot;checkerconfig&quot;, None)
        if checkerconfig is None:
            checkerconfig = CheckerConfig()
            kwargs[&quot;checkerconfig&quot;] = checkerconfig
        checkerconfig.update(ututiconfig)
        StandardChecker.__init__(self, **kwargs)


def main():
    parser = cmdlineparser()
    parser.add_option(&quot;&quot;, &quot;--ututi&quot;, dest=&quot;filterclass&quot;,
        action=&quot;store_const&quot;, default=None, const=UtutiChecker,
        help=&quot;use the standard checks for Ututi translations&quot;)

    parser.run()
</pre>

<p>
Then registered this new function as an entry point instead of the old
one:
</p>

<pre class="brush: plain;">
[test_translations]
find-links = http://pow.lt/eggs/
recipe = zc.recipe.egg
eggs = ututi
entry-points = pofilter=ututi.tests.translations:main
</pre>

<p>
Now if I will pass &#8220;&#8211;ututi&#8221; to pofilter it will not raise warnings for
title attributes anymore.
</p>

<h2>Icing on the cake</h2>

<p>
  Tests are pretty useless if they are not run, and we want to run our
  tests after every modification to the code, and after every commit
  to our git server. As I am using make as my tool to run everything,
  I just added these two targets to the Makefile.
</p>

<pre class="brush: plain;">
.PHONY: test_translations
test_translations: bin/pofilter
	bin/pofilter --progress=none -t xmltags -t printf --ututi src/ututi/i18n/ -o parts/test_translations/
	diff -r -u src/ututi/tests/expected_i18n_errors/ parts/test_translations/

.PHONY: update_expected_translations
update_expected_translations: bin/pofilter
	bin/pofilter --progress=none -t xmltags -t printf --ututi src/ututi/i18n/ -o parts/test_translations/
	rm -rf src/ututi/tests/expected_i18n_errors/
	mv parts/test_translations/ src/ututi/tests/expected_i18n_errors/
</pre>

<p>
  Even after changes pofilter is still reporting 3-4 false positives,
  that I will have to resolve with our translators, so instead of
  expecting absolutely no output, I am just asking for the output to
  be identical to the old one. If it is a known/accepted failure
  &ndash; we let it be.
</p>

<p>
  And of course &#8211; made our dear Hudson run this after every commit,
  for when I forget to do it myself.
</p>

<h2>Fin!</h2>
<a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F29%2Ftesting-your-translations-for-bugs%2F&amp;linkname=Testing%20your%20translations%20for%20bugs" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F29%2Ftesting-your-translations-for-bugs%2F&amp;linkname=Testing%20your%20translations%20for%20bugs" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F29%2Ftesting-your-translations-for-bugs%2F&amp;linkname=Testing%20your%20translations%20for%20bugs" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F29%2Ftesting-your-translations-for-bugs%2F&amp;linkname=Testing%20your%20translations%20for%20bugs" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F29%2Ftesting-your-translations-for-bugs%2F&amp;linkname=Testing%20your%20translations%20for%20bugs"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.pow.lt/2009/11/29/testing-your-translations-for-bugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cyclomatic complexity in emacs</title>
		<link>http://blog.pow.lt/2009/11/27/cyclomatic-complexity-in-emacs/</link>
		<comments>http://blog.pow.lt/2009/11/27/cyclomatic-complexity-in-emacs/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 18:11:36 +0000</pubDate>
		<dc:creator>Ignas Mikalajūnas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.pow.lt/?p=23</guid>
		<description><![CDATA[Seeing the Cyclomatic complexity in VIM video got me slightly envious. As I am a long time GNU Emacs user I have decided to get back at those VIM people. Emacs can do everything that VIM can, only better after all  

So I present you pycomplexity &#8212; an Emacs mode that can do the same [...]]]></description>
			<content:encoded><![CDATA[Seeing the <a href="http://www.vimeo.com/7259161">Cyclomatic complexity in VIM</a> video got me slightly envious. As I am a long time GNU Emacs user I have decided to get back at those VIM people. Emacs can do everything that VIM can, only better after all <img src='http://blog.pow.lt/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> 

So I present you <a href="http://wiki.github.com/Ignas/pycomplexity">pycomplexity</a> &mdash; an Emacs mode that can do the same thing that vim-complexity does:

<div id="attachment_24" class="wp-caption alignnone" style="width: 529px"><img class="size-full wp-image-24" title="Sample code" src="http://blog.pow.lt/wp-content/uploads/2009/11/emacs_complexity_1.png" alt="pieces of code highlighted according to cyclomatic complexity" width="519" height="436" /><p class="wp-caption-text">pieces of code highlighted according to cyclomatic complexity</p></div>

At the moment the mode is &#8220;Works on my machine&#8221; certified.  But it&#8217;s open source, so contributions are welcome. Big thanks go to <a href="http://stud4.tuwien.ac.at/~e0225855/index.html">Markus Triska</a> the author of the <a href="http://stud4.tuwien.ac.at/~e0225855/linum/linum.html">linum.el</a> and <a href="http://blog.extracheese.org/">Gary Bernhardt</a> for writing the complexity code calculator.

Oh as for the more part:

<img class="alignnone size-full wp-image-30" title="emacs_complexity_2" src="http://blog.pow.lt/wp-content/uploads/2009/11/emacs_complexity_2.png" alt="emacs_complexity_2" width="519" height="169" />

Coming up next &#8211; documenting how to set up pyflakes-enabled flymake:

<img class="alignnone size-full wp-image-31" title="emacs_complexity_3" src="http://blog.pow.lt/wp-content/uploads/2009/11/emacs_complexity_3.png" alt="emacs_complexity_3" width="519" height="181" />

Competition spurs innovation after all <img src='http://blog.pow.lt/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F27%2Fcyclomatic-complexity-in-emacs%2F&amp;linkname=Cyclomatic%20complexity%20in%20emacs" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F27%2Fcyclomatic-complexity-in-emacs%2F&amp;linkname=Cyclomatic%20complexity%20in%20emacs" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F27%2Fcyclomatic-complexity-in-emacs%2F&amp;linkname=Cyclomatic%20complexity%20in%20emacs" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F27%2Fcyclomatic-complexity-in-emacs%2F&amp;linkname=Cyclomatic%20complexity%20in%20emacs" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F11%2F27%2Fcyclomatic-complexity-in-emacs%2F&amp;linkname=Cyclomatic%20complexity%20in%20emacs"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.pow.lt/2009/11/27/cyclomatic-complexity-in-emacs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Cleaning up postgresql database</title>
		<link>http://blog.pow.lt/2009/05/30/cleaning-up-postgresql-database/</link>
		<comments>http://blog.pow.lt/2009/05/30/cleaning-up-postgresql-database/#comments</comments>
		<pubDate>Sat, 30 May 2009 01:23:04 +0000</pubDate>
		<dc:creator>Ignas Mikalajūnas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://blog.pow.lt/?p=4</guid>
		<description><![CDATA[Sometimes when writing tests or copying production database into testing servers you need to get your database back to a clean state, and you just don&#8217;t want to &#8220;DROP DATABASE&#8220;.

I can&#8217;t even do &#8220;DROP DATABASE&#8221; during my test run, because my testing user does not have the rights to do DROP/CREATE databases. So I am [...]]]></description>
			<content:encoded><![CDATA[Sometimes when writing tests or copying production database into testing servers you need to get your database back to a clean state, and you just don&#8217;t want to &#8220;<strong>DROP DATABASE</strong>&#8220;.

I can&#8217;t even do &#8220;<strong>DROP DATABASE</strong>&#8221; during my test run, because my testing user does not have the rights to do <strong>DROP</strong>/<strong>CREATE</strong> databases. So I am abusing^W taking advantage of the fact that by default all the tables, procedures, triggers and pretty much everything you add to the database are added to the default schema. As I am not adding any new schemas, I can just &#8220;<strong>DROP SCHEMA PUBLIC CASCADE</strong>&#8221; which gets rid of the default schema, and everything that is related to it (don&#8217;t forget to add it back with &#8220;<strong>CREATE SCHEMA PUBLIC</strong>&#8221; so you could add tables to the database).

I am not sure whether this operation can have any dangerous side effects, but for a quick and 100% reliable teardown &#8211; it works perfectly. And I am not really worrying about our testing database&#8230;

I tried to use the &#8220;-c&#8221; flag which you can pass to pg_restore. Running:
<pre><code>pg_dump production -Fc -O | pg_restore -d testing -c
</code></pre>
works fine most of the time. The command will delete all the tables and all the triggers that were present in your <strong>production</strong> database from your <strong>testing</strong> database, and &#8220;<strong>DROP SCHEMA PUBLIC</strong>&#8221; (notice the missing <strong>CASCADE</strong>). But it will fail if you had any other tables in your <strong>testing</strong> database. As I am going to be testing my evolution scripts on the testing database a lot, it will have additional tables and triggers most of the time and I really don&#8217;t want that interfering with my tests.<a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F05%2F30%2Fcleaning-up-postgresql-database%2F&amp;linkname=Cleaning%20up%20postgresql%20database" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F05%2F30%2Fcleaning-up-postgresql-database%2F&amp;linkname=Cleaning%20up%20postgresql%20database" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F05%2F30%2Fcleaning-up-postgresql-database%2F&amp;linkname=Cleaning%20up%20postgresql%20database" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F05%2F30%2Fcleaning-up-postgresql-database%2F&amp;linkname=Cleaning%20up%20postgresql%20database" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.pow.lt%2F2009%2F05%2F30%2Fcleaning-up-postgresql-database%2F&amp;linkname=Cleaning%20up%20postgresql%20database"><img src="http://blog.pow.lt/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.pow.lt/2009/05/30/cleaning-up-postgresql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

