<?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>Valentin's Lab &#187; howto</title>
	<atom:link href="https://vaab.blog.kal.fr/category/howto/feed/" rel="self" type="application/rss+xml" />
	<link>https://vaab.blog.kal.fr</link>
	<description>Ratiocination of an opensource techie</description>
	<lastBuildDate>Thu, 15 Nov 2018 08:04:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F&amp;language=en_US&amp;category=text&amp;title=Valentin%27s+Lab&amp;description=Ratiocination+of+an+opensource+techie&amp;tags=blog" type="text/html" />
	<item>
		<title>Fixing empathy in ubuntu 12.10, 13.04, 13.10, and 14.04</title>
		<link>https://vaab.blog.kal.fr/2013/04/04/fixing-empathy-in-ubuntu-12-10/</link>
		<comments>https://vaab.blog.kal.fr/2013/04/04/fixing-empathy-in-ubuntu-12-10/#comments</comments>
		<pubDate>Thu, 04 Apr 2013 20:41:47 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=431</guid>
		<description><![CDATA[I recently decided I'll upgrade my Ubuntu 12.04 to Quantal 12.10. There wasn't a lot of new feature, and I was really disappointed by the changes in empathy. Empathy was not usable anymore. I installed pidgin and recalled that it &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2013/04/04/fixing-empathy-in-ubuntu-12-10/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p>I recently decided I'll upgrade my Ubuntu 12.04 to Quantal 12.10.</p>
<p>There wasn't a lot of new feature, and I was really disappointed by the changes in <a class="reference external" href="https://live.gnome.org/Empathy">empathy</a>.</p>
<p>Empathy was not usable anymore. I installed pidgin and recalled that it wasn't correctly integrated with SIP technology which was a no-go for me.</p>
<p>I felt trapped with this upgrade: the version of empathy shipped with <tt class="docutils literal">12.04</tt> was way better than what I was confronted in <tt class="docutils literal">12.10</tt> (and <tt class="docutils literal">13.04</tt>, and <tt class="docutils literal">13.10</tt>, and <tt class="docutils literal">14.04</tt>)... Hopefully I managed to fix all this to my needs. Here's what I did.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">And when I upgraded to 13.04 (then 13.10, and 14.04), I could make the same complaints, and the same fixes.</p>
</div>
<div class="section" id="the-griefs">
<h3>The Griefs</h3>
<p>Bugs were reported:</p>
<ul>
<li><p class="first">the <strong>contact list has HUGE avatars</strong> and you can't choose to have smaller ones: what happened exactly is that the <a class="reference external" href="http://blog.desmottes.be/post/2012/06/15/New-Empathy-contact-list">contact list skin drastically changed</a> in a very un-wise move: each avatar took 48 pixel height, leading to un-manageably long, multi-screen tall contact list.
(<a class="reference external" href="https://bugs.launchpad.net/ubuntu/+source/empathy/+bug/1068668">30 people are awaiting on this bug resolution</a>). Worse: the <a class="reference external" href="https://git.gnome.org/browse/empathy/commit/?id=f58d68ddddf15dfe4e0d49af86e2add3c606316e">option to get compact list was removed</a> and more than <a class="reference external" href="https://bugs.launchpad.net/ubuntu/+source/empathy/+bug/1068668">96 people are awaiting for this option to come back</a>. A bug
report was also <a class="reference external" href="https://bugzilla.gnome.org/show_bug.cgi?id=693488">reported on bugzilla</a> at least <a class="reference external" href="https://bugzilla.gnome.org/show_bug.cgi?id=684199">twice</a>.</p>
<blockquote>
<ul class="simple">
<li><strong>I'm providing a fix</strong> to set avatar icon size.</li>
</ul>
</blockquote>
</li>
<li><p class="first">The <strong>contact list is not anymore sorted by status</strong>: yes, this means that <cite>connected</cite> and <cite>away</cite> contacts are mixed, if you have more than 10 contacts using google
talk for instance, they probably be growing your contact list as <cite>away</cite>. You'll have to painfully filter by eye the ones that are really available and active.</p>
<blockquote>
<ul class="simple">
<li><strong>I'm providing a quick fix</strong> to this also.</li>
</ul>
</blockquote>
</li>
<li><p class="first">You <strong>can't phone using your SIP account</strong> to your address book phone numbers.</p>
<blockquote>
<ul class="simple">
<li><strong>Hit only 12.10</strong>, on which <strong>I've provided a fix</strong> by cherry-picking the upstream bug resolution</li>
</ul>
</blockquote>
</li>
<li><p class="first"><strong>No more notification of new message</strong> (<a class="reference external" href="https://bugs.launchpad.net/ubuntu/+source/indicator-messages/+bug/1060469">launchpad report</a>).
What a failure ! I could hear message alert sound whenever I received a new message but <strong>could not get to see the incoming messages</strong> as there is no way to make the messaging window appear without the messaging indicator. Additionaly for the same reason, I could not answer to standard events as standard requests from new contacts
to share our visibility status despite a pretty notification message displayed on the top right corner of my screen telling me that the request was received (and that
the contact awaited an answer).</p>
<blockquote>
<ul class="simple">
<li><strong>This one was Ubuntu's fault</strong>, and can be fixed by installing <cite>telepathy-indicator</cite>, more info following</li>
</ul>
</blockquote>
</li>
</ul>
<p>Of course, I'm not the only one to have expressed deep concerns on theses <a class="reference external" href="http://ubuntuforums.org/showthread.php?t=2079243">empathy regressions</a>.</p>
</div>
<div class="section" id="the-cure">
<h3>The Cure</h3>
<div class="section" id="tl-dr">
<h4>TL;DR</h4>
<p>Provided you are on 64bit architecture, here are the new DEB files:</p>
<blockquote>
<ul class="simple">
<li><strong>To get compact contact list</strong>, and <strong>contact sorted by status</strong> get <a class="reference external" href="http://vaab.blog.kal.fr/files/2013/04/empathy_3.6.0.3-0ubuntu1_amd64.deb">this new fixed empathy deb for 12.10</a> (same for <a class="reference external" href="http://vaab.blog.kal.fr/files/2014/02/empathy_3.8.4-1ubuntu2_amd64.deb">13.10</a>, or for <a class="reference external" href="http://vaab.blog.kal.fr/files/2013/04/empathy_3.8.6-0ubuntu9_amd64.deb">14.04</a>) and install it.</li>
<li><strong>To re-enable calling landlines phone</strong> with your SIP account (only needed for 12.10), get <a class="reference external" href="http://vaab.blog.kal.fr/files/2013/04/account-plugin-sip_3.6.0.3-0ubuntu1_amd64.deb">this new account-plugin-sip deb for 12.10</a> and install it.</li>
<li><strong>To get instant message back in notification area</strong> ensure that you have <cite>telepathy-indicator</cite> installed and running.</li>
</ul>
</blockquote>
</div>
<div class="section" id="how-you-could-patch-it-yourself-the-next-time">
<h4>How you could patch it yourself the next time</h4>
<p>Open-source matters. Let me show you why:</p>
<p>Let's get the source code:</p>
<pre class="literal-block">
cd /tmp
apt-get source empathy
</pre>
<p>Note that this last command will get the source package of empathy, and apply ubuntu specific patches.</p>
<p>Now, we'll proceed with getting all build dependencies required for compilation of empathy sources:</p>
<pre class="literal-block">
apt-get build-dep empathy
</pre>
<p>With Ubuntu 12.10 (13.04, 13.10, and 14.04), the version of empathy is 3.6.0.3 (3.6.4, 3.8.4, and 3.8.6 respectively). We will now access to the source and make some modifications:</p>
<pre class="literal-block">
cd empathy-*
sed -ri 's/#define AVATAR_SIZE 48/#define AVATAR_SIZE 24/g' \
    libempathy-gtk/empathy-roster-contact.c
</pre>
<p>I'll let you tweak the size in this line, it's expressed in pixel. New value is <tt class="docutils literal">24</tt> here, instead of <tt class="docutils literal">48</tt>.</p>
<p>Optionally, I found that the <a class="reference external" href="https://bugzilla.gnome.org/show_bug.cgi?id=691195">SIP bug that prevented to call landlines phones</a> was corrected in empathy <tt class="docutils literal">3.7.4</tt>. And that it wasn't included in <tt class="docutils literal">12.10</tt> but was in <tt class="docutils literal">13.04</tt> and newer.</p>
<p>If using <tt class="docutils literal">12.10</tt> and interested by this feature, you should cherry-pick the patch:</p>
<pre class="literal-block">
wget -O - &quot;https://bug691195.bugzilla-attachments.gnome.org/attachment.cgi?id=232954&amp;action=diff&amp;collapsed=&amp;context=patch&amp;format=raw&amp;headers=1&quot; | patch -p 1
</pre>
<p>Optionally, I patched the sort algorithm to sort by contact status before sorting by alphabetical order, if you want to get this patch:</p>
<pre class="literal-block">
cat &lt;&lt;EOF | patch -p 1
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c
index c3ae66e..77d76d6 100644
--- a/libempathy-gtk/empathy-roster-view.c
+++ b/libempathy-gtk/empathy-roster-view.c
&#64;&#64; -188,6 +188,10 &#64;&#64; add_roster_contact (EmpathyRosterView *self,
   g_signal_connect (contact, &quot;notify::alias&quot;,
       G_CALLBACK (roster_contact_changed_cb), self);

+  /* Need to resort if presence is changed */
+  g_signal_connect (contact, &quot;notify::presence-type&quot;,
+      G_CALLBACK (roster_contact_changed_cb), self);
+
   gtk_widget_show (contact);
   gtk_container_add (GTK_CONTAINER (self), contact);

&#64;&#64; -633,19 +637,76 &#64;&#64; compare_roster_contacts_by_alias (EmpathyRosterContact *a,
 }

 static gint
+presence_sort_key (FolksPresenceType presence) {
+
+  switch (presence)
+    {
+      case FOLKS_PRESENCE_TYPE_UNSET:
+      case FOLKS_PRESENCE_TYPE_OFFLINE:
+      case FOLKS_PRESENCE_TYPE_UNKNOWN:
+      case FOLKS_PRESENCE_TYPE_ERROR:
+        return 0;
+
+      case FOLKS_PRESENCE_TYPE_HIDDEN:
+      case FOLKS_PRESENCE_TYPE_EXTENDED_AWAY:
+        return 1;
+
+      case FOLKS_PRESENCE_TYPE_AWAY:
+        return 2;
+
+      case FOLKS_PRESENCE_TYPE_BUSY:
+      case FOLKS_PRESENCE_TYPE_AVAILABLE:
+        return 3;
+
+      default:
+        g_warning (&quot;Unknown FolksPresenceType: %d&quot;, presence);
+        return 0;
+  }
+
+}
+
+static gint
+compare_roster_contacts_by_presence (EmpathyRosterContact *a,
+    EmpathyRosterContact *b)
+{
+  FolksPresenceType presence_a, presence_b;
+  FolksIndividual *ind_a, *ind_b;
+  gint key_a, key_b;
+
+  ind_a = empathy_roster_contact_get_individual (a);
+  ind_b = empathy_roster_contact_get_individual (b);
+
+  presence_a = folks_presence_details_get_presence_type (
+      FOLKS_PRESENCE_DETAILS (ind_a));
+  presence_b = folks_presence_details_get_presence_type (
+      FOLKS_PRESENCE_DETAILS (ind_b));
+
+  key_a = presence_sort_key(presence_a);
+  key_b = presence_sort_key(presence_b);
+
+  return key_b - key_a;
+}
+
+static gint
 compare_roster_contacts_no_group (EmpathyRosterView *self,
     EmpathyRosterContact *a,
     EmpathyRosterContact *b)
 {
   gboolean top_a, top_b;
+  gint presence_cmp;

   top_a = contact_in_top (self, a);
   top_b = contact_in_top (self, b);

   if (top_a == top_b)
-    /* Both contacts are in the top of the roster (or not). Sort them
-     * alphabetically */
-    return compare_roster_contacts_by_alias (a, b);
+    {
+      /* Both contacts are in the top of the roster (or not). Sort them
+       * by status, then alphabetically */
+      presence_cmp = compare_roster_contacts_by_presence(a, b);
+      if (presence_cmp == 0)
+        return compare_roster_contacts_by_alias (a, b);
+      return presence_cmp;
+    }
   else if (top_a)
     return -1;
   else
&#64;&#64; -676,14 +737,18 &#64;&#64; compare_roster_contacts_with_groups (EmpathyRosterView *self,
     EmpathyRosterContact *b)
 {
   const gchar *group_a, *group_b;
+  gint presence_cmp;

   group_a = empathy_roster_contact_get_group (a);
   group_b = empathy_roster_contact_get_group (b);

-  if (!tp_strdiff (group_a, group_b))
+  if (!tp_strdiff (group_a, group_b)) {
     /* Same group, compare the contacts */
-    return compare_roster_contacts_by_alias (a, b);
-
+    presence_cmp = compare_roster_contacts_by_presence(a, b);
+    if (presence_cmp == 0)
+      return compare_roster_contacts_by_alias (a, b);
+    return presence_cmp;
+  }
   /* Sort by group */
   return compare_group_names (group_a, group_b);
 }
EOF
</pre>
<p>And proceeded with the recompilation of the debian package:</p>
<pre class="literal-block">
dpkg-buildpackage -rfakeroot -b
</pre>
<p>After some time waiting for the compilation to finish, you should have some new 'deb' packages in <tt class="docutils literal">/tmp</tt>:</p>
<pre class="literal-block">
cd ..
ls -al *.deb
</pre>
<p>Before installing these packages, you can make sure to remove any empathy/telepathy process:</p>
<pre class="literal-block">
killall telepathy-gabble empathy-auth-client empathy-chat \
        telepathy-idle telepathy-logger telepathy-rakia  \
        telepathy-salut telepathy-haze mission-control-5 \
        empathy
</pre>
<p>And then install the new empathy:</p>
<pre class="literal-block">
sudo dpkg -i empathy_*.deb
</pre>
<p>If you applied the SIP patch:</p>
<pre class="literal-block">
sudo dpkg -i account-plugin-sip_*.deb
</pre>
<p>Then run empathy by any usual way you could think of.</p>
</div>
</div>
<div class="section" id="more-info">
<h3>More info</h3>
<ul class="simple">
<li>Many thanks to this how-to on <a class="reference external" href="http://www.cyberciti.biz/faq/rebuilding-ubuntu-debian-linux-binary-package/">rebuilding deb packages</a></li>
</ul>
</div>
</div>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=431&amp;md5=2cb31d00d49ab29bf1faf0f4d49e21cc" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2013/04/04/fixing-empathy-in-ubuntu-12-10/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2013%2F04%2F04%2Ffixing-empathy-in-ubuntu-12-10%2F&amp;language=en_GB&amp;category=text&amp;title=Fixing+empathy+in+ubuntu+12.10%2C+13.04%2C+13.10%2C+and+14.04&amp;description=I+recently+decided+I%27ll+upgrade+my+Ubuntu+12.04+to+Quantal+12.10.+There+wasn%27t+a+lot+of+new+feature%2C+and+I+was+really+disappointed+by+the+changes+in+empathy.+Empathy+was...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>comparison of minimal packaging between distribute and distutils2</title>
		<link>https://vaab.blog.kal.fr/2013/02/22/comparison-of-minimal-packaging-between-distribute-and-distutils2/</link>
		<comments>https://vaab.blog.kal.fr/2013/02/22/comparison-of-minimal-packaging-between-distribute-and-distutils2/#comments</comments>
		<pubDate>Fri, 22 Feb 2013 15:27:14 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[distribute]]></category>
		<category><![CDATA[distutils2]]></category>
		<category><![CDATA[packaging]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=382</guid>
		<description><![CDATA[In a pythonic mind, we shoud keep things simple as possible. But when having to deal with distribution of your code, especially if it's ONE small python file, you'll might cringe when facing the boilerplate that is required. Even with &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2013/02/22/comparison-of-minimal-packaging-between-distribute-and-distutils2/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p>In a pythonic mind, we shoud keep things simple as possible.</p>
<p>But when having to deal with distribution of your code,
especially if it's ONE small python file, you'll might cringe
when facing the boilerplate that is required. Even with
<a class="reference external" href="http://pythonhosted.org/distribute/setuptools.html">distribute</a> in place of setuptools.</p>
<p>And speaking of packaging system, python has a very complex
history of them (between distutils, setuptools, distribute,
distutils2), adding a considerable burden to get a clear
idea of what system you should use, and get a complete
documentation of one system. Especially when whole part of each
system share code, ideas, compatibility but aims to be better in
some obscure part for a newcomer.</p>
<p>Notice how this
<a class="reference external" href="http://stackoverflow.com/questions/6344076/differences-between-distribute-distutils-setuptools-and-distutils2">stackoverflow question about python packaging systems</a> gets
answered brilliantly and how concrete differences between all
these packaging solutions weren't mentioned.</p>
<p>However, I wanted a dead simple way to distribute my single file package. And I
found 2 ways:</p>
<blockquote>
<ul class="simple">
<li>one with <tt class="docutils literal">distribute</tt> (the actually recommended packaging
system),</li>
<li>one with <tt class="docutils literal">distutils2</tt> (the upcoming-but-not-finished replacement
of <tt class="docutils literal">distribute</tt>).</li>
</ul>
</blockquote>
<p>I realized that I could illustrate some simple differences for newcomers
when facing the need to package a simple python file.</p>
<div class="section" id="the-goal">
<h3>The goal</h3>
<p>You have a file <tt class="docutils literal">foo.py</tt> holding whatever python code you
want. <tt class="docutils literal">foo.py</tt> is alone in a directory.</p>
<div class="section" id="install-ability">
<h4>Install-ability</h4>
<p>You need to be able to type <tt class="docutils literal">python setup.py install</tt> (or something similar)
in the source directory and all the magic required will fire out to set things
how they are supposed to be in your python libraries, allowing you to invoke
<tt class="docutils literal">import foo</tt> in any of your python file without any unfriendly exception
being cast.</p>
</div>
<div class="section" id="distributability">
<h4>distributability</h4>
<p>Next, you should be able to type <tt class="docutils literal">python setup.py sdist register upload</tt> (or
something similar) to build a source distribution, register the package to the PyPI,
and send it. So that, finally, from any computer having access to internet, you
could cast a <tt class="docutils literal">pip install foo</tt> (or something similar) to get your package
downloaded from the PyPI, and installed.</p>
</div>
</div>
<div class="section" id="distribute-way">
<h3>Distribute way</h3>
<p>This is the simplest way I found to distribute
a ONE small python file using <tt class="docutils literal">distribute</tt>, which
seems to be the current best solution waiting
for <tt class="docutils literal">distutils2</tt>.</p>
<div class="section" id="requirements">
<h4>Requirements</h4>
<p>Make sure you have the last <tt class="docutils literal">distribute</tt> installed.
You can install it with this command:</p>
<pre class="literal-block">
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
</pre>
</div>
<div class="section" id="setup-py-file">
<h4>setup.py file</h4>
<p>Then create a <tt class="docutils literal">setup.py</tt> file in the same directory than <tt class="docutils literal">foo.py</tt>, containing:</p>
<pre class="literal-block">
from setuptools import setup
setup(
    ## Required for ``python setup.py install``
    name=&quot;foo_utils&quot;,
    version=&quot;0.1&quot;,
    py_modules=[&quot;foo&quot;]

    ## Required for ``python setup.py sdist upload install``
)
</pre>
<p>The <tt class="docutils literal">name</tt> will be your package name and <tt class="docutils literal">version</tt> will be its version, these
are used for naming the <tt class="docutils literal">.egg</tt> and PyPI references.</p>
<p>The following is a less documented option and makes the solution I have found so small:
<tt class="docutils literal">py_modules</tt> is the python module you want to distribute. Typing <tt class="docutils literal">foo</tt> targets
the <tt class="docutils literal">foo.py</tt> file.</p>
<p>Actually, complete reference of this trick can be found in <a class="reference external" href="http://docs.python.org/2/distutils/examples.html">distutils
documentation</a>, I couldn't find any reference to <tt class="docutils literal">py_modules</tt>
anywhere in the <a class="reference external" href="http://pythonhosted.org/distribute/setuptools.html">distribute documentation</a>.</p>
</div>
<div class="section" id="tada">
<h4>Tada !</h4>
<p>The small <tt class="docutils literal">setup.py</tt> you've written should allow you to type:</p>
<pre class="literal-block">
python setup.py install
</pre>
<!-- to reach the "install-ability" goal. -->
<p>To send it to PyPI, you'll need some other metadata as the author, summary,
licence and maybe a small description. These are to be added in your <tt class="docutils literal">setup.py</tt>
file, and then:</p>
<pre class="literal-block">
python setup.py sdist register upload
</pre>
<p>... will send it to PyPI.</p>
<p>At last you'll then be able to install it from anywhere with:</p>
<pre class="literal-block">
pip install foo_utils
</pre>
</div>
</div>
<div class="section" id="distutils2-way">
<h3>Distutils2 way</h3>
<p>The major modification that you'll notice here is the fact that the
configuration is not executable code anymore: <tt class="docutils literal">setup.py</tt> is replaced
by <tt class="docutils literal">setup.cfg</tt>.</p>
<div class="section" id="id1">
<h4>Requirements</h4>
<p>You need to install <tt class="docutils literal">distutils2</tt>:</p>
<pre class="literal-block">
pip install distutils2
</pre>
<p>If you have any trouble installing <tt class="docutils literal">distutils2</tt>, you might be interested in
the ending section about <tt class="docutils literal">the truth about distutils2</tt>. You could also try
something like that (adapt the version of course !):</p>
<pre class="literal-block">
cd /tmp
wget https://pypi.python.org/packages/source/D/Distutils2/Distutils2-1.0a4.tar.gz
tar xvzf Distutils2-1.0a4.tar.gz
cd Distutils2-1.0a4
python setup.py install
</pre>
</div>
<div class="section" id="setup-cfg">
<h4>setup.cfg</h4>
<p>In the same directory than <tt class="docutils literal">foo.py</tt>, you can create <tt class="docutils literal">setup.cfg</tt>
containing:</p>
<pre class="literal-block">
[metadata]
name = foo_utils
version = 0.1

[files]
modules = foo
</pre>
<p>Notice that <tt class="docutils literal">py_modules</tt> is in a <tt class="docutils literal">files</tt> section and has been renamed
to <tt class="docutils literal">modules</tt>.</p>
<p>This first version of <tt class="docutils literal">setup.cfg</tt> will allow you to achieve first goal of
&quot;install-ability&quot;. But you'll need more to get your code sent to PyPI:</p>
<pre class="literal-block">
[metadata]
name = foo_utils
version = 0.1.0
summary = A Simple example Foo program
description-file = README.rst CHANGELOG.rst

## sdist info
author = John Doe
author_email = john.doe&#64;example.com
classifier =
    Development Status :: 3 - Alpha
    License :: OSI Approved :: GNU General Public License (GPL)

[files]
modules = foo_utils
extra_files =
    README.rst
    CHANGELOG.rst
</pre>
<p>Well, it's not that small, but I'm not sure what is actually really required, and
I think a small summary or description won't hurt. Notice that we have to repeat our
selves for the inclusion of the <tt class="docutils literal">README.rst</tt> and <tt class="docutils literal">CHANGELOG.rst</tt> files that are used in
the description.</p>
<p>Of course, all details given hear are subject to changes in the upcoming releases of
<tt class="docutils literal">distutils2</tt>.</p>
</div>
<div class="section" id="id2">
<h4>Tada !</h4>
<p>The small <tt class="docutils literal">setup.cfg</tt> you've written should allow you to type:</p>
<pre class="literal-block">
pysetup install
</pre>
<p>To reach the &quot;install-ability&quot; goal. And:</p>
<pre class="literal-block">
pysetup run sdist register upload
</pre>
<p>To send it to PyPI. Then you should be able to install it from anywhere with:</p>
<pre class="literal-block">
pysetup install foo_utils
</pre>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">packages made with <tt class="docutils literal">distutils2</tt> won't be compatible with <tt class="docutils literal">pip install PACKAGE</tt> commands as
they do not provide any <tt class="docutils literal">setup.py</tt>. You'll receive <tt class="docutils literal">IOError: [Errno 2] No such file or directory</tt>.</p>
</div>
<p>If any of these commands don't work, jump ahead to the next section !.</p>
</div>
<div class="section" id="the-truth-about-distutils2">
<h4>The truth about distutils2</h4>
<p>Before getting something actually working, I ran in multiple issues, and these are some of
the trick I did to make it work.</p>
<p>First, get it installed:</p>
<pre class="literal-block">
cd /tmp
wget https://pypi.python.org/packages/source/D/Distutils2/Distutils2-1.0a4.tar.gz
tar xvzf Distutils2-1.0a4.tar.gz
cd Distutils2-1.0a4
python setup.py install
</pre>
<p>Then, I proceeded towards the distribute installation:</p>
<pre class="literal-block">
$ pysetup foo_utils
No handlers could be found for logger &quot;distutils2&quot;
</pre>
<p>Hum, after hacking into the <tt class="docutils literal">distutils2</tt> code, I've found that distutils hadn't
any default logger, once one set, it was only to realize that it wanted to display
a simple error to tell me that I messed with my arguments. The correct command is:</p>
<pre class="literal-block">
root&#64;myhost$ pysetup install foo_utils
Checking the installation location...
Unable to write in &quot;/usr/lib/python2.7/site-packages&quot;. Do you have the permissions ?
root&#64;myhost$
</pre>
<p>What are you talking about ?! I'm root ! After looking around, I found there were no such
directory <tt class="docutils literal"><span class="pre">site-packages</span></tt> in my testing VM, which should mimick an Ubuntu 12.04 standard
install. I pursued by:</p>
<pre class="literal-block">
root&#64;myhost$ mkdir /usr/lib/python2.7/site-packages
root&#64;myhost$ pysetup install foo_utils
Checking the installation location...
Getting information about 'foo_utils'...
u'python-debian': u'0.1.21ubuntu1' is not a valid version (field 'Version')
u'python-apt': u'0.8.3ubuntu7' is not a valid version (field 'Version')
u'ufw': u'0.31.1-1' is not a valid version (field 'Version')
u'Landscape Client': u'12.05' is not a valid version (field 'Version')
Installing u'foo_utils' 0.1.0...
running install_dist
running build
running build_py
running install_lib
byte-compiling /usr/lib/python2.7/site-packages/foo.py to foo.pyc
running install_distinfo
creating /usr/lib/python2.7/site-packages/foo-utils-0.1.0.dist-info
creating /usr/lib/python2.7/site-packages/foo-utils-0.1.0.dist-info/METADATA
creating /usr/lib/python2.7/site-packages/foo-utils-0.1.0.dist-info/INSTALLER
creating /usr/lib/python2.7/site-packages/foo-utils-0.1.0.dist-info/REQUESTED
creating /usr/lib/python2.7/site-packages/foo-utils-0.1.0.dist-info/RECORD
root&#64;myhost$
</pre>
<p>Success ! I then did the test to see if I could &quot;import&quot; my lib:</p>
<pre class="literal-block">
root&#64;myhost$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import foo
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ImportError: No module named foo
&gt;&gt;&gt;
</pre>
<p>Failure ! A quick check to <tt class="docutils literal">sys.path</tt> will confirm that if the &quot;site-package&quot; was not
existent, it wasn't included in the <tt class="docutils literal">sys.path</tt>... which makes sense. I'm not aware of
all these details, but why <tt class="docutils literal">distutils2</tt> then tries to install packages in this directory ?</p>
<p>Anyway, if I want to make sure that <tt class="docutils literal"><span class="pre">site-packages</span></tt> gets in <tt class="docutils literal">sys.path</tt>, I can follow <a class="reference external" href="http://superuser.com/questions/247620/how-to-globally-modify-the-default-pythonpath-sys-path">superuser advice</a>:</p>
<pre class="literal-block">
echo ../site-packages &gt; /usr/lib/python2.7/dist-packages/site-packages.pth
</pre>
<p>This will easily add <tt class="docutils literal"><span class="pre">site-packages</span></tt> directory system wide.</p>
</div>
</div>
<div class="section" id="conclusion">
<h3>Conclusion</h3>
<p>Is the packaging system of python dead-simple for one file ? Well, yes, once a straightforward recipe was discovered painfully.</p>
<p>Is it easy to find clear and unambiguous documentation ? Not really.</p>
<p>Is <tt class="docutils literal">distutils2</tt> finished ? Nope.
Did you try with <a class="reference external" href="http://hg.python.org/distutils2/">last available code from hg.python.org</a> ? Yes.</p>
<p>Do you still need to use <tt class="docutils literal">distribute</tt> ? Yes.</p>
<p>Any comments ?</p>
</div>
</div>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=382&amp;md5=b1ad1bba5169dd4715c5a089b8fe888b" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2013/02/22/comparison-of-minimal-packaging-between-distribute-and-distutils2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2013%2F02%2F22%2Fcomparison-of-minimal-packaging-between-distribute-and-distutils2%2F&amp;language=en_GB&amp;category=text&amp;title=comparison+of+minimal+packaging+between+distribute+and+distutils2&amp;description=In+a+pythonic+mind%2C+we+shoud+keep+things+simple+as+possible.+But+when+having+to+deal+with+distribution+of+your+code%2C+especially+if+it%27s+ONE+small+python+file%2C+you%27ll+might...&amp;tags=distribute%2Cdistutils2%2Cpackaging%2Cpython%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Emacs and flymake for python, javascript, php, rst</title>
		<link>https://vaab.blog.kal.fr/2012/09/20/emacs-and-flymake-for-python-javascript-php-rst/</link>
		<comments>https://vaab.blog.kal.fr/2012/09/20/emacs-and-flymake-for-python-javascript-php-rst/#comments</comments>
		<pubDate>Thu, 20 Sep 2012 10:28:16 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[comp]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[sci]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[flymake]]></category>
		<category><![CDATA[jhint]]></category>
		<category><![CDATA[jslint]]></category>
		<category><![CDATA[phplint]]></category>
		<category><![CDATA[rst]]></category>
		<category><![CDATA[rst2html]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=335</guid>
		<description><![CDATA[Emacs is a wonderfull editor, every sane people know this. Here's how to extend your flymake to some trendy languages. You'll find here a general overview by answering question as What's flymake ? for emacs, and How does it work &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2012/09/20/emacs-and-flymake-for-python-javascript-php-rst/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p><a class="reference external" href="http://www.gnu.org/software/emacs/">Emacs</a> is a wonderfull editor, every <a class="reference external" href="http://www.dina.kvl.dk/~abraham/religion/">sane people</a> know this. Here's
how to extend your <a class="reference external" href="http://www.emacswiki.org/emacs/FlyMake">flymake</a> to some trendy languages.</p>
<p>You'll find here a general overview by answering question as <a class="reference internal" href="#what-s-flymake">What's flymake ?</a> for emacs,
and <a class="reference internal" href="#how-does-it-work">How does it work ?</a>.</p>
<p>Following are the snippet of code to have nice <a class="reference external" href="http://www.emacswiki.org/emacs/FlyMake">flymake</a> integration for:</p>
<blockquote>
<ol class="arabic simple">
<li><a class="reference internal" href="#python">Python</a></li>
<li><a class="reference internal" href="#php">PHP</a></li>
<li><a class="reference internal" href="#javascript">Javascript</a></li>
<li><a class="reference internal" href="#restructured-text">ReSTructured Text</a></li>
</ol>
</blockquote>
<p>Happy coding !</p>
<div class="section" id="what-s-flymake">
<h3>What's flymake ?</h3>
<p><tt class="docutils literal"><span class="pre">flymake-mode</span></tt> in emacs is meant to &quot;compile&quot; your code while
you are typing (no need to save) so as to give you interesting
highlights on particular bits of code you've written.</p>
<p>If these can spot <em>syntax errors</em>, code analyzers can go much beyond and
show you <em>logical errors</em> as unused variables, unreachable code, an so
on. And there's more: you can be hinted when <em>breaking code style</em>
conventions that you've chosen, or even <em>code smell</em> detectors (too much
method in an object, too much local variable, ...)</p>
</div>
<div class="section" id="how-does-it-work">
<h3>How does it work ?</h3>
<div class="section" id="the-big-picture">
<h4>The big picture</h4>
<p><tt class="docutils literal"><span class="pre">flymake-mode</span></tt> is very simple, as you type it'll create a copy of your current
emacs buffer in a file usualy called <tt class="docutils literal"><span class="pre">&lt;filename&gt;-flymake.&lt;ext&gt;</span></tt>.</p>
<p>Then, it'll launch an executable on this file and will collect it's standard output.</p>
<p>To work out of the box, the format should be something like this:</p>
<pre class="literal-block">
myfile.myext:&lt;line no&gt;: &lt;ERROR|WARNING&gt;: error message
</pre>
<p>This is a typical output of my <tt class="docutils literal">pycheckers</tt> script which combines <a class="reference external" href="http://pypi.python.org/pypi/pep8">pep8</a>
code style checker and <a class="reference external" href="http://pypi.python.org/pypi/pylint">pylint</a> (syntax, logical, code style, code smell
checking):</p>
<pre class="literal-block">
converter.py:38: ERROR: E501 (pep8) line too long (141 characters)
converter.py:130: ERROR: E303 (pep8) too many blank lines (2)
converter.py:156: WARNING: W0212 (pylint) Access to a protected member _fields_id of a client class
converter.py:185: WARNING: R0911 (pylint) Too many return statements (9/6)
</pre>
<p><tt class="docutils literal">emacs</tt> will then use this output to highlight WARNING and ERROR message in
two different colors.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">Besides helping you in getting better code every day, having the same
format, one by line, with clear tagging of the error type and the analyzer
can be extremely usefull in continuous integration to get a valuable metric
on code quality.</p>
</div>
</div>
<div class="section" id="what-do-i-need">
<h4>What do I need ?</h4>
<p>You'll need to enable flymake once for all by adding the following line to
your <tt class="docutils literal"><span class="pre">~/.emacs</span></tt>, which will launch flymake whenever you'll open a file:</p>
<pre class="literal-block">
(add-hook 'find-file-hook 'flymake-find-file-hook)
</pre>
<p>Then to set up <tt class="docutils literal"><span class="pre">flymake-mode</span></tt> for a langage you'll need to:</p>
<blockquote>
<p>1. add a specific snippet of code in <tt class="docutils literal"><span class="pre">~/.emacs</span></tt> to configure the analyzer (ie:
to set the actual name of the executable analyzer and its command line
arguments if any).</p>
<p>2. create the executable code as it often require some tweaking to get the
correct output. This stage is optional if your analyzer output is already
in the correct format.</p>
</blockquote>
</div>
</div>
<div class="section" id="ok-where-s-the-code">
<h3>Ok, where's the code ?</h3>
<div class="section" id="python">
<h4>Python</h4>
<div class="section" id="analyzer">
<h5>Analyzer</h5>
<p>My <tt class="docutils literal">pycheckers</tt> code analyzer is actually written in python and will call
<a class="reference external" href="http://pypi.python.org/pypi/pep8">pep8</a> and <a class="reference external" href="http://pypi.python.org/pypi/pylint">pylint</a> and ensure that the output format is correct. These two
analyzers are available on <a class="reference external" href="http://pypi.python.org/pypi">PyPI</a> and thus are installable thanks to:</p>
<pre class="literal-block">
pip install pylint
pip install pep8
</pre>
<p>Please check the analyzer code at: <a class="reference external" href="https://gist.github.com/3754270">https://gist.github.com/3754270</a></p>
<p>I typically put the analyzer in <tt class="docutils literal">~/bin/pycheckers</tt> and ensure that it is
executable.</p>
</div>
<div class="section" id="id1">
<h5>Emacs</h5>
<p>Here's the emacs snippet:</p>
<pre class="literal-block">
;; Python flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-pycheckers-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                    'flymake-create-temp-inplace))
        (local-file (file-relative-name
                     temp-file
                     (file-name-directory buffer-file-name))))
      (list &quot;~/bin/pycheckers.py&quot;  (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
            '(&quot;\\.py\\'&quot; flymake-pycheckers-init)))
</pre>
</div>
<div class="section" id="for-the-lazier">
<h5>For the lazier</h5>
<p>This snippet will do the complete job for you:</p>
<pre class="literal-block">
mkdir -p ~/bin &amp;&amp;
cd ~/bin &amp;&amp;
wget https://raw.github.com/gist/3754270/a4fecffaff6ab702f5c8d37332afc90f6461e40b/pycheckers.py &amp;&amp;
chmod +x pycheckers.py &amp;&amp;
cat &lt;&lt;EOF &gt;&gt; ~/.emacs

;; Python flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-pycheckers-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                    'flymake-create-temp-inplace))
        (local-file (file-relative-name
                     temp-file
                     (file-name-directory buffer-file-name))))
      (list &quot;~/bin/pycheckers.py&quot;  (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
            '(&quot;\\.py\\'&quot; flymake-pycheckers-init)))

