Monthly Archives: June 2012

Sqlite3 shell and arrow keys in Debian

In Debian, the arrow keys do not work in the sqlite3 shell by default. For example arrow up-down doesn’t work to browse the command history, and arrow left-right doesn’t work to edit the current command line.

This is intentional, according to this conversation:
http://www.mail-archive.com/sqlite-users@sqlite.org/msg68970.html

The reason: the command line editing features are an external dependency, and so the maintainers of the sqlite3 binary package have decided not to make assumptions about the available external libraries, and by default do not make references to them, otherwise the binary could be unusable.

To enable the command line editing features, you have to build sqlite3 from source. During the build, the available command line editing libraries are automatically detected and enabled, if any.

apt-get source sqlite3
cd sqlite3-3.7.13
./configure
make
make install

If after this the arrow keys are still not working, that must be because you don’t have any command line editing libraries in your system.

How to install Bazaar in a shared hosting environment

Install pip with easy_install

easy_install --user pip

Update PATH

Unless you have already done it, add ~/.local/bin to PATH, because pip will install binaries there.

PATH=~/.local/bin:$PATH

Install Bazaar and recommended python modules using pip

http://wiki.bazaar.canonical.com/InstallationFaq

pip install --user pyrex  # optional
pip install --user paramiko  # optional
pip install --user bzr==2.5  # or whatever is the latest stable version

Additional plugins

You might want to install some additional plugins too:

pip install --user bzr-svn
pip install --user bzr-git 
pip install --user bzr-rebase
pip install --user bzr-fastimport

Or find more interesting plugins:

pip search bzr

Setup and test svn post-commit hook to send commit log

It’s been a while since I’ve done this, and the tools have evolved since then. Follow these steps to configure, test first, and in the end activate the hook.

Get the sample mailer script

This may depend on your distro/OS, usually there is a package called subversion-tools.

cd $REPOROOT
cp /path/to/subversion-tools/hook-scripts/mailer/mailer.py hooks
cp /path/to/subversion-tools/hook-scripts/mailer/mailer.conf.example mailer.conf

Edit mailer.conf

In my case I only needed to override/uncomment these settings:

mail_command = /usr/sbin/sendmail
commit_subject_prefix = [svn-myproject]
from_addr = noreply@mydomain.com
to_addr = commits-myproject@mydomain.com  # this is a mailing list

Pick a revision number for testing

You can pick any revision, just make sure it exists. You can find the latest revision like this:

svnlook info $REPOROOT
svnlook youngest $REPOROOT

Test the hook script

Confirm that the last line of the hook script template ($REPOROOT/hooks/post-commit.tmpl) is the same as this:

"$REPOS"/hooks/mailer.py commit "$REPOS" $REV "$REPOS"/mailer.conf

This is the default on recent versions of Linux. It uses the absolute path to mailer.py and mailer.conf, at the locations where we copied them in an earlier step. The correct path is important, otherwise you will get errors like “mailer.py: command not found”

Run the hook script:

sh $REPOROOT/hooks/post-commit.tmpl $REPOROOT $REVNO

where $REVNO is some revision number (for example the one returned by svnlook youngest). After this you should receive an email with the details of the commit, or some error message should appear in the terminal that you can debug.

Activate the hook

cd $REPOROOT
chmod +x hooks/post-commit.tmpl
mv hooks/post-commit.tmpl hooks/post-commit

That’s it!  Note that it is important to remove hooks/post-commit.tmpl file (or truncate to 0 size), otherwise the real hook script (without .tmpl extension) will be ignored. The hook script should be executable, otherwise Subversion will not run it.

UnicodeEncodeError: ‘ascii’ codec can’t encode characters

When coding in python, I’ve been hit by the following error every once in a while:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 25-28: ordinal not in range(128)

Today I finally figured why:

$ python -c 'import sys; print sys.stdout.encoding'
$ US-ASCII

Although my terminal application is capable of outputting unicode characters, python (2.6) somehow does not know it, and tries to output everything in ascii, hence the error. The solution is to set PYTHONIOENCODING in my ~/.bashrc:

export PYTHONIOENCODING=utf-8