Friday, February 17, 2012

Python Imaging Library Compiled

The compiled Python Imaging Library (version 1.1.7 for python 2.4-2.7 i386 and python 2.7 x86_64) can be found here. See the other post how to get it compiled in Debian.

Thursday, February 16, 2012

How to Install Python Imaging Library in Debian

If you need install Python Imaging Library into virtual environment under Debian you will need set location of several libraries (libfreetype, libjpeg). First of all let setup pre-requirements so we can compile PIL.
apt-get -y install build-essential python-dev \
  python-virtualenv libbz2-dev zlib1g-dev \
  libfreetype6-dev libjpeg8-dev
The script below simplify PIL configuration/setup procedure.
# Download PIL and uzip it
wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar xzf Imaging-1.1.7.tar.gz

# create virtual environment
virtualenv env

ARCH=i386
#ARCH=x86_64

cd Imaging-1.1.7
# Set location of libjpeg8-dev
sed -e "s,JPEG_ROOT = None,JPEG_ROOT = '/usr/lib/$ARCH-linux-gnu',g" \
  setup.py > /tmp/x && mv /tmp/x setup.py

# Set location of zlib1g-dev
sed -e "s,ZLIB_ROOT = None,ZLIB_ROOT = '/usr/lib/$ARCH-linux-gnu',g" \
  setup.py > /tmp/x && mv /tmp/x setup.py

# Set location of libfreetype6-dev
sed -e "s,FREETYPE_ROOT = None,FREETYPE_ROOT = '/usr/lib/$ARCH-linux-gnu',g" \
  setup.py > /tmp/x && mv /tmp/x setup.py

# Proceed with installation into virtual environment
../env/bin/python setup.py install
The virtual environment is ready to be used with projects dependent on PIL, e.g. captcha, etc.

You can download pre-compiled version of PIL per this post.

Wednesday, February 15, 2012

How to Revert Broken Package in Debian

You just made upgrade of your Debian testing box and noticed something went wrong, some daemon not starting and you have no idea what to do until the bug will be fixed. Fortunately, you are able to revert broken package in Debian. Here we are going revert broken bind9 package version 1:9.8.1.dfsg.P1-2 and replace it with last known to work.
  1. We need to find last known to work version of the broken package. Take a look at /var/log/apt/history.log. You should be able to find information about the package failed to install/configure:
    Upgrade: ..., bind9:i386 (9.7.3.dfsg-1+b1, 
    9.8.1.dfsg.P1-2)...
    
    So here version 9.7.3.dfsg-1+b1 is replaced by 9.8.1.dfsg.P1-2. Thus we found last working version.
  2. Since we know version (9.7.3.dfsg-1+b1) of the bind9 package we can install it from snapshot.debian.org. Go to that site and search for your package. You will get a list of various versions available. Follow link for with version that you found previously. You will get a list of various options, including source, architecture specific files, etc.
    bind9_9.7.3.dfsg-1+b1_i386.deb
    Seen in debian on 2011-04-20 22:16:02 in 
    /pool/main/b/bind9.
    
    Follow link /pool/main/b/bind9. In my case it was:
    http://snapshot.debian.org/archive/debian/20110420T221602Z/pool/main/b/bind9/
    
  3. Add snapshot url to file /etc/apt/sources.list:
    deb http://snapshot.debian.org/archive/debian/20110420T221602Z testing main
    
  4. Update your apt repository with the following command:
    apt-get -o Acquire::Check-Valid-Until=false update
    
  5. Have a look at updated package information:
    apt-cache showpkg bind9
    
    You should be able to see something like this:
    Versions: 
    1:9.8.1.dfsg.P1-2 ...
    1:9.7.3.dfsg-1 ...
    
    1:9.7.3.dfsg-1 is the version we need.
  6. Remove broken package and related dependencies:
    apt-get remove bind9
    apt-get autoremove
    
  7. Install version we need:
    apt-get install bind9=1:9.7.3.dfsg-1
    
    Since it complains:
    The following packages have unmet dependencies:
     bind9 : Depends: bind9utils (= 1:9.7.3.dfsg-1) but 1:9.8.1.dfsg.P1-2 is to be installed
    
    ... let add that one dependency for bind9utils as well.
    apt-get install bind9=1:9.7.3.dfsg-1 bind9utils=1:9.7.3.dfsg-1
    