EOF
</pre>
<p>You'll need to restart <tt class="docutils literal">emacs</tt> for this to work. (Or highlight the added snippet
in the end of your <tt class="docutils literal">.emacs</tt> and call <tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">eval-region</span></tt>)</p>
</div>
</div>
<div class="section" id="php">
<h4>Php</h4>
<div class="section" id="id2">
<h5>Analyzer</h5>
<p>I've also a <tt class="docutils literal">phpcheckers</tt>, even if it is very small, I feel better to know
that I could grep out some specific warnings or add another sub-analyzer quite
easily, and feel free to add your own include path as you wish in the
'packages-path' arguments:</p>
<pre class="literal-block">
#!/bin/bash

phplint --modules-path ~/var/lib/phplint/modules \
        --packages-path /usr/share/php \
        --no-print-notices &quot;$&#64;&quot;
</pre>
<p>So i'm using only <a class="reference external" href="http://www.icosaedro.it/phplint">phplint</a> here.</p>
</div>
<div class="section" id="id3">
<h5>Emacs</h5>
<p>Here's the emacs snippet:</p>
<pre class="literal-block">
;; PHP flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-phplint-init()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
      (list &quot;phpcheckers&quot; (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
             '(&quot;\\.php[345]?$&quot; flymake-phplint-init))
  (add-to-list 'flymake-allowed-file-name-masks
               '(&quot;\\.inc$&quot; flymake-phplint-init)))
</pre>
</div>
<div class="section" id="id4">
<h5>For the lazier</h5>
<p>This snippet will do the complete job for you:</p>
<pre class="literal-block">
mkdir -p ~/bin &amp;&amp;
cd ~/bin &amp;&amp;
cat &lt;&lt;EOF &gt; ~/bin/phpcheckers &amp;&amp;
#!/bin/bash

phplint --modules-path ~/var/lib/phplint/modules \
        --packages-path /usr/share/php \
        --no-print-notices &quot;\$&#64;&quot;
EOF
chmod +x phpcheckers &amp;&amp;
cat &lt;&lt;EOF &gt;&gt; ~/.emacs

;; PHP flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-phplint-init()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                    'flymake-create-temp-inplace))
        (local-file (file-relative-name
                     temp-file
                     (file-name-directory buffer-file-name))))
      (list &quot;~/bin/phpcheckers&quot; (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
            '(&quot;\\.php[345]?$&quot; flymake-phplint-init))
  (add-to-list 'flymake-allowed-file-name-masks
               '(&quot;\\.inc$&quot; flymake-phplint-init)))

EOF
</pre>
<p>You'll need to restart <tt class="docutils literal">emacs</tt> for this to work. (Or highlight the added snippet
in the end of your <tt class="docutils literal">.emacs</tt> and call <tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">eval-region</span></tt>)</p>
</div>
</div>
<div class="section" id="javascript">
<h4>Javascript</h4>
<div class="section" id="id5">
<h5>Analyzer</h5>
<p>I use a combination of <a class="reference external" href="http://www.jslint.com/lint.html">jslint</a> and <a class="reference external" href="http://www.jshint.com/about/">jshint</a>.</p>
<p>This is more work as <a class="reference external" href="http://www.jslint.com/lint.html">jslint</a> is widely criticized for behing too spotty on
some conventions only shared by its author, I find it useful when tamed down
to normal behavior.</p>
<p>Second, it's not so easy to get the correct format out of <a class="reference external" href="http://www.jslint.com/lint.html">jslint</a>. So I
created a <tt class="docutils literal"><span class="pre">jslint-emacs</span></tt> executable that lies in
<tt class="docutils literal"><span class="pre">~/bin/jslint-emacs</span></tt>. Here's the code:</p>
<pre class="literal-block">
#!/bin/bash

filename=&quot;$1&quot;

jslint &quot;$filename&quot; --nomen --maxerr 999999 |

## reformat from:
##
##  #45 Expected exactly one space between 'function' and '('.
##      init: function(parent, dataset, csv_import_record){ // Line 127, Pos 23
##
## to:
##
##  filename.js:94: WARNING: (jslint) Expected exactly one space between 'function' and '('.

         sed -r &quot;N;s/^\s*#[0-9]+ (.*)\n\s+.*\/\/ Line ([0-9]+),.*/$filename:\2: WARNING: W000 (jslint) \1/&quot; |

## Remove garbages lines that were not match by previous regex
## as their is a small header not matching regexp.

         grep -E &quot;^$filename:[0-9]+:&quot; |

         grep -v &quot;at column.*not column.*.&quot; |
         grep -v &quot;Expected '{' and instead saw 'return'&quot; |
         grep -v &quot;Expected exactly one space between ')' and 'return'&quot; |
         grep -v &quot;Combine this with the previous 'var' statement&quot; |
         grep -v &quot;Unexpected 'in'. Compare with undefined, or use .*&quot;

## force errorlevel 0 so as to avoid emacs ``flymake-mode`` to complain
exit 0
</pre>
<p>I've found that <tt class="docutils literal">jshint</tt> can use a specific reporter written in javascript, which
seems perfect to get the correct ouput from it.</p>
<p>This is my <tt class="docutils literal"><span class="pre">~/bin/jshint-emacs</span></tt>:</p>
<pre class="literal-block">
#!/bin/bash

jshint &quot;$1&quot; --reporter ~/.emacs.d/jslint-emacs-reporter.js
</pre>
<p>And of course, my <tt class="docutils literal"><span class="pre">~/.emacs.d/jslint-emacs-reporter.js</span></tt> is available as a
gist here: <a class="reference external" href="https://gist.github.com/3754379">https://gist.github.com/3754379</a></p>
<p>It seems that this javascript reporter could be used also with <tt class="docutils literal">jslint</tt> but I didn't
figure out how to do so. (This was maybe because I've already written the sed/grep thing
before).</p>
<p>Of course, this is my <tt class="docutils literal">~/bin/jscheckers</tt>:</p>
<pre class="literal-block">
#!/bin/bash

jslint-emacs &quot;$1&quot;
jshint-emacs &quot;$1&quot;
</pre>
</div>
<div class="section" id="id6">
<h5>Emacs</h5>
<p>Here's the emacs snippet:</p>
<pre class="literal-block">
;; Javascript flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-jslint-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list &quot;jscheckers&quot; (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
               '(&quot;\\.js\\'&quot; flymake-jslint-init)))
</pre>
</div>
<div class="section" id="id7">
<h5>For the lazier</h5>
<p>This snippet will do the complete job for you:</p>
<pre class="literal-block">
mkdir -p ~/bin &amp;&amp;
cd ~/bin &amp;&amp;
cat &lt;&lt;EOF &gt; ~/bin/jslint-emacs &amp;&amp;
#!/bin/bash

filename=&quot;\$1&quot;

jslint &quot;\$filename&quot; --nomen --maxerr 999999 |

## reformat from:
##
##  #45 Expected exactly one space between 'function' and '('.
##      init: function(parent, dataset, csv_import_record){ // Line 127, Pos 23
##
## to:
##
##  filename.js:94: WARNING: (jslint) Expected exactly one space between 'function' and '('.

         sed -r &quot;N;s/^\s*#[0-9]+ (.*)\n\s+.*\/\/ Line ([0-9]+),.*/\$filename:\2: WARNING: W000 (jslint) \1/&quot; |

## Remove garbages lines that were not match by previous regex
## as their is a small header not matching regexp.

         grep -E &quot;^\$filename:[0-9]+:&quot; |

         grep -v &quot;at column.*not column.*.&quot; |
         grep -v &quot;Expected '{' and instead saw 'return'&quot; |
         grep -v &quot;Expected exactly one space between ')' and 'return'&quot; |
         grep -v &quot;Combine this with the previous 'var' statement&quot; |
      grep -v &quot;Unexpected 'in'. Compare with undefined, or use .*&quot;

## force errorlevel 0 so as to avoid emacs ``flymake-mode`` to complain
exit 0
EOF
chmod +x jslint-emacs &amp;&amp;
cat &lt;&lt;EOF &gt; ~/bin/jscheckers &amp;&amp;
#!/bin/bash

~/bin/jslint-emacs &quot;\$1&quot;
~/bin/jshint-emacs &quot;\$1&quot;

EOF
chmod +x jscheckers &amp;&amp;
mkdir -p ~/.emacs.d &amp;&amp;
cd ~/.emacs.d &amp;&amp;
wget https://raw.github.com/gist/3754379/3c43c50b4d85f50b8314af8e498b1b4f2cee58ea/jslint-emacs-reporter.js &amp;&amp;
cat &lt;&lt;EOF &gt;&gt; ~/.emacs

;; Javascript flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-jslint-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                    'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list &quot;jscheckers&quot; (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
               '(&quot;\\.js\\'&quot; flymake-jslint-init)))

