<?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>Lior Gradstein'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, 13 May 2010 09:46:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>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 could [...]]]></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>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></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 have [...]]]></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>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">svn co &nbsp;http://svn.<span style="color: black;">digium</span>.<span style="color: black;">com</span>/svn/dahdi/linux-complete/trunk DAHDI</div>
<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>
<p><source lang="diff"><br />
# diff -u dahdi_dummy.c.ori dahdi_dummy.c<br />
&#8212; dahdi_dummy.c.ori	2009-03-23 09:50:36.000000000 +0000<br />
+++ dahdi_dummy.c	2009-03-23 08:55:38.000000000 +0000<br />
@@ -59,11 +59,11 @@<br />
 #if defined(CONFIG_HIGH_RES_TIMERS) &#038;&#038; LINUX_VERSION_CODE >= VERSION_CODE(2,6,22)<br />
 #define USE_HIGHRESTIMER<br />
 #else<br />
-#define USE_RTC<br />
+//#define USE_RTC<br />
 #endif<br />
 #else<br />
 #if 0<br />
-#define USE_RTC<br />
+//#define USE_RTC<br />
 #endif<br />
 #endif<br />
 #endif<br />
</source></p>
<p>Then compile the module, as usual, with :</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">/etc/init.<span style="color: black;">d</span>/dahdi stop<br />
make all<br />
make install<br />
make config</div>
<p>Verify that your module has been correctly installed:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">ls -<span style="color: #dc143c;">al</span> ./<span style="color: #ff4500;">2.6</span><span style="color: #ff4500;">.24</span><span style="color: #ff4500;">-19</span>-xen/dahdi/dahdi_dummy.<span style="color: black;">ko</span></div>
<p>Comment out all the defined modules in the /etc/dahdi/modules file.</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">/etc/init.<span style="color: black;">d</span>/dahdi start<br />
<span style="color: #808080; font-style: italic;">#&amp;gt; dmesg</span><br />
<span style="color: #ff4500;">1007539.576458</span><span style="color: black;">&#93;</span> dahdi: Telephony Interface Registered on major <span style="color: #ff4500;">196</span><br />
<span style="color: black;">&#91;</span><span style="color: #ff4500;">1007539.576468</span><span style="color: black;">&#93;</span> dahdi: Version: SVN-trunk-r6201M<br />
<span style="color: black;">&#91;</span><span style="color: #ff4500;">1007540.642839</span><span style="color: black;">&#93;</span> dahdi: Registered tone zone <span style="color: #ff4500;">2</span> <span style="color: black;">&#40;</span>France<span style="color: black;">&#41;</span></div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.gradstein.info/python/how-to-dial-a-number-using-asterisk-and-python/" title="How to dial a number using Asterisk and Python (December 17, 2008)">How to dial a number using Asterisk and Python</a> (1)</li>
	<li><a href="http://www.gradstein.info/software/asterisk/asterisk-cirpack-problem-with-free-and-freephonienet/" title="Asterisk cirpack problem with Free and freephonie.net (February 12, 2009)">Asterisk cirpack problem with Free and freephonie.net</a> (0)</li>