At this point you have reverted broken bind9 package to last known to be working.

Package pinning

We will use apt pinning feature to prevent packages from being upgraded. Just create a file /etc/apt/preferences.d/bind9 and add the following:
Package: bind9                                                                 
Pin: version 1:9.7.3*                                                          
Pin-Priority: 1001                                                             
                                                                               
Package: bind9utils                                                            
Pin: version 1:9.7.3*                                                          
Pin-Priority: 1001
The next time you run upgrade these two packages remain untouched.

Thursday, December 22, 2011

How to Convert FLAC+CUE to MP3

Converting flac to mp3 package pre-requirements are the same as published in previous post (How to Convert APE+CUE to MP3). So I will add what is necessary. You will need flac package.
apt-get -y install flac
Here is a script that does the rest (file flac-mp3.sh):
#!/bin/sh

# Convert FLAC to MP3 VBR
flac -cd CDImage.flac | lame -h - -v \
    --preset cd CDImage.mp3

# Split file
mp3splt -a -d mp3 -c CDImage.flac.cue -o \
    @a/@b/@n-@a-@t CDImage.mp3
rm CDImage.mp3
Drop that file into a directory that has two files input CDImage.flac and CDImage.flac.cue. Run the script and in few minutes you will get a mp3 directory with your mp3 tracks.

Wednesday, December 21, 2011

How to Convert APE+CUE to MP3

There is no a single tool to convert a APE file to a number of mp3 tracks. We are going to convert ape file to wav first, than wav to mp3 (a single file) and finally cut a single mp3 file into several (per CUE file). We need several packages. Two of them (libmac2 monkey-audio) are from debian-multimedia, choose mirror from the following list. You need to install debian-multimedia-keyring package. In my case I have obtained it from here:
http://mirror.yandex.ru/debian-multimedia/pool/main/d/deb-multimedia-keyring/
Download debian-multimedia-keyring_2010.12.26_all.deb file (in your case the file can be newer) and install:
dpkg -i debian-multimedia-keyring_2010.12.26_all.deb
Once above is done we need to add debian-multimedia repository location to apt source list and update it:
echo "deb http://mirror.yandex.ru/debian-multimedia/ testing main non-free" \
    >> /etc/apt/sources.list
apt-get update
Install required packages:
apt-get -y install libmac2 monkeys-audio shntool \
    lame mp3splt
Here is a script that does the rest (file ape-mp3.sh):
#!/bin/sh

# Convert APE to WAV
shnconv -o wav CDImage.ape
# Convert WAV to MP3 VBR
lame -h -v --preset cd CDImage.wav CDImage.mp3
rm CDImage.wav
# Split file
mp3splt -a -d mp3 -c CDImage.ape.cue -o \
    @a/@b/@n-@a-@t CDImage.mp3
rm CDImage.mp3
Drop that file into a directory that has two files input CDImage.ape and CDImage.ape.cue. Run the script and in few minutes you will get a mp3 directory with your tracks.

Troubleshooting: mp3splt does not set ID3 tags

As of this writing Debian testing comes with mp3splt version 2.2.5-1. The problem has been fixed since version 2.3. So in order to install latest version you need to add the following to /etc/apt/sources.list:
echo "deb http://mp3splt.sourceforge.net/repository wheezy main" \
    >> /etc/apt/sources.list
apt-get update
Note that you need remove previously installed packages related to mp3splt:
apt-get remove libmp3splt-mp3 libmp3splt-ogg \
    libmp3splt0 mp3splt
Install latest:
apt-get install libmp3splt0-mp3 libmp3splt0-ogg \
    libmp3splt0 mp3splt