EOF
</pre>
<p>You'll need to restart <tt class="docutils literal">emacs</tt> for this to work. (Or highlight the added snippet
in the end of your <tt class="docutils literal">.emacs</tt> and call <tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">eval-region</span></tt>)</p>
</div>
</div>
<div class="section" id="restructured-text">
<h4>ReSTructured Text</h4>
<div class="section" id="id8">
<h5>Analyzer</h5>
<p>I was surprised to see that <a class="reference external" href="http://docutils.sourceforge.net/docs/user/tools.html">rst2html</a> will make very decent rst analyzer.</p>
<p><a class="reference external" href="http://docutils.sourceforge.net/docs/user/tools.html">rst2html</a> is provided by python <a class="reference external" href="http://pypi.python.org/pypi/docutils">docutils package</a>.</p>
<p>My <tt class="docutils literal">~/bin/rstcheckers</tt>:</p>
<pre class="literal-block">
#!/bin/bash

rst2html &quot;$1&quot; &gt; /dev/null
</pre>
<p>Surprising isn't it ? As it isn't a code analyzer but the compiler itself, it
does it's job really well, and in combination with flymake, it gives you a very
convenient on-the-fly syntax checking.</p>
<p>Note that <tt class="docutils literal">&gt;/dev/null</tt> is required as <tt class="docutils literal">rst2html</tt> jobs is to output HTML from your
<tt class="docutils literal">rst</tt> (which we don't want to see), and it casts errors on the standard error pipe.</p>
</div>
<div class="section" id="id9">
<h5>Emacs</h5>
<p>Here's the emacs snippet:</p>
<pre class="literal-block">
;; ReSTructured Text Flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-rst-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list &quot;rstcheckers&quot; (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
               '(&quot;\\.rst\\'&quot; flymake-rst-init)))
