<?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>Luc Stepniewski&#039;s Blog &#187; software</title>
	<atom:link href="http://www.gradstein.info/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gradstein.info</link>
	<description></description>
	<lastBuildDate>Thu, 29 Dec 2011 22:59:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://www.gradstein.info/?pushpress=hub'/>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>New version of chess PGN to TeX to PDF converter</title>
		<link>http://www.gradstein.info/python/version-chess-pgn-tex-pdf-converter/</link>
		<comments>http://www.gradstein.info/python/version-chess-pgn-tex-pdf-converter/#comments</comments>
		<pubDate>Tue, 28 Dec 2010 01:37:08 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[chess]]></category>
		<category><![CDATA[kid]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[children]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[converter]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[mate in one]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[pgn]]></category>
		<category><![CDATA[tetex]]></category>
		<category><![CDATA[tex]]></category>
		<category><![CDATA[tex live]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=418</guid>
		<description><![CDATA[OK, I&#8217;m shameful. After fighting with Scid&#8217;s exporter, and then correcting bugs in pgn2ltx&#8217;s source, I finally decided to take a look at that PGN file format. And guess what? It&#8217;s already composed of FEN notation. And guess what? that super-über cool new skaknew module for LaTeX gets its input as FEN!! So, if I [...]]]></description>
			<content:encoded><![CDATA[<p>OK, I&#8217;m shameful. After fighting with <a href="http://scid.sourceforge.net/" class="liexternal">Scid&#8217;s</a> exporter, and then correcting bugs in pgn2ltx&#8217;s source, I finally decided to take a look at that <a href="http://en.wikipedia.org/wiki/Portable_Game_Notation" rel="nofollow" class="liwikipedia">PGN</a> file format. And guess what? It&#8217;s already composed of <a href="http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="nofollow" class="liwikipedia">FEN</a> notation. And guess what? that super-über cool new skaknew module for LaTeX gets its input as FEN!!</p>
<p><span id="more-418"></span></p>
<p>So, if I had a working brain 1 week ago (at least), I would write a small python program that would eat that PGN and make it into a nicely formatted skaknew TeX formatted file!</p>
<p>Here is that much wanted program, that took just 5 minutes to write:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># vim:syntax=python:sw=4:ts=4:expandtab</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>,<span style="color: #dc143c;">re</span>
&nbsp;
HEADER=<span style="color: #483d8b;">&quot;&quot;&quot;<span style="color: #000099; font-weight: bold;">\</span>
<span style="color: #000099; font-weight: bold;">\\</span>documentclass[10pt,twocolumn]{article}
&nbsp;
<span style="color: #000099; font-weight: bold;">\\</span>usepackage[skaknew]{chessboard,skak}
%<span style="color: #000099; font-weight: bold;">\\</span>usepackage[ps]{skak}
<span style="color: #000099; font-weight: bold;">\\</span>usepackage{latexsym}
<span style="color: #000099; font-weight: bold;">\\</span>usepackage[utf8]{inputenc}
<span style="color: #000099; font-weight: bold;">\\</span>font<span style="color: #000099; font-weight: bold;">\\</span>logo=logo10
<span style="color: #000099; font-weight: bold;">\\</span>font<span style="color: #000099; font-weight: bold;">\\</span>sknf=SkakNew-Figurine
<span style="color: #000099; font-weight: bold;">\\</span>font<span style="color: #000099; font-weight: bold;">\\</span>sknfbx=SkakNew-FigurineBold
<span style="color: #000099; font-weight: bold;">\\</span>font<span style="color: #000099; font-weight: bold;">\\</span>skndia=SkakNew-DiagramT
<span style="color: #000099; font-weight: bold;">\\</span>def<span style="color: #000099; font-weight: bold;">\\</span>Metafont{<span style="color: #000099; font-weight: bold;">\\</span>mbox{<span style="color: #000099; font-weight: bold;">\\</span>logo METAFONT}}
&nbsp;
<span style="color: #000099; font-weight: bold;">\\</span>usepackage{a4wide}
%<span style="color: #000099; font-weight: bold;">\\</span>usepackage{geometry} % to change the page dimensions
%<span style="color: #000099; font-weight: bold;">\\</span>geometry{a4paper}
%%<span style="color: #000099; font-weight: bold;">\\</span>geometry{margin=5in}
%<span style="color: #000099; font-weight: bold;">\\</span>geometry{portrait}
&nbsp;
<span style="color: #000099; font-weight: bold;">\\</span>usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
<span style="color: #000099; font-weight: bold;">\\</span>pagestyle{fancy} % options: empty , plain , fancy
<span style="color: #000099; font-weight: bold;">\\</span>renewcommand{<span style="color: #000099; font-weight: bold;">\\</span>headrulewidth}{0pt} % customise the layout...
<span style="color: #000099; font-weight: bold;">\\</span>lhead{}<span style="color: #000099; font-weight: bold;">\\</span>chead{}<span style="color: #000099; font-weight: bold;">\\</span>rhead{}
<span style="color: #000099; font-weight: bold;">\\</span>lfoot{}<span style="color: #000099; font-weight: bold;">\\</span>cfoot{<span style="color: #000099; font-weight: bold;">\\</span>thepage}<span style="color: #000099; font-weight: bold;">\\</span>rfoot{}
&nbsp;
<span style="color: #000099; font-weight: bold;">\\</span>frenchspacing
<span style="color: #000099; font-weight: bold;">\\</span>begin{document}
&quot;&quot;&quot;</span>
&nbsp;
TEMPLATE=<span style="color: #483d8b;">&quot;&quot;&quot;<span style="color: #000099; font-weight: bold;">\</span>
<span style="color: #000099; font-weight: bold;">\\</span>chessboard[
   setfen=%s,
   ]
&nbsp;
&quot;&quot;&quot;</span>
&nbsp;
END_DOC = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>end{document}&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    pre = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
    output_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s-out.tex&quot;</span> <span style="color: #66cc66;">%</span> pre,<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># First, write the header</span>
    output_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span>HEADER<span style="color: black;">&#41;</span>
&nbsp;
    expr = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'^<span style="color: #000099; font-weight: bold;">\[</span>FEN &quot;([^&quot;]+)&quot;<span style="color: #000099; font-weight: bold;">\]</span>'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">xreadlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        result = expr.<span style="color: black;">search</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> result:
            output_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span>TEMPLATE <span style="color: #66cc66;">%</span> result.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    output_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span>END_DOC<span style="color: black;">&#41;</span>
    output_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>And the best of all, is that I have now full control in its output (well, in my light LaTeX&#8217;s knowledge limits). So now I can add a marker to tell which turn it is (little colored square box next to each game). You wll still get 1<a href="http://www.gradstein.info/wp-content/uploads/mate_in_one-out.pdf" class="lipdf">96 pages</a>, that is 1171 mate in one diagrams to solve.</p>
<p><a href="http://www.gradstein.info/wp-content/uploads/2010/12/pdf-screen.png" class="liimagelink"><img class="aligncenter size-full wp-image-419" title="Example of chess diagram output" src="http://www.gradstein.info/wp-content/uploads/2010/12/pdf-screen.png" alt="" width="462" height="690" /></a></p>
<p>So, to summarize, here are the files:</p>
<ul>
<li>The <a href="http://www.gradstein.info/wp-content/uploads/mate_in_one-out.pdf" class="lipdf">generated PDF</a></li>
<li>The intermediate file, <a href="http://www.gradstein.info/wp-content/uploads/mate_in_one-out.tex" class="liinternal">in TeX format</a></li>
<li>The original file, in <a href="http://www.gradstein.info/static/mate_in_one.pgn.gz" class="lizip">PGN format</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/version-chess-pgn-tex-pdf-converter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updated mate-in-one document, now includes chess coordinates</title>
		<link>http://www.gradstein.info/kid/updated-mate-in-one-document-includes-coordinates/</link>
		<comments>http://www.gradstein.info/kid/updated-mate-in-one-document-includes-coordinates/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 23:18:18 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[chess]]></category>
		<category><![CDATA[kid]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[checkmate]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[échecs]]></category>
		<category><![CDATA[mate]]></category>
		<category><![CDATA[mate in one]]></category>
		<category><![CDATA[Portable Game Notation]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=415</guid>
		<description><![CDATA[After a request to have coordinates on the board, to be able to write answers (a really nice idea, especially that Ido begins writing), I noticed I couldn&#8217;t do it so easily, because the LaTeX module (chess12) didn&#8217;t support that. What a disappointment! And the only way I had for converting from PGN to TeX [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gradstein.info/wp-content/uploads/2010/12/932337_chessman.jpg" class="liimagelink"><img class="size-thumbnail wp-image-417 alignright" title="Chess Knights" src="http://www.gradstein.info/wp-content/uploads/2010/12/932337_chessman-150x150.jpg" alt="" width="150" height="150" /></a>After a request to have coordinates on the board, to be able to write answers (a really nice idea, especially that Ido begins writing), I noticed I couldn&#8217;t do it so easily, because the LaTeX module (chess12) didn&#8217;t support that. What a disappointment!</p>
<p>And the only way I had for converting from PGN to TeX was through <a href="http://scid.sourceforge.net/" class="liexternal">Scid</a> (still cool, still being developed), but supporting only exports to <a href="http://scid.sourceforge.net/help/LaTeX.html" class="liexternal">TeX with chess12 module</a>. Fortunately, <a href="https://launchpad.net/~dl9obn" class="liexternal">Dirk Baechle</a> wrote a tool to convert directly from PGN format to TeX, using his tool <a href="http://pgn2ltx.sourceforge.net/" class="liexternal">pgn2ltx</a>. That tool, written in C++ hasn&#8217;t been updated since 2003, so after a small patch to the source, it worked!</p>
<p>And the best part, is that it generates TeX files for the <a href="http://www.ctan.org/tex-archive/fonts/chess/skaknew/" class="liexternal">skak module</a>, the best alternative to the old, dead chess12 module.</p>
<p><span id="more-415"></span></p>
<p>So, if you wan to generate yourself the PDF, here is my procedure:</p>
<ul>
<li>First, download the pgn2ltx zip file and uncompress it</li>
<li>Patch it with the following diff file:</li>
</ul>
<div id="_mcePaste">

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;"><span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;--- pgn2ltx.cpp.ori	2010-12-27 21:06:56.000000000 +0100&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;+++ pgn2ltx.cpp	2010-12-27 21:07:10.000000000 +0100&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;@@ -35,6 +35,7 @@&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;/*------------------------------------------------------------- Includes */&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;#include &lt;iostream&gt;&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;+#include &lt;cstring&gt;&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;#include &lt;string&gt;&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;#include &lt;fstream&gt;&lt;/div&gt;</span>
<span style="color: #991111;">&lt;div id=&quot;_mcePaste&quot;&gt;#include &lt;sstream&gt;&lt;/div&gt;</span></pre></div></div>

</div>
<div id="_mcePaste">In fact, just add the <strong>#include &lt;cstring&gt;</strong> besides the other includes.</div>
<div>
<ul>
<li>Now just compile it (you need g++ and usual compilation tools like make).</li>
<li>Download the <a href="http://www.gradstein.info/static/mate_in_one.pgn.gz" class="lizip">mate-in-one PGN database</a> I have in my <a href="http://www.gradstein.info/kid/easy-chess-games-for-kids-mate-in-one" class="liinternal">previous article</a> (no way to get the original, the web page we I found it was erased).</li>
<li>Generate the TeX file (did I tell you that <em><strong>you need the TeX Live distribution</strong></em>, which includes by default the skak module?) with the following command:</li>
</ul>
</div>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>pgn2ltx  <span style="color: #000000; font-weight: bold;">&lt;</span> mate_in_one.pgn  <span style="color: #000000; font-weight: bold;">&gt;</span> temp.tex</pre></div></div>

<p>Now, if you generate your PDF file with that temp.tex file, you&#8217;ll get just one diagram per page, and horrible text placement, so I modified the header to remove the useless text and also remove the answers. That makes space for 6 diagrams on each page.</p>
<p>I used this grep command to remove the text:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> temp.tex <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;White to Move and Mate in One&quot;</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> mate <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> mainline <span style="color: #000000; font-weight: bold;">&gt;</span> temp2.tex</pre></div></div>

<p>Replace the header with the following :</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #E02020; ">\</span><span style="color: #800000;">documentclass</span><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">10pt,twocolumn</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">usepackage</span><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">ps</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">skak</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">latexsym</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">usepackage</span><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">utf8</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">inputenc</span><span style="color: #E02020; ">}\</span><span style="color: #800000;">usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">a4wide</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">fancyhdr</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% This should be set AFTER setting up the page geometry</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">pagestyle</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">fancy</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% options: empty , plain , fancy</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">renewcommand</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\headrulewidth</span></span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">0pt</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% customise the layout...</span>
<span style="color: #800000; font-weight: normal;">\lhead</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">}<span style="color: #800000; font-weight: normal;">\chead</span>{</span><span style="color: #2020C0; font-weight: normal;">}<span style="color: #800000; font-weight: normal;">\rhead</span>{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\lfoot</span>{</span><span style="color: #2020C0; font-weight: normal;">}<span style="color: #800000; font-weight: normal;">\cfoot</span><span style="color: #E02020; ">{</span><span style="color: #800000; font-weight: normal;">\thepage</span></span><span style="color: #E02020; ">}</span><span style="color: #800000; font-weight: normal;">\rfoot</span><span style="color: #E02020; ">{</span><span style="color: #E02020; ">}</span></pre></div></div>

<p>Here is the <a href="http://www.gradstein.info/wp-content/uploads/new-mate-in-one.pdf" class="lipdf">result, 196 pages of mate in one</a>! (<a href="http://www.gradstein.info/wp-content/uploads/new-mate-in-one.tex" class="liinternal">here is the .tex file</a>, if someone is interested)</p>
<p>Note: There are two problems left.</p>
<ul>
<li>First is that when generating the PDF, I get a lot of &#8220;<strong>Underfull \vbox (badness 10000) has occurred while \output is active</strong>&#8220;. If a LaTeX expert can take a look&#8230;</li>
<li>Second problem, I just noticed that some diagrams have the Black mate in one. I thought there were only White mate in one. So there is no way to know whose turn it is. A solution to this is to use a small coloredbox with the side to play. I think the skak module supports it. Some r<a href="ftp://ftp.inria.fr/pub/TeX/CTAN/fonts/chess/skaknew/SkakNew.pdf" class="lipdf">eading in perspective</a>&#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/kid/updated-mate-in-one-document-includes-coordinates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-provisioning with Asterisk and ST2030 Technicolor/Thomson phones</title>
		<link>http://www.gradstein.info/software/asterisk/auto-provisioning-asterisk-st2030-technicolorthomson-phones/</link>
		<comments>http://www.gradstein.info/software/asterisk/auto-provisioning-asterisk-st2030-technicolorthomson-phones/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 13:45:03 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[voip]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[autoprovisioning]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[dhcp]]></category>
		<category><![CDATA[http server]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[provisioning]]></category>
		<category><![CDATA[sip]]></category>
		<category><![CDATA[sip phones]]></category>
		<category><![CDATA[Technicolor]]></category>
		<category><![CDATA[tftp]]></category>
		<category><![CDATA[Thomson]]></category>
		<category><![CDATA[vlan]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=411</guid>
		<description><![CDATA[An introduction to the ST2030 The ST2030 is one of the few SIP phones distributed by Thomson (now changed name to Technicolor). In fact there are only 2 models: the ST2020, and the ST2030, and also a new one, the TB30, which is the successor to the ST2030. The ST2030 is supposed to have an [...]]]></description>
			<content:encoded><![CDATA[<h2 class="title">An introduction to the ST2030</h2>
<p>The ST2030 is one of the few SIP phones distributed by Thomson (now changed name to Technicolor). In fact there are only 2 models: the ST2020, and the ST2030, and also a new one, the TB30, which is the successor to the ST2030. The ST2030 is supposed to have an End-of-Life set to the end of this year (2010), but I read that its EOL has been extended to the end of 2012.<br />
In my personal experience, I think the ST2030 has the best price/functionalities/quality ratio. It has features like:</p>
<ul>
<li> PoE (Power over Ethernet).</li>
<li>Headphone plug with a button on the phone to pickup with the headphone (or if you have a compatible headphone, pickup directly with a button on the headphone).</li>
<li>XML based Directory support, that you can interface with a remote HTTP server.</li>
<li>4 differents lines/profiles (but not at the same time).</li>
<li>BLF (Busy Lamp Fields) to monitor other&#8217;s phone status (if they are using their phone, and even possibility to intercept a call).</li>
<li>Full compatibilty with Asterisk (tested on Asterisk 1.6+ and 1.8+).</li>
<li>Auto-provisioning with support for TFTP but also for HTTP/HTTPS, which simplifies quite a lot the provisioning configuration.</li>
</ul>
<p>In this document, we&#8217;ll see the auto-provisioning process through DHCP+HTTP.</p>
<p><span id="more-411"></span></p>
<p>The main web pages related on the ST2030 are the <a href="http://www.voip-info.org/wiki/view/Thomson+ST2030" class="liexternal">Voip-info.org</a> pages and the <a href="http://technicolorbroadbandpartner.com/telephony-solutions/products/product-detail.php?id=87" class="liexternal">official Technicolor/Thomson web page</a>.</p>
<h2>Requirements</h2>
<ul>
<li>Linux</li>
<li>Asterisk (1.8+)</li>
<li>Technicolor ST2030 phones</li>
<li>DHCP server</li>
<li>HTTP server (Apache, nginx)</li>
</ul>
<p><span style="font-size: 26px; line-height: 28px;">Manual upgrade of the Boot, DSP and APP firmware</span></p>
<ul>
<li>Boot your phone (yes it&#8217;s very long, 5+ minutes)</li>
<li>Long press the &#8216;menu&#8217; button, which will display the phone&#8217;s ip address</li>
</ul>
<p><a href="http://www.gradstein.info/wp-content/uploads/2010/12/300px-St2030_1.jpg" class="liimagelink"><img class="aligncenter size-full wp-image-412" title="Main console of ST2030 phones" src="http://www.gradstein.info/wp-content/uploads/2010/12/300px-St2030_1.jpg" alt="" width="300" height="271" /></a></p>
<ul>
<li>Connect to http://your_ip/admin.html and enter &#8216;<strong>administrator</strong>&#8216; as login and <strong>784518</strong> as password (the default)</li>
<li>Finally go to &#8216;Utility&#8217; tab, and upload the <strong>v2030_boot_v111.zz</strong>, <strong>v2030_dsp_R11.1_SED_v320.zz</strong> and <strong>v2030SG.R11.1.SED.100804.2.72.2.zz</strong> files (each one needs to reboot your phone, it will take a loooooong time :-)</li>
</ul>
<p>To verify that you&#8217;ve correctly upgraded your phone, go to the admin Home page, you should get something like:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">H/W Version: 	V5
 Boot Version: 	V1.11
 DSP Version: 	V3.20
 APP Version: 	V2.72</pre></div></div>

<p><span style="font-size: 26px; line-height: 28px;">Deploying ST2030 IP phones using DHCP and HTTP</span></p>
<p>This is called auto-provisioning. Normally, one use DHCP/PXE/BOOTP + TFTP to deploy servers, but it is so slow, unreliable, and the tftp protocol is so primitive, that it gets really hard when you need to deploy different phones.</p>
<p>Today, I&#8217;ll show you how to deploy ST2030 phones with only DHCP and HTTP servers, nothing more. The most useful documentation you&#8217;ll need is the &#8220;official&#8221; doc named &#8220;Auto provisioning and customization for IP Phone ST2030 and ST2022, November 16, 2009&#8243;. You can find it in the latest zip file (currently &#8220;<a href="http://technicolorbroadbandpartner.com/telephony-solutions/products/product-detail.php?id=87" class="liexternal">ST2030 SIP firmware and documents v2.72</a>&#8220;.<br />
The latest versions of these phones support provisioning not only by TFTP, but also by HTTP. I don&#8217;t know since which version of the firmware it works that way, but I advise you to upgrade to the latest version (you can also try the upgrade by provisioning, as it does the firmware upgrade too).</p>
<p>My version shows:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">Boot Version: 	V1.11
 DSP Version: 	V3.20
 APP Version: 	V2.7</pre></div></div>

<h2 class="title">Boot workflow</h2>
<p>As detailed in the official documentation, here is its workflow:</p>
<p style="text-align: center;"><a href="http://www.gradstein.info/wp-content/uploads/2010/12/800px-St2030-workflow.png" class="liimagelink"><img class="aligncenter size-full wp-image-413" title="ST2030 boot workflow" src="http://www.gradstein.info/wp-content/uploads/2010/12/800px-St2030-workflow.png" alt="" width="600" height="314" /></a></p>
<h2 class="title">Configuring the DHCP server</h2>
<p>Personnaly I use the default ISC DHCPv3 server (on Ubuntu), but it should work the same way on any implementation (not sure about MS Windows).<br />
As you can see on the workflow, we need to get in the &#8216;Option 43&#8242; state. But to get there, you need to be sure your phone is in a default/factory reset state (otherwise your phone may be setup to boot without DHCP, or not use the HTTP/TFTP data, and get it directly).</p>
<p>In your DHCP server configuration you must be sure you haven&#8217;t defined or played with the 150, 66 or 67 option codes, otherwise you&#8217;ll get into the TFTP boot workflow! If you want to be sure, or to debug your workflow, I recommend you use tcpdump, or even better, tshark. You&#8217;ll get something like that:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root<span style="color: #000000; font-weight: bold;">@</span>home:<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dhcp3<span style="color: #666666; font-style: italic;"># tshark host 10.0.8.123</span>
 Capturing on eth0
 <span style="color: #000000;">0.564814</span>     10.0.8.1 -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.0.8.123   DHCP DHCP Offer    - Transaction ID 0xf101e5e6
 <span style="color: #000000;">1.694101</span>     10.0.8.1 -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.0.8.123   DHCP DHCP ACK      - Transaction ID 0xf101e5e6
 <span style="color: #000000;">2.194885</span>     10.0.8.1 -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.0.8.123   ICMP Echo <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ping</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> request
 <span style="color: #000000;">2.195531</span>     10.0.8.123 -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.0.8.1   ICMP Echo <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ping</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> reply
 <span style="color: #000000;">8.877535</span>     10.0.8.123 -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.0.8.1   TFTP Read Request, File: provisioning<span style="color: #000000; font-weight: bold;">/</span>ST2030<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>\000, Transfer <span style="color: #7a0874; font-weight: bold;">type</span>: octet\000
 <span style="color: #000000;">8.882145</span>     10.0.8.1 -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.0.8.123   TFTP Error Code, Code: File not found, Message: File not found\000</pre></div></div>

<p>Which is BAD!</p>
<p>So edit your /<strong>etc/dhcp3/dhcpd.conf</strong> configuration file, and *REMOVE* lines like:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">option option-66 code 66 = text;
 option option-67 code 67 = text;</pre></div></div>

<p>A correct example would be:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">option option-43 code 43 = text;
 option domain-name &quot;intra.myhome.fr&quot;;
 option domain-name-servers 10.0.8.3;
&nbsp;
default-lease-time 12000;
 max-lease-time 72000;
&nbsp;
authoritative;
 log-facility local7;
&nbsp;
subnet 10.0.8.0 netmask 255.255.255.0 {
 range 10.0.8.100 10.0.8.150;
 option routers 10.0.8.254;
 option ntp-servers 192.168.100.254;
 }
 group {
  option option-43 &quot;&lt;a rel=&quot;nofollow&quot; href=&quot;http://10.0.8.165/ST2030.inf&quot;&gt;http://10.0.8.165/ST2030.inf&lt;/a&gt;&quot;;
  host test1 { hardware ethernet 00:1f:9f:86:a8:29;}
}</pre></div></div>

<p><span style="font-size: 26px; line-height: 28px;">Configuration of the HTTP server and the served files</span></p>
<p>I used NGINX as web server, but it will work equaly well with Apache2 or anything that can serve files throught HTTP.<br />
Just define a root where you will put your firmware and configuration files:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">server {
 listen   80; ## listen for ipv4
 listen   [::]:80 default ipv6only=on; ## listen for ipv6
 server_name  localhost;
 access_log  /var/log/nginx/provisioning.access.log;
&nbsp;
location / {
 root   /var/www;
 index  index.html index.htm;
 autoindex on;
 allow 10.0.0.0/16;
 }</pre></div></div>

<p>After uncompressing the firmware files (from the ZIP), the directory structure in your web root should be the following:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">root@monserveur:/var/www# tree
 .
 .-- nginx-default
 .   .-- 50x.html
 .   .-- index.html
 .-- provisioning
 .   .-- ST2030
 .       .-- config
 .       .   .-- ComConf2030SG.R11.1.SED.100804.2.72.2.txt
 .       .   .-- ST2030S_001F9F16A849.txt
 .       .-- data
 .           .-- LangTbl.zz
 .           .-- TelConf2030SG.R11.1.SED.100804.2.72.2.txt
 .           .-- Tone-CW.txt
 .           .-- Tone-Melodies.txt
 .           .-- Tone-RG.txt
 .           .-- ToneTbl.zz
 .           .-- v2030_boot_v111.zz
 .           .-- v2030_dsp_R11.1_SED_v320.zz
 .           .-- v2030SG.R11.1.SED.100804.2.72.2.zz
 .-- ST2030.inf</pre></div></div>

<p>The most important file is the <strong>ST2030.inf</strong> file (you can find a default file named &#8216;<strong>ST2030S-ip.inf</strong>&#8216; in the ZIP. The goal of this file is to define where to get all the following files (firmware and configuration files). Mine looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">[application]
 fwurl=http://10.0.8.165/provisioning/ST2030/data/v2030SG.R11.1.SED.100804.2.72.2.zz
 dspurl=http://10.0.8.165/provisioning/ST2030/data/v2030_dsp_R11.1_SED_v320.zz
 booturl=http://10.0.8.165/provisioning/ST2030/data/v2030_boot_v111.zz
&nbsp;
[config]
 telcfg=http://10.0.8.165/provisioning/ST2030/data/TelConf2030SG.R11.1.SED.100804.2.72.2.txt
 common_config=http://10.0.8.165/provisioning/ST2030/config/ComConf2030SG.R11.1.SED.100804.2.72.2.txt
&nbsp;
melodies=http://10.0.8.165/provisioning/ST2030/data/Tone-Melodies.txt
 system_melodies=http://10.0.8.165/provisioning/ST2030/data/Tone-RG.txt
 call_waiting_tone=http://10.0.8.165/provisioning/ST2030/data/Tone-CW.txt
&nbsp;
tone_table=http://10.0.8.165/provisioning/ST2030/data/ToneTbl.zz
 language_table=http://10.0.8.165/provisioning/ST2030/data/LangTbl.zz
&nbsp;
config=http://10.0.8.165/provisioning/ST2030/config/</pre></div></div>

<p>All your phone specific files will be looked according to the &#8216;config&#8217; variable. Here, it&#8217;s &#8216;<strong>/provisioning/ST2030/config/</strong>&#8216;, where it will look for <strong>ST2030S_ .txt</strong> (the &#8216;S&#8217; is for SIP).</p>
<p>Before you boot you phone(s), you should at least configure your common file (<strong>ComConf2030SG.R11.1.SED.100804.2.72.2.txt</strong>) to most used values. Then add a file named <strong>ST2030S_ .txt</strong> where you put only the differences with that common file. One of mine&#8217;s looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">[ipp]
 TimeFlag=1
 LanguageType=1
&nbsp;
[sip]
 RegisterServerMP1=10.0.8.165
 ProxyServerMP1=10.0.8.165
 ServiceDomainMP1=10.0.8.165
&nbsp;
RegisterServerBK1=10.0.3.1
 ProxyServerBK1=10.0.3.1
 ServiceDomainBK1=10.0.3.1
&nbsp;
TEL1Number=1001
 DisplayName1=Telephone 1001
 regid1=1001
 regpwd1=1234
&nbsp;
CallPkupSC=*8X
 AuthMessageServer=10.0.8.165
&nbsp;
[net]
 TelnetTime=240
 TelnetSrv=1
 VLAN=0
&nbsp;
[sys]
 CodecJitterBufMult=g711a(2/3/7)g711mu(1/3/5)g729(2/3/4)g723(1/2/3)
 CodecPktime=g711a(20)g711mu(20)g729(30)g723(30)
 CodecPriority=g711a(1)g711mu(2)g729(3)g723(4)
 CodecAdaptivePlayout=g711a(1)g711mu(1)g729(1)g723(1)
 Current_Max_Multiline=5
 TelnetID=administrator
 TelnetPWD=789234
 CountryCode=FR
 config_sn=201007300008
 FeatureKeyExt01=L/
 FeatureKeyExt02=L/
 FeatureKeyExt03=L/
 FeatureKeyExt04=L/
 FeatureKeyExt05=L/
 FeatureKeyExt06=L/
 FeatureKeyExt07=L/
 FeatureKeyExt08=S/
 FeatureKeyExt09=S/
 FeatureKeyExt10=S/
 Phonebook1_url=http://myhomeserver.mydomain.fr:8000/search?q=#SEARCH
 Phonebook1_name=My phone book
&nbsp;
[autoprovision]
 AutoprovisionFlag=1
 AutoprovisionHTTPServer=
 AutoprovisionTFTPServer=
 AutoprovisionTimeDays=0
 Autoprovisionstarttime=00:00
 AutoprovisionTimeSpan=0
 AutoprovisionRetryPeriod=30
 Decryption_Key=Th0mson2$8s8@9z!
&nbsp;
[ntp]
 NtpDaylight=1
 NTPFlag=1
 NtpIP=10.0.1.44
 NtpZoneNum=22</pre></div></div>

<p>This file has NTP and several other parameters adjusted for french infos/timezone. Another note, please take great details when editing this file, as any mistake, will make it be skipped by the phone boot process. Also, don&#8217;t forget to increase/modify the &#8216;config_sn&#8217; attribute (<em><strong>attention, that attribute *MUST* be 12 digits long, i.e. 201007300008</strong></em>).</p>
<h2 class="title">Boot workflow</h2>
<p>To force a firmware update/workflow from scratch, you can click the &#8216;restore default&#8217; button in the phone web interface, or, when the phone starts (unplug/plug the power supply/network cable for PoE), press and hold down the headset and mute buttons.</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">GET /ST2030.inf HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/v2030SG.R11.1.SED.100804.2.72.2.zz HTTP/1.1 200
 GET /provisioning/ST2030/data/v2030_dsp_R11.1_SED_v320.zz HTTP/1.1 200
 GET /provisioning/ST2030/data/v2030_boot_v111.zz HTTP/1.1 200</pre></div></div>

<p>Here, it gets the main configuration file, ST2030.inf, and, from it, the APP, DSP and BOOT firmwares.</p>
<p>The phone reboots&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">GET /ST2030.inf HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/Tone-Melodies.txt HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/Tone-RG.txt HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/Tone-CW.txt HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/ToneTbl.zz HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/LangTbl.zz HTTP/1.1&quot; 200
 GET /provisioning/ST2030/data/TelConf2030SG.R11.1.SED.100804.2.72.2.txt HTTP/1.1&quot; 200
 GET /provisioning/ST2030/config/ComConf2030SG.R11.1.SED.100804.2.72.2.txt HTTP/1.1&quot; 200
 GET /provisioning/ST2030/config/ST2030S_001F9F16E849.ser HTTP/1.1&quot; 404
 GET /provisioning/ST2030/config/ST2030S_001F9F16E849.txt HTTP/1.1&quot; 200</pre></div></div>

<p>Here, it gets the common configuration files for the phone, and looks for a file the the phone&#8217;s MAC address name (ST2030S_001F9F16E849.txt).<br />
The phone reboots&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">GET /ST2030.inf HTTP/1.1&quot; 200
 GET /provisioning/ST2030/config/ST2030S_001F9F16E849.ser HTTP/1.1&quot; 404
 GET /provisioning/ST2030/config/ST2030S_001F9F16E849.txt HTTP/1.1&quot; 200</pre></div></div>

<p>When there is no modification, you&#8217;ll get the following HTTP request on your server (if you want to force a firmware update/workflow from scratch, you can click the &#8216;restore default&#8217; button in the web interface, or, when the phone boots, press and hold down the headset and mute buttons)</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">GET /ST2030.inf HTTP/1.1 200
 GET /provisioning/ST2030/config/ST2030S_001F9F16E849.ser HTTP/1.1 404
 GET /provisioning/ST2030/config/ST2030S_001F9F16E849.txt HTTP/1.1 200</pre></div></div>

<p>Here, as you can see with the 404 error code, the ST2030S_001F9F16E849.ser is missing, but that&#8217;s normal. This file only exists if you encrypt your configuration file (tools available in the zip file). So it&#8217;s the same as the .txt file, but encrypted.</p>
<p>So , to summarize the workflow, the phone gets an IP address from the DHCP, and also the url to get the main configuration, throught the option-43 DHCP attribute.</p>
<p>Another way to find out what went wrong, is to look at the APS logs, which are available on the web phone&#8217;s GUI, in the &#8216;setup&#8217; menu, option &#8216;APS Log&#8217;:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">Autoprovision Process start
 Begin General file download...
 General file: ST2030.inf download successfully!
 Begin Firmware download...
 Firmware filename is the same!
 Begin DSP download...
 DSP filename is the same!
 Begin Boot Code download...
 BOOT code filename is the same!
 Begin Melody download...
 Begin Common Config download...
 Common Config filename is the same!
 Begin Mac config download...
 Error: provisioning/ST2030/config/ST2030S_001F9F16E849.ser file not found!
 Now will try to search txt file!
 MacConfig: provisioning/ST2030/config/ST2030S_001F9F16E849.txt download successfully!
 Serial number is not the same!
 Begin upgrading config file...
 Check config file syntax
 Check config file syntax successfully!
 Upgrading config file successfully!
 Reboot.....
 [...]
 Begin General file download...
 General file: ST2030.inf download successfully!
 Begin Firmware download...
 Firmware filename is the same!
 Begin DSP download...
 Begin Telephone Config download...
 Telephone config filename is the same!
 Begin Common Config download...
 Common Config filename is the same!
 Begin Mac config download...
 Error: provisioning/ST2030/config/ST2030S_001F9F16E849.ser file not found!
 Now will try to search txt file!
 MacConfig: provisioning/ST2030/config/ST2030S_001F9F16E849.txt download successfully!
 Serial number is the same!
 Begin upgrading config file...
 No upgrading config file required...
 Autoprovision Process End</pre></div></div>

<p><strong><span style="text-decoration: underline;">Update:</span></strong> One last note, when you edit/update your MAC named file, do not forget to update/increment the config_sn file, otherwise the phone will think the data hasn&#8217;t changed!</p>
<p>Now, to finish, you just have to create a new file (named with a MAC address) for each of your phones. In the next article, I&#8217;ll show you how to make Asterisk do it for you, all automatically, from sip.conf&#8217;s files!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/software/asterisk/auto-provisioning-asterisk-st2030-technicolorthomson-phones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Default behaviour in implementation of STOMP protocol in RabbitMQ with python</title>
		<link>http://www.gradstein.info/python/default-behaviour-implementation-stomp-protocol-rabbitmq-python/</link>
		<comments>http://www.gradstein.info/python/default-behaviour-implementation-stomp-protocol-rabbitmq-python/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 15:51:39 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[network]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rabbitmq]]></category>
		<category><![CDATA[Advanced Message Queuing Protocol]]></category>
		<category><![CDATA[amqp]]></category>
		<category><![CDATA[consumers]]></category>
		<category><![CDATA[direct]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Internet protocols]]></category>
		<category><![CDATA[one]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[round-robin]]></category>
		<category><![CDATA[stomp]]></category>
		<category><![CDATA[stompy]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=368</guid>
		<description><![CDATA[Why STOMP? Why STOMP, and not directly AMQP, as I&#8217;m using RabbitMQ. No real reason, but the fact that there are less dependencies on a STOMP client, as it&#8217;s just a socket with text sent. Implementations There are several implementations of the STOMP protocol for Python. The module I chose is python-stomp (version 0.2.9), from [...]]]></description>
			<content:encoded><![CDATA[<h2>Why STOMP?</h2>
<p>Why STOMP, and not directly AMQP, as I&#8217;m using RabbitMQ. No real reason, but the fact that there are less dependencies on a STOMP client, as it&#8217;s just a socket with text sent.</p>
<h2>Implementations</h2>
<p>There are <a href="http://pypi.python.org/pypi?%3Aaction=search&#038;term=stomp&#038;submit=search" class="liexternal">several implementations</a> of the STOMP protocol for Python. The module I chose is <a href="http://pypi.python.org/pypi/stompy/" class="liexternal">python-stomp</a> (version 0.2.9), from Benjamin W. Smith. It&#8217;s simple and easy to understand.</p>
<h2>Simple Code Examples</h2>
<p>sto_send.py:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> stompy.<span style="color: black;">simple</span> <span style="color: #ff7700;font-weight:bold;">import</span> Client
&nbsp;
stomp = Client<span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">'rabbitmq2'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'guest'</span>,password=<span style="color: #483d8b;">'noneofyourbusiness'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">put</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Thomas est une b*te à Tetris...'</span>, destination=<span style="color: #483d8b;">'/queue/jeuvideo'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">disconnect</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>sto_receive.py:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> stompy.<span style="color: black;">simple</span> <span style="color: #ff7700;font-weight:bold;">import</span> Client
&nbsp;
stomp = Client<span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">'rabbitmq2'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'guest'</span>,password=<span style="color: #483d8b;">'noneofyourbusiness'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">subscribe</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/queue/jeuvideo'</span><span style="color: black;">&#41;</span>
message = stomp.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> message.<span style="color: black;">body</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#stomp.ack(message)</span>
stomp.<span style="color: black;">unsubscribe</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/queue/video'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">disconnect</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Everything is working fine, when launching sto_receive.py, I receive the message. But when I launched several receivers, I noticed, that ONLY ONE programs received the message! After some research, I found the answer: As documented <a href="https://dev.rabbitmq.com/wiki/StompGateway" class="liexternal">in the RabbitMQ wiki</a>, the default exchange is &#8216;direct&#8217;:</p>
<blockquote><p>[...]when messages leave a queue for a consumer, they are not duplicated. One message, sitting on a queue, is delivered to only one of the available consumers. [...] If there are multiple clients, all SUBSCRIBEing to the same queue, then there will be multiple consumers all on the same queue, leading to round-robin delivery to those clients.</p></blockquote>
<p>There is <a href="https://dev.rabbitmq.com/wiki/StompGateway" class="liexternal">an explanation</a> on how to change the behaviour, by changing the exchange type, and some of particular bits (like the id). I even found <a href="http://github.com/dcarley/mcollective-plugins/commit/4801dda81cdb7fca2fc3f87efdcc3295d497e973" class="liexternal">an example of modification</a> for use in the equivalent <a href="http://rubygems.org/gems/stomp" class="liexternal">STOMP Ruby module</a>.</p>
<p>Here are the modifications. The good news is that there is no need to patch the stompy module, as the author provided the possibility to pass arbitrary parameters to the headers by the use of the &#8216;conf&#8217; variable. </p>
<p>The important points are:</p>
<ul>
<li>You need to define an exchange of type amq.topic</li>
<li>You need to set an id, which is different for each client</li>
<li>As you&#8217;re using topics, you&#8217;ll have to specify a routing_key</li>
</ul>
<p>sto_receive.py:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> stompy.<span style="color: black;">simple</span> <span style="color: #ff7700;font-weight:bold;">import</span> Client
<span style="color: #ff7700;font-weight:bold;">import</span> uuid
&nbsp;
unique_id = uuid.<span style="color: black;">uuid4</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
stomp = Client<span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">'rabbitmq2'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'guest'</span>,password=<span style="color: #483d8b;">'nonononono'</span><span style="color: black;">&#41;</span>
&nbsp;
stomp.<span style="color: black;">subscribe</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
                conf=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'exchange'</span>: <span style="color: #483d8b;">'amq.topic'</span>,
                      <span style="color: #483d8b;">'routing_key'</span>:<span style="color: #483d8b;">'x.#'</span>,
                      <span style="color: #483d8b;">'id'</span>: unique_id,
                      <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Wait for a message to appear</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
    message = stomp.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> message.<span style="color: black;">body</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#stomp.ack(message)</span>
stomp.<span style="color: black;">unsubscribe</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,conf=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'id'</span>: unique_id<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">disconnect</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>sto_send.py:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> stompy.<span style="color: black;">simple</span> <span style="color: #ff7700;font-weight:bold;">import</span> Client
&nbsp;
&nbsp;
&nbsp;
stomp = Client<span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">'rabbitmq2'</span><span style="color: black;">&#41;</span>
stomp.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'guest'</span>,password=<span style="color: #483d8b;">'nonononono'</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10000</span><span style="color: black;">&#41;</span>:
 stomp.<span style="color: black;">put</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Thomas est une b*te au Tetris...'</span>, destination=<span style="color: #483d8b;">'x.y'</span>,
          conf=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'exchange'</span>:<span style="color: #483d8b;">'amq.topic'</span>,
                <span style="color: #808080; font-style: italic;">#  'routing_key':'x.y'</span>
                <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
&nbsp;
stomp.<span style="color: black;">disconnect</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/default-behaviour-implementation-stomp-protocol-rabbitmq-python/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Puppet: Files found in modules without specifying &#8216;modules&#8217; in file path will be deprecated in the next major release</title>
		<link>http://www.gradstein.info/network/puppet-files-modules-modules-file-path-deprecated-major-release/</link>
		<comments>http://www.gradstein.info/network/puppet-files-modules-modules-file-path-deprecated-major-release/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 14:11:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[network]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[deprecation]]></category>
		<category><![CDATA[notice]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=351</guid>
		<description><![CDATA[DEPRECATION NOTICE: Files found in modules without specifying &#8216;modules&#8217; in file path will be deprecated in the next major release. If you get this warning in your puppet logs, you should take action (only if you don&#8217;t have any Puppet agent with a version]]></description>
			<content:encoded><![CDATA[<blockquote><p>DEPRECATION NOTICE: Files found in modules without specifying &#8216;modules&#8217; in file path will be deprecated in the next major release.
</p></blockquote>
<p>If you get this warning in your puppet logs, you should take action (only if you don&#8217;t have any Puppet agent with a version <= 0.24) and modify all you references to file resources.<br />
For example, if you have a module named 'ssh', normally, up to puppet 0.25 you would reference a file to it as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">source <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;puppet:///ssh/authorized_keys&quot;</span>,<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>But now, you need to insert a &#8216;module&#8217; identifier in between like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">source <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;puppet:///modules/ssh/authorized_keys&quot;</span>,<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p><em>Just a small note: It seems that the templates do not need any modification.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/network/puppet-files-modules-modules-file-path-deprecated-major-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where do I find pngout for Linux?</title>
		<link>http://www.gradstein.info/software/where-do-i-find-pngout-for-linux/</link>
		<comments>http://www.gradstein.info/software/where-do-i-find-pngout-for-linux/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 17:11:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=290</guid>
		<description><![CDATA[I just found a nice comparison chart of different compression programs for PNG images (optimizations). It seems that PNGout is the best of the best :-) On the author&#8217;s website, there&#8217;s only a windows version. The link to the Linux version gets redirected to a gtagaming website?! After asking the great oracle Google where I [...]]]></description>
			<content:encoded><![CDATA[<p>I just found a <a href="http://www.olegkikin.com/png_optimizers/" class="liexternal">nice comparison chart of different compression programs</a> for PNG images (optimizations). It seems that PNGout is the best of the best :-) On the author&#8217;s website, there&#8217;s only a windows version. The link to the Linux version gets redirected to a gtagaming website?!<br />
After asking the great oracle Google where I could find a version for Linux, he replied to me I could find it on <a href="http://www.jonof.id.au/pngout" class="liexternal">JonoF&#8217;s website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/software/where-do-i-find-pngout-for-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asterisk: DADHI module not working when using Xen</title>
		<link>http://www.gradstein.info/software/asterisk/asterisk-dadhi-module-not-working-when-using-xen/</link>
		<comments>http://www.gradstein.info/software/asterisk/asterisk-dadhi-module-not-working-when-using-xen/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 11:30:54 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[voip]]></category>
		<category><![CDATA[digium]]></category>
		<category><![CDATA[hardware card]]></category>
		<category><![CDATA[rtc]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=224</guid>
		<description><![CDATA[If you want to use any Asterisk module that needs a timer, like MeetMe, you have to use a module named dahdi (previously named zaptel). DAHDI has one module for each Digium supported card (B410P), and a dummy module (named dahdi_dummy) if you don&#8217;t have a hardware card, like me. The problem appears when you [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to use any <a href="http://www.asterisk.org/" class="liexternal">Asterisk</a> module that needs a timer, like MeetMe, you have to use a module named dahdi (previously named zaptel). DAHDI has one module for each Digium supported card (B410P), and a dummy module (named dahdi_dummy) if you don&#8217;t have a hardware card, like me.</p>
<p>The problem appears when you have your Asterisk in a Xen environment. Xen does not allow the use of the RTC, so when using Dahdi/meetme, you get the following in you logs:</p>
<blockquote><p>res_timing_dahdi.c: Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection.</p></blockquote>
<p>So get the sources, and let&#8217;s patch it!</p>
<p><code>svn co  http://svn.digium.com/svn/dahdi/linux-complete/trunk DAHDI</code></p>
<p>In dahdi_dummy.c, you&#8217;ll have to comment the two defines USE_RTC, as in a Xen, you can&#8217;t use it:</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;"># diff -u dahdi_dummy.c.ori dahdi_dummy.c
<span style="color: #888822;">--- dahdi_dummy.c.ori	2009-03-23 09:50:36.000000000 +0000</span>
<span style="color: #888822;">+++ dahdi_dummy.c	2009-03-23 08:55:38.000000000 +0000</span>
<span style="color: #440088;">@@ -59,11 +59,11 @@</span>
 #if defined<span style="">&#40;</span>CONFIG_HIGH_RES_TIMERS<span style="">&#41;</span> &amp;&amp; LINUX_VERSION_CODE &gt;= VERSION_CODE<span style="">&#40;</span><span style="">2</span>,<span style="">6</span>,<span style="">22</span><span style="">&#41;</span>
 #define USE_HIGHRESTIMER
 #else
<span style="color: #991111;">-#define USE_RTC</span>
<span style="color: #00b000;">+//#define USE_RTC</span>
 #endif
 #else
 #if <span style="">0</span>
<span style="color: #991111;">-#define USE_RTC</span>
<span style="color: #00b000;">+//#define USE_RTC</span>
 #endif
 #endif
 #endif</pre></div></div>

<p>Then compile the module, as usual, with :</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">/etc/init.d/dahdi stop
make all
make install
make config</pre></div></div>

<p>Verify that your module has been correctly installed:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">ls -al ./2.6.24-19-xen/dahdi/dahdi_dummy.ko</pre></div></div>

<p>Comment out all the defined modules in the /etc/dahdi/modules file.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">/etc/init.d/dahdi start
# dmesg
1007539.576458] dahdi: Telephony Interface Registered on major 196
[1007539.576468] dahdi: Version: SVN-trunk-r6201M
[1007540.642839] dahdi: Registered tone zone 2 (France)</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/software/asterisk/asterisk-dadhi-module-not-working-when-using-xen/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Django: How to find the url/path you&#8217;re into, in a template loaded by a generic view</title>
		<link>http://www.gradstein.info/python/django-how-to-find-the-urlpath-youre-into-in-a-template-loaded-by-a-generic-view/</link>
		<comments>http://www.gradstein.info/python/django-how-to-find-the-urlpath-youre-into-in-a-template-loaded-by-a-generic-view/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 22:11:39 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=197</guid>
		<description><![CDATA[In a Django project, I have a template that is used by two urls, which is quite common (generic views, using &#8216;create_object&#8217; and &#8216;update_object&#8217;). The problem is that I had to add a supplementary menu just when the template is loaded from the &#8216;update&#8217; generic view, and not from the &#8216;create&#8217; generic view. Making the [...]]]></description>
			<content:encoded><![CDATA[<p>In a Django project, I have a template that is used by two urls, which is quite common (generic views, using &#8216;create_object&#8217; and &#8216;update_object&#8217;). The problem is that I had to add a supplementary menu just when the template is loaded from the &#8216;update&#8217; generic view, and not from the &#8216;create&#8217; generic view.</p>
<p>Making the difference between the two urls calls at the template level is a problem because it&#8217;s managed by generic views, so the same template is used.</p>
<p>Anyways, there are several possibilities:</p>
<p>In urls.py, use the <a href="http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-create-update-create-object" class="liexternal">&#8216;template_name&#8217; variable</a>, where you can speficy a specific template for this url(). That is instead of using the default &lt;model&gt;_form.html.<br />
What I don&#8217;t like in this situation, is that I will have two nearly similar templates, just for an added menu. Not cool. Another problem is that I use <a href="http://code.djangoproject.com/wiki/GenerateGenericURLs" class="liexternal">a loop to create all my urls</a>. So if I add a special template, I&#8217;ll add it to <strong>ALL my models</strong> :-(.</p>
<p>Another solution, is to find a way to use a variable in the template that would be different wether the template has been loaded by update_object or create_object.</p>
<p>In our urlpatterns in urls.py, we can use the &#8216;<strong>extra_context</strong>&#8216; variable (takes a <a href="http://docs.djangoproject.com/en/dev/ref/generic-views/?from=olddocs#django-views-generic-create-update-create-object" class="liexternal">dictionnary as parameter</a>). It is correctly managed, even when using generic views. So, you&#8217;ll have :</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'foo/ajouter/$'</span>, <span style="color: #483d8b;">'django.views.generic.create_update.create_object'</span>,  
		<span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>form_class=modelForm,
                extra_context=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'usage'</span>:<span style="color: #483d8b;">'create'</span><span style="color: black;">&#125;</span>,
                name=<span style="color: #483d8b;">'foo_create'</span>,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'foo/%s/(?P&lt;object_id&gt;<span style="color: #000099; font-weight: bold;">\d</span>+)/modifier/$'</span>,
                <span style="color: #483d8b;">'django.views.generic.create_update.update_object'</span>,
		<span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>form_class=modelForm,
                extra_context=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'usage'</span>:<span style="color: #483d8b;">'modify'</span><span style="color: black;">&#125;</span>,
                name=<span style="color: #483d8b;">'foo_update'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>We can also use, in urls.py, the <a href="http://docs.djangoproject.com/en/dev/ref/generic-views/?from=olddocs#django-views-generic-create-update-create-object" class="liexternal">&#8216;context_processors&#8217; variable</a>. For more information about the context processors, have <a href="http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/" class="liexternal">a look at this tutorial</a>. The goal is to add &#8216;django.core.context_processors.request&#8217;, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">context_processors</span> <span style="color: #ff7700;font-weight:bold;">import</span> request</pre></div></div>

<p>and in the url(), add context_processors:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'foo/ajouter/$'</span>, <span style="color: #483d8b;">'django.views.generic.create_update.create_object'</span>,  
		<span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>form_class=modelForm,
		context_processors=<span style="color: black;">&#91;</span>request,<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,
                name=<span style="color: #483d8b;">'foo_create'</span>,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The last possiblity is a more global solution. It&#8217;s like the context_processors usage above, but added into every templates automatically.<br />
To do this, you&#8217;ll have to edit the list of Template Processors in your settings.py file. That list is run each time a template is loaded, and allows one to add any variable to the template automatically. By default (on Django 1.0.x) this list is commented out, so it has by <a href="http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEMPLATE_CONTEXT_PROCESSORS" class="liexternal">default the list</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;django.core.context_processors.auth&quot;</span>,
<span style="color: #483d8b;">&quot;django.core.context_processors.debug&quot;</span>,
<span style="color: #483d8b;">&quot;django.core.context_processors.i18n&quot;</span>,
<span style="color: #483d8b;">&quot;django.core.context_processors.media&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>You&#8217;ll have to uncomment it, and add &#8216;django.core.context_processors.request&#8217;. By doing this, you get the variable &#8216;request.path&#8217; available in your template.</p>
<p>Finally, you&#8217;ll be able to test your variable with {% ifequal %} and display your conditional elements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/django-how-to-find-the-urlpath-youre-into-in-a-template-loaded-by-a-generic-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asterisk cirpack problem with Free and freephonie.net</title>
		<link>http://www.gradstein.info/software/asterisk/asterisk-cirpack-problem-with-free-and-freephonienet/</link>
		<comments>http://www.gradstein.info/software/asterisk/asterisk-cirpack-problem-with-free-and-freephonienet/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 09:34:51 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[voip]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[cirpack]]></category>
		<category><![CDATA[correction]]></category>
		<category><![CDATA[france]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[free isp provider]]></category>
		<category><![CDATA[freephonie.net]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[provider]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=179</guid>
		<description><![CDATA[If you configured your Asterisk/FreeSWITCH server to talk to your freephonie.net (french Free ISP provider), you&#8217;ll see in the logs the following warning message: [Feb 12 09:29:06] WARNING[9228]: chan_sip.c:6624 determine_firstline_parts: Bad request protocol Packet This is not really a problem, but an annoyance, as it fills up your logs. This is a known problem for [...]]]></description>
			<content:encoded><![CDATA[<p>If you configured your Asterisk/FreeSWITCH server to talk to your freephonie.net (french Free ISP provider), you&#8217;ll see in the logs the following warning message:<br />
<code>[Feb 12 09:29:06] WARNING[9228]: chan_sip.c:6624 determine_firstline_parts: Bad request protocol Packet</code></p>
<p>This is not really a problem, but an annoyance, as it fills up your logs. This is a <a href="http://bugs.digium.com/view.php?id=7261&#038;nbn=6" class="liexternal">known problem</a> for more than years, but has never been corrected (neither by Asterisk nor by Cirpack devs). The usual correction was to add the following line to your startup scripts (/etc/rc.local on Debian for example):<br />
<code>iptables -A INPUT -p udp -m udp --dport 5060 -m string --string "Cirpack KeepAlive Packet" -j DROP</code></p>
<p>But the syntax has changed in iptables, and you&#8217;ll get the error:<br />
<code>iptables v1.3.6: STRING match: You must specify `--algo'</code></p>
<p>so, just add one of the 2 available algorithms (bm and kmp):<br />
<code>iptables -A INPUT -p udp -m udp --dport 5060 -m string --string "Cirpack KeepAlive Packet" --algo bm -j DROP<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/software/asterisk/asterisk-cirpack-problem-with-free-and-freephonienet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python snippet to get Mediawiki/Wikipedia Recent Changes externally</title>
		<link>http://www.gradstein.info/python/python-snippet-to-get-mediawikiwikipedia-recent-changes-externally/</link>
		<comments>http://www.gradstein.info/python/python-snippet-to-get-mediawikiwikipedia-recent-changes-externally/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 23:37:35 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[rc]]></category>
		<category><![CDATA[recent changes]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[wikipedia]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=94</guid>
		<description><![CDATA[Mediawiki allows one to send Recent Changes (RC) to a UDP port. The ip address is defined by the variable wgRC2UDPAddress, and the port by the variable wgRC2UDPPort. It&#8217;s a really good idea that it&#8217;s a UDP transfer, since there is no need for any ACK, so Mediawiki doesn&#8217;t block if there is nothing listening [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mediawiki.org/" class="liexternal">Mediawiki</a> allows one to <a href="http://wikitech.wikimedia.org/view/IRCD" class="liexternal">send Recent Changes</a> (RC) to a UDP port.<br />
The ip address is defined by the variable wgRC2UDPAddress, and the port by the variable wgRC2UDPPort. It&#8217;s a really good idea that it&#8217;s a UDP transfer, since there is no need for any ACK, so Mediawiki doesn&#8217;t block if there is nothing listening on that port.</p>
<p>These parameters must be set in the LocalSettings.php file, like this, for example.</p>
<p><code>$wgRC2UDPAddress = '127.0.0.1';<br />
$wgRC2UDPPort = 9390;<br />
</code></p>
<p>I wrote a really simple python program (more a proof of concept) that receives the data, cleans it, and then prints it to stdout :</p>
<p><code>#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
#<br />
# vim:syntax=python:sw=4:ts=4:expandtab<br />
import SocketServer<br />
import re</p>
<p>HOST,PORT = '', 9390</p>
<p>class MyUDPHandler(SocketServer.BaseRequestHandler):<br />
   def handle(self):<br />
       print re.sub(r'\x03\d{0,2}', '', self.request[0])</p>
<p>if __name__ == '__main__':<br />
   server = SocketServer.UDPServer((HOST, PORT), MyUDPHandler)<br />
   server.serve_forever()</code></p>
<p>I plan to make it into a complete project that will send the data/notifications using Jabber(XMPP).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/python-snippet-to-get-mediawikiwikipedia-recent-changes-externally/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using memcached

Served from: www.stepniewski.fr @ 2012-02-06 07:52:46 -->