</ul>

]]></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 difference [...]]]></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="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&#8216;foo/ajouter/$&#8217;</span>, <span style="color: #483d8b;">&#8216;django.views.generic.create_update.create_object&#8217;</span>, &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>form_class=modelForm,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extra_context=<span style="color: black;">&#123;</span><span style="color: #483d8b;">&#8216;usage&#8217;</span>:<span style="color: #483d8b;">&#8216;create&#8217;</span><span style="color: black;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=<span style="color: #483d8b;">&#8216;foo_create&#8217;</span>,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></p>
<p>url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&#8216;foo/%s/(?P&lt;object_id&gt;<span style="color: #000099; font-weight: bold;">\d</span>+)/modifier/$&#8217;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&#8216;django.views.generic.create_update.update_object&#8217;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>form_class=modelForm,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extra_context=<span style="color: black;">&#123;</span><span style="color: #483d8b;">&#8216;usage&#8217;</span>:<span style="color: #483d8b;">&#8216;modify&#8217;</span><span style="color: black;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=<span style="color: #483d8b;">&#8216;foo_update&#8217;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></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="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><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</div>
<p>and in the url(), add context_processors:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&#8216;foo/ajouter/$&#8217;</span>, <span style="color: #483d8b;">&#8216;django.views.generic.create_update.create_object&#8217;</span>, &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>form_class=modelForm,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context_processors=<span style="color: black;">&#91;</span>request,<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=<span style="color: #483d8b;">&#8216;foo_create&#8217;</span>,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></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="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;django.core.context_processors.auth&quot;</span>,<br />
<span style="color: #483d8b;">&quot;django.core.context_processors.debug&quot;</span>,<br />
<span style="color: #483d8b;">&quot;django.core.context_processors.i18n&quot;</span>,<br />
<span style="color: #483d8b;">&quot;django.core.context_processors.media&quot;</span><span style="color: black;">&#41;</span></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>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></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:
&#91;Feb 12 09:29:06&#93; WARNING&#91;9228&#93;: 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 more than [...]]]></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:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: black;">&#91;</span>Feb <span style="color: #ff4500;">12</span> <span style="color: #ff4500;">09</span>:<span style="color: #ff4500;">29</span>:<span style="color: #ff4500;">06</span><span style="color: black;">&#93;</span> WARNING<span style="color: black;">&#91;</span><span style="color: #ff4500;">9228</span><span style="color: black;">&#93;</span>: chan_sip.<span style="color: black;">c</span>:<span style="color: #ff4500;">6624</span> determine_firstline_parts: Bad request protocol Packet</div>
<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):</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">iptables -A INPUT -p udp -m udp &#8211;dport <span style="color: #ff4500;">5060</span> -m <span style="color: #dc143c;">string</span> &#8211;<span style="color: #dc143c;">string</span> <span style="color: #483d8b;">&quot;Cirpack KeepAlive Packet&quot;</span> -j DROP</div>
<p>But the syntax has changed in iptables, and you&#8217;ll get the error:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">iptables v1<span style="color: #ff4500;">.3</span><span style="color: #ff4500;">.6</span>: STRING match: You must specify `&#8211;algo<span style="color: #483d8b;">&#8216;</span></div>
<p>so, just add one of the 2 available algorithms (bm and kmp):</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">iptables -A INPUT -p udp -m udp &#8211;dport <span style="color: #ff4500;">5060</span> -m <span style="color: #dc143c;">string</span> &#8211;<span style="color: #dc143c;">string</span> <span style="color: #483d8b;">&quot;Cirpack KeepAlive Packet&quot;</span> &#8211;algo bm -j DROP</div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.gradstein.info/python/how-to-dial-a-number-using-asterisk-and-python/" title="How to dial a number using Asterisk and Python (December 17, 2008)">How to dial a number using Asterisk and Python</a> (1)</li>
	<li><a href="http://www.gradstein.info/software/asterisk/asterisk-dadhi-module-not-working-when-using-xen/" title="Asterisk: DADHI module not working when using Xen (March 26, 2009)">Asterisk: DADHI module not working when using Xen</a> (5)</li>
</ul>

]]></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 on [...]]]></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>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">$wgRC2UDPAddress = <span style="color: #483d8b;">&#8216;127.0.0.1&#8242;</span>;<br />
$wgRC2UDPPort = <span style="color: #ff4500;">9390</span>;</div>
<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>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span><br />
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span><br />
<span style="color: #808080; font-style: italic;">#</span><br />
<span style="color: #808080; font-style: italic;"># vim:syntax=python:sw=4:ts=4:expandtab</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">SocketServer</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span></p>
<p>HOST,PORT = <span style="color: #483d8b;">&#8221;</span>, <span style="color: #ff4500;">9390</span></p>
<p><span style="color: #ff7700;font-weight:bold;">class</span> MyUDPHandler<span style="color: black;">&#40;</span><span style="color: #dc143c;">SocketServer</span>.<span style="color: black;">BaseRequestHandler</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">def</span> handle<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&#8216;<span style="color: #000099; font-weight: bold;">\x</span>03<span style="color: #000099; font-weight: bold;">\d</span>{0,2}&#8217;</span>, <span style="color: #483d8b;">&#8221;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">request</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></p>
<p><span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&#8216;__main__&#8217;</span>:<br />
&nbsp; &nbsp;server = <span style="color: #dc143c;">SocketServer</span>.<span style="color: black;">UDPServer</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>HOST, PORT<span style="color: black;">&#41;</span>, MyUDPHandler<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp;server.<span style="color: black;">serve_forever</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
<p>I plan to make it into a complete project that will send the data/notifications using Jabber(XMPP).</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.gradstein.info/software/how-to-skip-the-useless-you-are-now-logged-in-page-in-mediawiki/" title="How to skip the useless &#8220;you are now logged in&#8221; page in Mediawiki (January 18, 2009)">How to skip the useless &#8220;you are now logged in&#8221; page in Mediawiki</a> (0)</li>
	<li><a href="http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/" title="How to automatically run a script after inserting a USB device on Ubuntu? (April 13, 2008)">How to automatically run a script after inserting a USB device on Ubuntu?</a> (2)</li>