</pre>
</div>
<div class="section" id="id10">
<h5>For the lazier</h5>
<p>This snippet will do the complete job for you:</p>
<pre class="literal-block">
mkdir -p ~/bin &amp;&amp;
cd ~/bin &amp;&amp;
cat &lt;&lt;EOF &gt; ~/bin/rstcheckers &amp;&amp;
#!/bin/bash

rst2html &quot;\$1&quot; &gt; /dev/null
EOF
chmod +x rstcheckers &amp;&amp;
cat &lt;&lt;EOF &gt;&gt; ~/.emacs

;; ReSTructured Text Flymake configuration

(when (load &quot;flymake&quot; t)
  (defun flymake-rst-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                    'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list &quot;rstcheckers&quot; (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
               '(&quot;\\.rst\\'&quot; flymake-rst-init)))

EOF
</pre>
<p>You'll need to restart <tt class="docutils literal">emacs</tt> for this to work. (Or highlight the added snippet
in the end of your <tt class="docutils literal">.emacs</tt> and call <tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">eval-region</span></tt>)</p>
</div>
</div>
</div>
<div class="section" id="conclusion">
<h3>Conclusion</h3>
<p>I hope this will let you add some more language to your emacs
<tt class="docutils literal"><span class="pre">flymake-mode</span></tt>. If you spot any errors, please let me know.</p>
</div>
</div>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=335&amp;md5=9ac35db7c92e40c75f8ffba62903aee9" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2012/09/20/emacs-and-flymake-for-python-javascript-php-rst/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2012%2F09%2F20%2Femacs-and-flymake-for-python-javascript-php-rst%2F&amp;language=en_GB&amp;category=text&amp;title=Emacs+and+flymake+for+python%2C+javascript%2C+php%2C+rst&amp;description=Emacs+is+a+wonderfull+editor%2C+every+sane+people+know+this.+Here%27s+how+to+extend+your+flymake+to+some+trendy+languages.+You%27ll+find+here+a+general+overview+by+answering+question+as...&amp;tags=emacs%2Cflymake%2Cjhint%2Cjslint%2Cphplint%2Crst%2Crst2html%2Cblog" type="text/html" />
	</item>
		<item>
		<title>inconsistent duplicate attribute mailhost</title>
		<link>https://vaab.blog.kal.fr/2011/04/10/inconsistent-duplicate-attribute-mailhost/</link>
		<comments>https://vaab.blog.kal.fr/2011/04/10/inconsistent-duplicate-attribute-mailhost/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 22:08:04 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[openldap]]></category>
		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=102</guid>
		<description><![CDATA[Adding a new schema in LDAP can give you headache. I've the cure for this one: Inconsistent duplicate attributeType: "mailHost" This is due to a new misc.schema that is now default in Ubuntu Lucid at least (and maybe other distribution) &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2011/04/10/inconsistent-duplicate-attribute-mailhost/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p>Adding a new schema in LDAP can give you headache. I've the cure for this one:</p>
<pre>
Inconsistent duplicate attributeType: "mailHost"
</pre>
<p>This is due to a new <em>misc.schema</em> that is now default in Ubuntu Lucid at least (and maybe other distribution) and defines a <em>mailhost</em> attribute.</p>
<p>You'll encounter this error when trying to add another schema defining this same attribute. I have a <a href="http://mds.mandriva.org/svn/mmc-projects/mmc-core/trunk/agent/contrib/ldap/mail.schema">mail.schema</a> comming from <a href="http://mds.mandriva.org/">Mandriva Directory Server</a>, which tries to do so. And a small google reveals that <a href="http://www.openldap.org/lists/openldap-software/200608/msg00175.html">qmail.schema</a> has similar problem.</p>
<p>2 solutions:</p>
<ul>
<li>Either remove the attribute from your new schema by deleting the attribute entry in the schema file and remove any reference to mailhost anywhere it appears in the file. I wouldn't recommend this.</li>
<li>Either remove the <em>misc.schema</em> from your ldap server. Cross fingers that it isn't used too much ;)</li>
</ul>
<p>Et voilà !</p>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=102&amp;md5=31b66c287e90d6d49ad1768a6f05f9e3" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2011/04/10/inconsistent-duplicate-attribute-mailhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2011%2F04%2F10%2Finconsistent-duplicate-attribute-mailhost%2F&amp;language=en_GB&amp;category=text&amp;title=inconsistent+duplicate+attribute+mailhost&amp;description=Adding+a+new+schema+in+LDAP+can+give+you+headache.+I%27ve+the+cure+for+this+one%3A+Inconsistent+duplicate+attributeType%3A+%22mailHost%22+This+is+due+to+a+new+misc.schema+that+is+now...&amp;tags=openldap%2Cschema%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Enabling Ctrl-S for forward-history-search in bash</title>
		<link>https://vaab.blog.kal.fr/2010/11/11/enabling-ctrl-s-for-forward-history-search-in-bash/</link>
		<comments>https://vaab.blog.kal.fr/2010/11/11/enabling-ctrl-s-for-forward-history-search-in-bash/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 11:58:51 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[comp]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[sci]]></category>
		<category><![CDATA[readline]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=67</guid>
		<description><![CDATA[Ctrl-R and Ctrl-S are advertised in every readline command-line to do backward and forward search in your command history (as emacs does on text with the same shortcuts). And you've probably come to the fact that if Ctrl-R is working &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2010/11/11/enabling-ctrl-s-for-forward-history-search-in-bash/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p>Ctrl-R and Ctrl-S are advertised in every <em>readline</em> command-line to do backward and forward search in your command history (as <em>emacs</em> does on text with the same shortcuts).</p>
<p>And you've probably come to the fact that if Ctrl-R is working (and you use it every day), Ctrl-S doesn't seem to work and freezes the screen. So you've just learned not to use Ctrl-S.</p>
<p><em>readline</em> based command-line program (as any unix shell) will answer to Ctrl-S <strong>if they receive the keystroke</strong>. The keystroke Ctrl-S actually does not reach <em>readline</em> because it's caught by the TTY driver. TTY driver will trigger a pause in the reception of characters upon Ctrl-S keystroke, and this is why the screen appears to freeze. You can unfreeze with Ctrl-Q.</p>
<p>This pausing mechanism is from old times when you could ask for other end to pause sending characters. This was meant to prevent character loss. With nowadays hardware, this is not useful anymore, and you can safely de-activate this obsolete feature to enable back Ctrl-S in your <em>readline</em> based command-line with:</p>
<pre>stty stop ''</pre>
<p>Note that you can put this in your <em>~/.bashrc</em> if needed.</p>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=67&amp;md5=b53863f8e870a41cbc58ddc27a557164" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2010/11/11/enabling-ctrl-s-for-forward-history-search-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2010%2F11%2F11%2Fenabling-ctrl-s-for-forward-history-search-in-bash%2F&amp;language=en_GB&amp;category=text&amp;title=Enabling+Ctrl-S+for+forward-history-search+in+bash&amp;description=Ctrl-R+and+Ctrl-S+are+advertised+in+every+readline+command-line+to+do+backward+and+forward+search+in+your+command+history+%28as+emacs+does+on+text+with+the+same+shortcuts%29.+And+you%27ve...&amp;tags=readline%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Import / Export ldap database</title>
		<link>https://vaab.blog.kal.fr/2010/03/10/import-export-ldap-database/</link>
		<comments>https://vaab.blog.kal.fr/2010/03/10/import-export-ldap-database/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 08:22:52 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[openldap]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=38</guid>
		<description><![CDATA[Importing data to LDAP server didn't sound obvious for me, so here's how to import / export ldap database. This is usefull if you want to migrate your LDAP database from one server to another. Export Export seems quite easy &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2010/03/10/import-export-ldap-database/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p>Importing data to LDAP server didn't sound obvious for me, so here's how to import / export ldap database. This is usefull if you want to migrate your LDAP database from one server to another.</p>
<div class="section" id="export">
<h3>Export</h3>
<p>Export seems quite easy and well-known:</p>
<pre class="literal-block">
# slapcat
</pre>
<p>This will dump (if run as <tt class="docutils literal">root</tt> user) the complete ldap database information on <tt class="docutils literal">stdout</tt>.</p>
<p>You can use this command to make backups of your <tt class="docutils literal">OpenLDAP</tt> database, for example:</p>
<pre class="literal-block">
# slapcat | bzip2 &gt; mybase.ldif.bz2
</pre>
<p>This solution is not optimum because of the existence of structural attributes in the slapcat dump.</p>
<div class="section" id="structural-attributes">
<h4>Structural Attributes</h4>
<p><tt class="docutils literal">slapcat</tt> output contains all the LDAP database including some structural information as values associated to attribute <tt class="docutils literal">modifyTimestamp</tt>, <tt class="docutils literal">createTimestamp</tt>, <tt class="docutils literal">creatorsName</tt> (and so on ...). These are set automatically by the ldap subsystem when you add/modify info in the ldap database, and thus cannot be set directly. These are similar to meta information stored by filesystems for each files (user, group, permissions, date of creation ...).</p>
</div>
<div class="section" id="stripping-structural-attributes">
<h4>Stripping structural attributes</h4>
<p>Applying output of a <tt class="docutils literal">slapcat</tt> output directly to <tt class="docutils literal">ldapadd</tt> will issue this error message (as of openldap 2.4.15):</p>
<pre class="literal-block">
# cat mybase.ldif | ldapadd -D cn=admin,dc=example,dc=org -W
Enter LDAP Password:
adding new entry &quot;dc=example,dc=org&quot;
ldap_add: Constraint violation (19)
additional info: structuralObjectClass: no user modification allowed
</pre>
<p>This error message simply states that the attribute <tt class="docutils literal">structuralObjectClass</tt> is not to be modified by any user (even administrator).</p>
<p>These structural information do not carry any information you've stored in the LDAP, so they can be stripped away without any second thought.</p>
<p>Here's how to create a dump stripped out from its structural information:</p>
<pre class="literal-block">
slapcat |
    egrep -v  &quot;^(structuralObjectClass|entryUUID|creatorsName|modifiersName|createTimestamp|modifyTimestamp|entryCSN):&quot; |
    bzip2 &gt; mybase.ldif.bz2
</pre>
<p>Note: this <tt class="docutils literal">egrep</tt> filter works because all stripped entries are one-liners.</p>
</div>
</div>
<div class="section" id="import">
<h3>Import</h3>
<p>Once stripped, the import is quite simple:</p>
<pre class="literal-block">
# cat mybase.ldif | \
    ldapadd -D cn=admin,dc=example,dc=org -W
</pre>
</div>
<div class="section" id="deleting-duplicates">
<h3>Deleting duplicates</h3>
<p>If you have already some entries, you might end up with this error message when trying to import data with the previous command:</p>
<pre class="literal-block">
adding new entry &quot;dc=example,dc=org&quot;
ldap_add: Already exists (68)
</pre>
<p>You might want to overwrite all existing data with the imported values. You should probably think about removing all previous data with:</p>
<pre class="literal-block">
# ldapdelete -r -D cn=admin,dc=example,dc=org dc=example,dc=org -W
</pre>
<p>This should recursively (thanks to the <tt class="docutils literal"><span class="pre">-r</span></tt> option) delete all entries in <tt class="docutils literal">dc=example,dc=org</tt>.</p>
<p>That's all you should need to know to import your ldap database.</p>
</div>
</div>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=38&amp;md5=a88086809840a2a8e5a0b5702d6e35ea" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2010/03/10/import-export-ldap-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2010%2F03%2F10%2Fimport-export-ldap-database%2F&amp;language=en_GB&amp;category=text&amp;title=Import+%2F+Export+ldap+database&amp;description=Importing+data+to+LDAP+server+didn%27t+sound+obvious+for+me%2C+so+here%27s+how+to+import+%2F+export+ldap+database.+This+is+usefull+if+you+want+to+migrate+your+LDAP+database...&amp;tags=openldap%2Cblog" type="text/html" />
	</item>
		<item>
		<title>How to add a schema in OpenLDAP 2.4</title>
		<link>https://vaab.blog.kal.fr/2010/03/06/how-to-add-a-schema-in-openldap-24/</link>
		<comments>https://vaab.blog.kal.fr/2010/03/06/how-to-add-a-schema-in-openldap-24/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 17:23:49 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[openldap]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=34</guid>
		<description><![CDATA[In version prior to 2.4, administrators were used to configure slapd through its /etc/ldap/slapd.conf. That was good ol' time. Since version 2.4, slapd configuration is stored right in itself !. This may sound as a good idea, but is really &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2010/03/06/how-to-add-a-schema-in-openldap-24/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p>In version prior to 2.4, administrators were used to configure
<tt class="docutils literal">slapd</tt> through its <tt class="docutils literal">/etc/ldap/slapd.conf</tt>. That was good ol'
time.</p>
<p>Since version 2.4, <tt class="docutils literal">slapd</tt> configuration is stored right in
itself !. This may sound as a good idea, but is really
unpractical: administrators needs to really master LDAP now to
configure <tt class="docutils literal">slapd</tt>: use
<tt class="docutils literal">ldapmodify</tt>/<tt class="docutils literal">ldapsearch</tt>/<tt class="docutils literal">ldapadd</tt>, or delve into some
<a class="reference external" href="http://en.wikipedia.org/wiki/LDAP_Data_Interchange_Format">LDIF</a> files. Also, simple tasks (as adding a schema definition
to the server) are now quite tedious. Although the complete
configuration is accessible as <tt class="docutils literal">ldif</tt> files, I concider
<tt class="docutils literal">ldif</tt> file format as <tt class="docutils literal">XML</tt>: it's way too verbose and tedious
to read and be maintained by a human being. And above all, it's
yet another language to master.</p>
<p>In last Ubuntu as of 2010-03-06, this change was not correctly reported in LDAP
servers documentation. These are 2 bug reports on this issue:
<a class="reference external" href="https://bugs.launchpad.net/ubuntu/+source/openldap/+bug/463684">Bug #463684</a>, <a class="reference external" href="https://bugs.launchpad.net/ubuntu/+source/openldap/+bug/442498">Bug #442498</a>. A quick glance to these bug
reports will show you that this changement is a great source of
distress for a lot of casual administrators (as I am).</p>
<p>The <a class="reference external" href="http://doc.ubuntu.com/ubuntu/serverguide/C/openldap-server.html">last documentation from Ubuntu</a> has not explained the changes and is not that clear.</p>
<p><em>EDIT</em> (2012-01-05): the last link have now some valuable information despite the fact that it seems not anymore maintained. I would rather hint towards the <a class="reference external" href="https://help.ubuntu.com/community/OpenLDAPServer">community help site page on OpenLDAP</a> of ubuntu, which seems a natural and well documented point to get information.</p>
<div class="section" id="what-is-the-reason-behind-this-change">
<h3>What is the reason behind this change ?</h3>
<p>First, openldap changed it's default way to store configuration
files. The idea is simple: The configuration is stored in a
SEPARATE ldap database identified by the prefix &quot;cn=config&quot;. And
you'll be able to declare separate databases with different
credentials, or backend (<tt class="docutils literal">bdb</tt> or <tt class="docutils literal">hdb</tt> for instance).</p>
<p>With this new way of using the configuration, you can make
changes to configuration without restarting <tt class="docutils literal">slapd</tt>.</p>
<p><a class="reference external" href="https://lists.ubuntu.com/archives/ubuntu-server/2009-August/003182.html">This thread post</a> is quite clear on what is going at Ubuntu around OpenLDAP.</p>
</div>
<div class="section" id="how-to-use-the-config-database">
<h3>How to use the config database ?</h3>
<p>The configuration database does not need any password for root
system user on local connection. You can see its content with
<tt class="docutils literal">ldapsearch</tt> this way:</p>
<pre class="literal-block">
sudo ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config
</pre>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">if you are on ubuntu, ldapsearch is available in
<tt class="docutils literal"><span class="pre">ldap-utils</span></tt> package.</p>
</div>
<dl class="docutils">
<dt>This database contains roughly:</dt>
<dd><ul class="first last simple">
<li>some basic slapd daemon configuration parameters (pid file, loglevel ...)</li>
<li>loaded schemas</li>
<li>and databases configuration</li>
</ul>
</dd>
</dl>
<p>To make addition to this database you'll need to inject <tt class="docutils literal">ldif</tt>
files for example through <tt class="docutils literal">ldapadd</tt>:</p>
<pre class="literal-block">
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f file.ldif
</pre>
<p>Or, better, use tool like <a class="reference external" href="http://www.lichteblau.com/ldapvi/">ldapvi</a></p>
<pre class="literal-block">
sudo ldapvi -h ldapi:/// -D cn=config -Y EXTERNAL -b cn=config
</pre>
<dl class="docutils">
<dt>You'll need to make additions/modifications to this database to:</dt>
<dd><ul class="first last simple">
<li>add new schemas</li>
<li>add new databases (and you'll require to create at least one database)</li>
<li>add indexes to databases</li>
<li>modify LogLevel</li>
<li>...</li>
</ul>
</dd>
</dl>
</div>
<div class="section" id="how-to-add-a-new-schema">
<h3>How to add a new schema ?</h3>
<p>This is the common way to add a schema:</p>
<pre class="literal-block">
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
</pre>
</div>
<div class="section" id="how-to-add-a-new-database">
<h3>How to add a new database ?</h3>
<p>The following method will require that <tt class="docutils literal">nis</tt> schema was loaded as it defines rule
on the <tt class="docutils literal">shadowLastChange</tt> attribute that is defined in this schema.</p>
<p>Then copy-paste this code into a ldif file <tt class="docutils literal">/tmp/database.ldif</tt>:</p>
<pre class="literal-block">
# Load dynamic backend modules
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib/ldap
olcModuleload: back_hdb

# Database settings
dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcSuffix: dc=example,dc=com
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=example,dc=com
olcRootPW: secret
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword by dn=&quot;cn=admin,dc=example,dc=com&quot; write by anonymous auth by self write by * none
olcAccess: to attrs=shadowLastChange by self write by * read
olcAccess: to dn.base=&quot;&quot; by * read
olcAccess: to * by dn=&quot;cn=admin,dc=example,dc=com&quot; write by * read
</pre>
<dl class="docutils">
<dt>You should change:</dt>
<dd><ul class="first last simple">
<li><tt class="docutils literal">dc=example,dc=com</tt> with your own prefix</li>
<li>'secret' value of <tt class="docutils literal">olcRootPW</tt> should be updated by your password.</li>
</ul>
</dd>
</dl>
<p><em>EDIT (2012-01-05):</em> You will have to remove the first part about loading the <tt class="docutils literal">hdb</tt> module if you are in recent ubuntu installation, as it is already loaded, and will trigger a fatal error preventing the following <tt class="docutils literal">ldapadd</tt> command to work as expected.</p>
<p><em>EDIT (2013-12-30):</em> An existing database was created by ubuntu before installation and can spew very annoying error message and block <tt class="docutils literal">slapcat</tt>. Unfortunately, you can't delete it with <tt class="docutils literal">ldapvi</tt>. The best way I found was to stop <tt class="docutils literal">slapd</tt>, then <tt class="docutils literal">cd /etc/ldap/slapd.d/cn=config</tt>, remove <tt class="docutils literal"><span class="pre">olcDatabase={1}hdb.ldif</span></tt> file, and relaunch <tt class="docutils literal">slapd</tt>. Please check that content of the file removed is the one mentionning <tt class="docutils literal">nodomain</tt>.</p>
<p>Once you've created this file, you can add your new database with:</p>
<pre class="literal-block">
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /tmp/database.ldif
</pre>
<p>You can then remove <tt class="docutils literal">/tmp/database.ldif</tt>.</p>
<p>Notice that <tt class="docutils literal">slapcat</tt> should work only after having configured
a database. Without any database you'll get this error:</p>
<pre class="literal-block">
$ slapcat
Available database(s) do not allow slapcat
</pre>
<p>Because <tt class="docutils literal">cn=config</tt> database doesn't allow <tt class="docutils literal">slapcat</tt> and no
other database has been configured.</p>
</div>
</div>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=34&amp;md5=82e433160894aa833db9a0e550502ed0" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2010/03/06/how-to-add-a-schema-in-openldap-24/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2010%2F03%2F06%2Fhow-to-add-a-schema-in-openldap-24%2F&amp;language=en_GB&amp;category=text&amp;title=How+to+add+a+schema+in+OpenLDAP+2.4&amp;description=In+version+prior+to+2.4%2C+administrators+were+used+to+configure+slapd+through+its+%2Fetc%2Fldap%2Fslapd.conf.+That+was+good+ol%27+time.+Since+version+2.4%2C+slapd+configuration+is+stored+right+in+itself+%21....&amp;tags=openldap%2Cubuntu%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Removing duplicate contacts</title>
		<link>https://vaab.blog.kal.fr/2009/11/29/removing-duplicate-contacts/</link>
		<comments>https://vaab.blog.kal.fr/2009/11/29/removing-duplicate-contacts/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 13:24:44 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=25</guid>
		<description><![CDATA[After the sync of iPhone / Thunderbird / Google Contacts and importing contacts from my telephone, I had several duplicate entry. Duplicate Contact Manager saved me.]]></description>
				<content:encoded><![CDATA[<p>After the sync of iPhone / Thunderbird / Google Contacts and importing contacts from my telephone, I had several duplicate entry. <a title="Duplicate Contact Manager" href="https://addons.mozilla.org/fr/thunderbird/addon/2505">Duplicate Contact Manager</a> saved me.</p>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=25&amp;md5=bcfd64f408d6fcdcf8e81c832fddd1b4" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2009/11/29/removing-duplicate-contacts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2009%2F11%2F29%2Fremoving-duplicate-contacts%2F&amp;language=en_GB&amp;category=text&amp;title=Removing+duplicate+contacts&amp;description=After+the+sync+of+iPhone+%2F+Thunderbird+%2F+Google+Contacts+and+importing+contacts+from+my+telephone%2C+I+had+several+duplicate+entry.+Duplicate+Contact+Manager+saved+me.&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>iPhone, Thunderbird and Google Sync</title>
		<link>https://vaab.blog.kal.fr/2009/11/29/iphone-thunderbird-and-google-sync/</link>
		<comments>https://vaab.blog.kal.fr/2009/11/29/iphone-thunderbird-and-google-sync/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 13:23:40 +0000</pubDate>
		<dc:creator><![CDATA[vaab]]></dc:creator>
				<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://vaab.blog.kal.fr/?p=7</guid>
		<description><![CDATA[I recently acquired an iPhone. As any stubborn tech maniac, I cannot live without a proper synchronization between my Mails, Contacts, and Agenda. I can't figure out any decent reason to have an iPhone if these cannot be achieved. Hopefully, &#8230;<p class="read-more"><a href="https://vaab.blog.kal.fr/2009/11/29/iphone-thunderbird-and-google-sync/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p>I recently acquired an iPhone. As any stubborn tech maniac, I cannot live without a proper synchronization between my Mails, Contacts, and Agenda. I can't figure out any decent reason to have an iPhone if these cannot be achieved.</p>
<p>Hopefully, there's a lot of zealous people on the net that share my mental disorder. Thanks to them, let's see how I managed <strong>synchronization between Thunderbird/Lightning - Google Mail/Agenda - iPhone</strong>. It'll not cover Mail synchronization as this is a quite simple and common pattern.</p>
<p>This <strong>applies to any system (Linux, Windows, Macintosh)</strong> as Thunderbird and Google web services are OS agnostic.</p>
<h4>Principle</h4>
<p>Google Account will be our central exchange platform. So <a title="go get an account" href="http://mail.google.com/mail/signup">go get an account</a> if you haven't one yet.</p>
<h4>Thunderbird sync with Google</h4>
<h5>Contact synchronization</h5>
<p>Install <a title="Zindus extension" href="https://addons.mozilla.org/fr/thunderbird/addon/6095">Zindus extension</a> in Thunderbird. This extension manage synchronisation towards any number of Google or Zimbra accounts.</p>
<p>Configuration can be a bit tricky, in the extension configuration panel:</p>
<ol>
<li>Enter your Google Account credentials, and check them with the test button.</li>
<li>Then you should check the advanced google settings to ask for XML output</li>
<li>Ask for your first synchronisation</li>
</ol>
<p><em>Sanity check:</em> Look at your Contact Book on Thunderbird before and after synchronization (same for GMail). If you feel like you should clean that mess, check <a title="Removing Duplicate Contacts" href="http://vaab.blog.kal.fr/2009/11/29/removing-duplicate-contacts/">my other blog post</a> on cleaning contact list.</p>
<h5>Calendars</h5>
<p>Note that Agenda support in Thunderbird is brought by <a title="the Lightning extension" href="https://addons.mozilla.org/fr/thunderbird/addon/2313">the Lightning extension</a>. Which you should have installed prior to what's following.</p>
<p>Notice that Lightning and Google can be synchronized out-of-the box, no new extension here:</p>
<ol>
<li>Get in your google account preferences and check your XML private address to the agenda you want to sync</li>
<li>Use this XML address as a New Network Agenda in Lightning</li>
</ol>
<p>That's it.</p>
<p><em>Sain check:</em> create a new dummy event in one end (Lightning or Google), and check it appears on the other end. Suppress it on the other end, and check that it disappeared from the first end.</p>
<h4>iPhone sync with Google</h4>
<h5>Contact &amp; Agenda</h5>
<p>In Mail, Contact, Agendas settings, you'll have to Add an Exchange Account towards "m.google.com". Note that:</p>
<ul>
<li>email fields is not used, so set as you mind</li>
<li>Exchange server might not appear first, so don't mind, iPhone will ask it after a first try to standard servers (I guess)</li>
<li>do not set the Mail synchronization unless that is what you want to do.</li>
</ul>
<p>This might delete previous contact. I didn't mind as my iPhone was empty.</p>
<p><em>Sanity check:</em> You should look at your agenda and contacts, create an event and a contact, and check that in Google and Thunderbird all is well reported. (You might need to ask for synchronization in Zindus extension to get a quick change synchronized.)</p>
<p>That's all.</p>
<h4>References</h4>
<p>You should definitively check this reference with more details:</p>
<ul>
<li><a title="Sync between Thunderbird and iPhone" href="http://howto.landure.fr/gnu-linux/synchronisation-du-calendrier-et-des-contacts-entre-thunderbird-et-un-iphone">Synchronisation du Calendrier et des Contacts sous Thunderbird</a> - in french.</li>
</ul>
 <p><a href="https://vaab.blog.kal.fr/?flattrss_redirect&amp;id=7&amp;md5=f79e77f00f53b2206ca8515484601bd2" title="Flattr" target="_blank"><img src="https://vaab.blog.kal.fr/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>https://vaab.blog.kal.fr/2009/11/29/iphone-thunderbird-and-google-sync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=vaab&amp;popout=1&amp;url=https%3A%2F%2Fvaab.blog.kal.fr%2F2009%2F11%2F29%2Fiphone-thunderbird-and-google-sync%2F&amp;language=en_GB&amp;category=text&amp;title=iPhone%2C+Thunderbird+and+Google+Sync&amp;description=I+recently+acquired+an+iPhone.+As+any+stubborn+tech+maniac%2C+I+cannot+live+without+a+proper+synchronization+between+my+Mails%2C+Contacts%2C+and+Agenda.+I+can%27t+figure+out+any+decent+reason...&amp;tags=blog" type="text/html" />
	</item>
	</channel>
</rss>