</ul>

]]></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>
		<item>
		<title>How to skip the useless &#8220;you are now logged in&#8221; page in Mediawiki</title>
		<link>http://www.gradstein.info/software/how-to-skip-the-useless-you-are-now-logged-in-page-in-mediawiki/</link>
		<comments>http://www.gradstein.info/software/how-to-skip-the-useless-you-are-now-logged-in-page-in-mediawiki/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 23:47:38 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=57</guid>
		<description><![CDATA[You installed Mediawiki some time ago, and now something bothers you: aren&#8217;t you tired of having an intermediate page named &#8220;Login successful&#8221; saying &#8220;You are now logged in to&#8221; before being allowed to go to the page you wanted to go? I am.
I found there&#8217;s a hook that is called just when a user successfully [...]]]></description>
			<content:encoded><![CDATA[<p>You installed Mediawiki some time ago, and now something bothers you: aren&#8217;t you tired of having an intermediate page named &#8220;Login successful&#8221; saying &#8220;You are now logged in to&#8221; before being allowed to go to the page you wanted to go? I am.<br />
I found there&#8217;s a hook that is called just when a user successfully logs on (<a href="http://www.mediawiki.org/wiki/Manual:Hooks/UserLoginComplete" class="liexternal">UserLoginComplete</a>), and even an extension named <a href="http://www.mediawiki.org/wiki/Extension:RedirectOnLogin" class="liexternal">RedirectOnLogin</a> that does the redirection for you, BUT to a fixed one. It seems the hook doesn&#8217;t give you the page you previously were before the login request.</p>
<p>So to correct this, I just found a dirty hack. That means you&#8217;ll have to patch the source, meaning also that you&#8217;ll loose some flexibility when upgrading Mediawiki :-(<br />
Anyway, if you still want to do this, here is the magic stuff:</p>
<p>Edit the file mediawiki/includes/specials/SpecialUserlogin.php and look for the function successfulLogin().<br />
At the end of it, just add (it&#8217;s just one line):</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">header<span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;Location: ./index.php?title=&#8217;</span> . $this-&gt;mReturnTo<span style="color: black;">&#41;</span>;</div>
<p>That&#8217;s it. You&#8217;ll get redirected to the previously accessed page automatically! Really cool.</p>
<p><em>This has been successfully used on a Mediawiki 1.13.</em></p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.gradstein.info/python/python-snippet-to-get-mediawikiwikipedia-recent-changes-externally/" title="Python snippet to get Mediawiki/Wikipedia Recent Changes externally (January 28, 2009)">Python snippet to get Mediawiki/Wikipedia Recent Changes externally</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/software/how-to-skip-the-useless-you-are-now-logged-in-page-in-mediawiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to dial a number using Asterisk and Python</title>
		<link>http://www.gradstein.info/python/how-to-dial-a-number-using-asterisk-and-python/</link>
		<comments>http://www.gradstein.info/python/how-to-dial-a-number-using-asterisk-and-python/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 09:39:17 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[voip]]></category>
		<category><![CDATA[clickto dial]]></category>
		<category><![CDATA[dial]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=33</guid>
		<description><![CDATA[I didn&#8217;t find any example in Python on how to Dial a number from an Asterisk server and link it to another channel. So here&#8217;s a quick code to do it. You just need to have a manager defined in your /etc/asterisk/manager.conf defined.
import socket
HOST=&#34;192.168.1.116&#34;
PORT=5038
p = &#34;&#34;&#34;Action: login
Events: off
Username: %(username)s
Secret: %(password)s
Action: originate
Channel: SIP/%(local_user)s
WaitTime: 60
CallerId: 600
Exten: %(phone_to_dial)s
Context: [...]]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t find any example in Python on how to Dial a number from an Asterisk server and link it to another channel. So here&#8217;s a quick code to do it. You just need to have a manager defined in your /etc/asterisk/manager.conf defined.</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span></p>
<p>HOST=<span style="color: #483d8b;">&quot;192.168.1.116&quot;</span><br />
PORT=<span style="color: #ff4500;">5038</span></p>
<p>p = <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Action: login<br />
Events: off<br />
Username: %(username)s<br />
Secret: %(password)s</p>
<p>Action: originate<br />
Channel: SIP/%(local_user)s<br />
WaitTime: 60<br />
CallerId: 600<br />
Exten: %(phone_to_dial)s<br />
Context: default<br />
Priority: 1</p>
<p>Action: Logoff<br />
&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><br />
<span style="color: #ff7700;font-weight:bold;">def</span> click_to_call<span style="color: black;">&#40;</span>phone_to_dial, username, password, local_user<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; pattern = p % <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&#8216;phone_to_dial&#8217;</span>: phone_to_dial,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&#8216;username&#8217;</span>: username,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&#8216;password&#8217;</span>: password,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&#8216;local_user&#8217;</span>: local_user<span style="color: black;">&#125;</span></p>
<p>&nbsp; &nbsp; s = <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; s.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>HOST, PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></p>
<p>&nbsp; &nbsp; data = s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> l <span style="color: #ff7700;font-weight:bold;">in</span> pattern.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;n&#8217;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Sending&gt;&quot;</span>, l<br />
&nbsp; &nbsp; &nbsp; &nbsp; s.<span style="color: black;">send</span><span style="color: black;">&#40;</span>l+<span style="color: #483d8b;">&#8216;rn&#8217;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> l == <span style="color: #483d8b;">&quot;&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data = s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> data<br />
&nbsp; &nbsp; data = s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></p>
<p><span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&#8216;__main__&#8217;</span>:<br />
&nbsp; &nbsp; click_to_call<span style="color: black;">&#40;</span>phone_to_dial=<span style="color: #483d8b;">&#8216;123456789&#8242;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username=<span style="color: #483d8b;">&#8216;manager_login&#8217;</span>, password=<span style="color: #483d8b;">&#8216;yourpass&#8217;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local_user=<span style="color: #483d8b;">&#8216;600&#8242;</span><span style="color: black;">&#41;</span></div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.gradstein.info/software/asterisk/asterisk-cirpack-problem-with-free-and-freephonienet/" title="Asterisk cirpack problem with Free and freephonie.net (February 12, 2009)">Asterisk cirpack problem with Free and freephonie.net</a> (0)</li>
	<li><a href="http://www.gradstein.info/software/asterisk/asterisk-dadhi-module-not-working-when-using-xen/" title="Asterisk: DADHI module not working when using Xen (March 26, 2009)">Asterisk: DADHI module not working when using Xen</a> (5)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/how-to-dial-a-number-using-asterisk-and-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Synchronization methods of a file with Puppet</title>
		<link>http://www.gradstein.info/ruby/synchronization-methods-of-a-file-with-puppet/</link>
		<comments>http://www.gradstein.info/ruby/synchronization-methods-of-a-file-with-puppet/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 12:39:32 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[puppet]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[reductivelabs]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=37</guid>
		<description><![CDATA[Usually, to synchronize a file with remote hosts, using puppet, one would use the following pattern:
file &#123; &#34;/etc/init.d/pvfs2-server&#34;:
&#160; &#160; &#160; owner =&#62; root, group =&#62; root, 
&#160; &#160; &#160; mode =&#62; 755, 
&#160; &#160; &#160; source =&#62; &#34;puppet:///files/pvfs2-server&#34; &#160; &#160;
&#125;
(using &#8220;source&#8221; to copy data as-is, and using &#8220;template(&#8220;filename&#8221;) to use a template structure as data).
Or, [...]]]></description>
			<content:encoded><![CDATA[<p>Usually, to synchronize a file with remote hosts, using <a href="http://reductivelabs.com/trac/puppet/" class="liexternal">puppet</a>, one would use the following pattern:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #008000;">file</span> <span style="color: black;">&#123;</span> <span style="color: #483d8b;">&quot;/etc/init.d/pvfs2-server&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; owner =&gt; root, group =&gt; root, <br />
&nbsp; &nbsp; &nbsp; mode =&gt; <span style="color: #ff4500;">755</span>, <br />
&nbsp; &nbsp; &nbsp; source =&gt; <span style="color: #483d8b;">&quot;puppet:///files/pvfs2-server&quot;</span> &nbsp; &nbsp;<br />
<span style="color: black;">&#125;</span></div>
<p>(using &#8220;source&#8221; to copy data as-is, and using &#8220;template(&#8220;filename&#8221;) to use a template structure as data).</p>
<p>Or, if one wishes to directly set the content of the target file:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #008000;">file</span> <span style="color: black;">&#123;</span> <span style="color: #483d8b;">&quot;/etc/init.d/pvfs2-server&quot;</span>:<br />
&nbsp; &nbsp;owner =&gt; root, group =&gt; root, <br />
&nbsp; &nbsp;mode =&gt; <span style="color: #ff4500;">755</span>, <br />
&nbsp; &nbsp;source =&gt; <span style="color: #483d8b;">&quot;puppet:///files/pvfs2-server&quot;</span> &nbsp; &nbsp;<br />
<span style="color: black;">&#125;</span></div>
<p>Please note that on the first line, for example &#8216;file { &#8220;/etc/mpd.conf&#8221;:&#8217;), the &#8220;/etc/mpd.conf&#8221; is a merge of two functionalities/concepts: Usually, the syntax is clear and simple:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #008000;">file</span> <span style="color: black;">&#123;</span> mon_fichier_mpd_conf:<br />
&nbsp; &nbsp; &nbsp;path =&gt; <span style="color: #483d8b;">&quot;/etc/mpd.conf&quot;</span>,<br />
&nbsp; &nbsp; &nbsp;<span style="color: black;">&#91;</span>&#8230;<span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span></div>
<p>The first line is about the resource description. Its goal is to be able to reference to it a little later from another resources (Notify[], etc.). By putting directly the file path and name (I think it&#8217;s identified as a filename and not as a description because there are quotes, or maybe it&#8217;s because it begins with a slash?) you mege the &#8220;path&#8221; attribute with its description.<br />
On the other end, we&#8217;ll not be able to reference to it later, if you need to.</p>
<p>You may also need to synchronize a file that is not present in the repository (puppet:///files/*). That usually happens, for example, when that file is regenerated by an external program or an external action (like /etc/passwd).</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #008000;">file</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;/etc/passwd&quot;</span>:<br />
&nbsp; &nbsp; &nbsp;owner =&gt; root, group =&gt; root, mode =&gt; <span style="color: #ff4500;">644</span>,<br />
&nbsp; &nbsp; &nbsp;content =&gt; <span style="color: #008000;">file</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/etc/passwd&quot;</span><span style="color: black;">&#41;</span><br />
<span style="color: black;">&#125;</span></div>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/ruby/synchronization-methods-of-a-file-with-puppet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to automatically run a script after inserting a USB device on Ubuntu?</title>
		<link>http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/</link>
		<comments>http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 21:32:01 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[hardware]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[hotplug]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[run]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[udev]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=35</guid>
		<description><![CDATA[Here&#8217;s the setup: you have a computer which has a SD port (small memory cards, mostly used in cameras, phones, etc.). You want to get all of your photos from that card automatically as soon as you insert your card (may be a USB key as well), that is, run a script which will search [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the setup: you have a computer which has a SD port (small memory cards, mostly used in cameras, phones, etc.). You want to get all of your photos from that card automatically as soon as you insert your card (may be a USB key as well), that is, run a script which will search for all of your photos, and copy them to a local directory.</p>
<p><span id="more-35"></span></p>
<p>I know, some programs already do this, but they require Xwindow and some <a href="http://f-spot.org/Main_Page" class="liexternal">ugly Gnome</a>/KDE app. What we&#8217;re doing here is a minimal setup, using the least memory.</p>
<p>Normally, on a normal Unix system you would use the included device detection mechanism, which is <a href="http://linux-hotplug.sourceforge.net/" title="Linux Hotplug project" class="liexternal">hotplug</a>. But on Ubuntu (at least <em>Gutsy</em> and <em>Hardy</em>), the de-facto/required way is by using <strong>udev</strong>, which is an event based system, using rules to fire new events/mount/symlink or run programs according to some patterns defined as &#8220;rules&#8221;.</p>
<p>So, the first thing to do is to identify your device according to USB events. udevinfo is your friend. So, after looking at the output of dmesg, you&#8217;ll see your USB device is available on some sd* device.</p>
<p>So run:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"> udevinfo -a -p &nbsp;/<span style="color: #dc143c;">sys</span>/block/sda<br />
<span style="color: black;">&#40;</span>replace sda with you device<span style="color: black;">&#41;</span></div>
<p>You will get a list of &#8220;blocks&#8221; representing each layer of drivers. For example:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">root@sleek:/etc/udev/rules.<span style="color: black;">d</span><span style="color: #808080; font-style: italic;"># udevinfo -a -p /sys/block/sda/</span></p>
<p>looking at device <span style="color: #483d8b;">&#8216;/block/sda&#8217;</span>:<br />
KERNEL==<span style="color: #483d8b;">&quot;sda&quot;</span><br />
SUBSYSTEM==<span style="color: #483d8b;">&quot;block&quot;</span><br />
DRIVER==<span style="color: #483d8b;">&quot;&quot;</span><br />
ATTR<span style="color: black;">&#123;</span><span style="color: #dc143c;">stat</span><span style="color: black;">&#125;</span>==<span style="color: #483d8b;">&quot; &nbsp;229567 &nbsp; &nbsp;[...] 456048 &nbsp;3697068&quot;</span><br />
ATTR<span style="color: black;">&#123;</span>size<span style="color: black;">&#125;</span>==<span style="color: #483d8b;">&quot;488397168&quot;</span><br />
ATTR<span style="color: black;">&#123;</span>removable<span style="color: black;">&#125;</span>==<span style="color: #483d8b;">&quot;0&quot;</span><br />
ATTR<span style="color: black;">&#123;</span><span style="color: #008000;">range</span><span style="color: black;">&#125;</span>==<span style="color: #483d8b;">&quot;16&quot;</span><br />
ATTR<span style="color: black;">&#123;</span>dev<span style="color: black;">&#125;</span>==<span style="color: #483d8b;">&quot;8:0&quot;</span></p>
<p>looking at parent device <span style="color: #483d8b;">&#8216;/devices/pci0000:00/00[...]:<br />
KERNELS==&quot;2:0:0:0&quot;<br />
SUBSYSTEMS==&quot;scsi&quot;<br />
DRIVERS==&quot;sd&quot;<br />
ATTRS{ioerr_cnt}==&quot;0&#215;0&quot;<br />
ATTRS{iodone_cnt}==&quot;0xcc26b&quot;<br />
ATTRS{iorequest_cnt}==&quot;0xcc26c&quot;<br />
ATTRS{iocounterbits}==&quot;32&quot;<br />
ATTRS{timeout}==&quot;30&quot;<br />
ATTRS{state}==&quot;running&quot;<br />
ATTRS{rev}==&quot;3.AA&quot;<br />
ATTRS{model}==&quot;ST3250310AS &nbsp; &nbsp; &quot;<br />
ATTRS{vendor}==&quot;ATA &nbsp; &nbsp; &quot;</span></div>
<p>These are in fact attributes that you can use in your rule to filter the devices. So for example,<br />
to run a shell script when a SCSI device is detected which has a size of 1GB, I&#8217;ll use the following line:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">KERNEL==<span style="color: #483d8b;">&quot;sd?1&quot;</span>, ATTRS<span style="color: black;">&#123;</span>size<span style="color: black;">&#125;</span>==<span style="color: #483d8b;">&quot;1999872&quot;</span>, RUN+=<span style="color: #483d8b;">&quot;/usr/local/bin/recup_usb.sh&quot;</span></div>
<p>This line is to be put in a new file in /etc/udev/rules.d, named something like 91-backuptousbdrivetrigger.rules. It&#8217;s better to put the file at the end of the rules (the &#8220;91&#8243;), as not to disturb other module loadings.</p>
<p>The content of the recup_usb.sh file can be:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;"><span style="color: #808080; font-style: italic;">#!/bin/bash</span></p>
<p><span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#91;</span> <span style="color: #483d8b;">&quot;${ACTION}&quot;</span> = <span style="color: #483d8b;">&quot;add&quot;</span> <span style="color: black;">&#93;</span>; then<br />
&nbsp; &nbsp;rm -rf /tmp/x<br />
&nbsp; &nbsp;mkdir /tmp/x<br />
&nbsp; &nbsp;mount -t vfat /dev/sdc1 /tmp/x<br />
&nbsp; &nbsp;find /tmp/x -name <span style="color: #483d8b;">&quot;*jpg&quot;</span> -<span style="color: #ff7700;font-weight:bold;">exec</span> /usr/bin/rsync -avz <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> &nbsp;\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /home/foobar/Pictures/Incoming/`date +%Y-%m-%d`/ \;<br />
&nbsp; &nbsp;umount /tmp/x<br />
fi</div>
<p><em>(yes, I know this code is dirty, I should have used mktemp, but you get the point&#8230;)</em><br />
Don&#8217;t forget to chmod +x the shell script and reload the configuration with:</p>
<div class="python" style="font-family: monospace;color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">udevcontrol reload_rules</div>
<p>For more detailed information about writing udev rules, take a look at the<a href="http://reactivated.net/writing_udev_rules.html" class="liexternal"> official documentation</a>, or <a href="http://tlug.dnho.net/?q=smeserver_udev_automated_backups" class="liexternal">another&#8217;s detailed information</a> about doing the same thing.</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.gradstein.info/python/python-snippet-to-get-mediawikiwikipedia-recent-changes-externally/" title="Python snippet to get Mediawiki/Wikipedia Recent Changes externally (January 28, 2009)">Python snippet to get Mediawiki/Wikipedia Recent Changes externally</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Videos of every presentation of Journée Python 2007 are now online!</title>
		<link>http://www.gradstein.info/python/videos-of-every-presentation-of-journee-python-2007-are-now-online/</link>
		<comments>http://www.gradstein.info/python/videos-of-every-presentation-of-journee-python-2007-are-now-online/#comments</comments>
		<pubDate>Tue, 12 Jun 2007 00:50:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[language]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twisted]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/language/videos-of-every-presentation-of-journee-python-2007-are-now-online/</guid>
		<description><![CDATA[As the title says it, each presentation was filmed, and has just been uploaded for everyone&#8217;s pleasure! Here is the two-part video presentation of Twisted, done by Michael SCHERER.


Oh, by the way, please take a minute to vote for your favourite Internet Engine!



	Related posts
	
	No related posts.
	

]]></description>
			<content:encoded><![CDATA[<p>As the title says it, each <a href="http://journees.afpy.org/programme" class="liexternal">presentation was filmed</a>, and has just been uploaded for everyone&#8217;s pleasure! Here is the two-part video presentation of Twisted, done by Michael SCHERER.</p>
<p><object type="application/x-shockwave-flash" data="http://video.google.com/googleplayer.swf?docId=8739163173039026567" width="425" height="350" wmode="transparent"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=8739163173039026567" /></object><br />
<object type="application/x-shockwave-flash" data="http://video.google.com/googleplayer.swf?docId=1837647658089311574" width="425" height="350" wmode="transparent"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=1837647658089311574" /></object></p>
<p>Oh, by the way, please take a minute to vote for your favourite Internet Engine!</p>
<p align="center">
<iframe src="http://jyte.com/widget/claim/twistedmatrix.com-is-the-engine-of-your-internet" style="width:400px;height:60px;border:1px solid #777;" scrolling="no"></iframe></p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/videos-of-every-presentation-of-journee-python-2007-are-now-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
