vrijdag 3 juni 2011

Android hacking

So I bought an Android Archos 32 for my 5 year old daughter. A tiny device, ideal for fun things she can do (without spending money, it's wifi only).

I also want to see with it what is possible with python on this device, and if perhaps I can port a part of Gramps to there. Well, it will not be easy it seems, but something is possible. I'm thinking about an reader that can understand the Gramps xml fileformat.

So, what is needed to try things out?
  1. SL4A (scripting layer for android), so download it on your phone by clicking the barcode on : http://code.google.com/p/android-scripting/
    Then when downloaded, go to downloads on your android phone, and click the download to install it.
  2. Next, install python for SL4A, latest version of PythonForAndroid from http://code.google.com/p/android-scripting/downloads/list
    Again, click it in the Downloads to install it, then open run in and the app you see will have an install button at the top. Click that to install python and extra python modules/scripts
  3. You are now ready on your phone, click the SL4A app and you will see a list of scripts, click one to run it in a terminal or run it standalone
  4. To develop, you need to have a good PC/laptop, and install the android emulator there. Follow eg the walkthrough on this blog. So download the SDK, install it, and run it by typing in the tools directory ./android, then in the emulated phone, install again SL4A and python4android.
  5. Write a script on your PC. Eg, I write an application in
    push it to the open emulated android, go in the platform-tools directory from the SDK and run
    ./adb push ~/gramps/android/ /sdcard/sl4a/scripts/
  6. On the emulated phone, you will see the script in SL4A, and you can click it to run it.
  7. Once your script is not crashing your emulated phone anymore, you can push it to your actual phone: connect the phone to your PC in usb-mode, and move the file to /sdcard/sl4a/scripts/ on the phone. You can now run it in SL4A on the actual phone.
So, what is my first android script? A framework to read gramps xml files, so

# Gramps - a GTK+/GNOME based genealogy program
# Copyright (C) 2011 Benny Malengier
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# $Id: gramps.py 17390 2011-05-03 14:38:54Z nick-h $

# Python modules

import android
import os
import sys

BASE_PATH = '/sdcard/gramps'
if not os.path.isdir(BASE_PATH):

#different states

class grampsA:
def __init__(self, droid ):
self.droid = droid
self.state = ST_START
self.error = None

def run(self):
while True:
if self.state == ST_STOP:
elif self.state == ST_START:
print 'Unknown State'
#check if we have an error, if so alert user and exit
if self.error:

def showerror(self, error):
self.droid.dialogCreateAlert('Error encountered: %s' % self.error)
response = self.droid.dialogGetResponse().result

def setxmlfile(self):
title = 'Select Gramps xml file from %s' % BASE_PATH
files = [item for item in os.listdir(BASE_PATH)]
if not files:
self.droid.dialogCreateAlert('No files found in %s! Move a file there.'
response = self.droid.dialogGetResponse().result
self.state = ST_STOP

self.droid.dialogCreateAlert('Select file')
response = self.droid.dialogGetResponse().result
if response.has_key('which') and response['which'] == 'negative':
self.state = ST_STOP

sel = self.droid.dialogGetResponse().result['item']
self.xmlfile = files[sel]
self.droid.makeToast(self.xmlfile + ' chosen')
self.error = 'Wrong response from file selection'
#next the xml file must be loaded, we import it in a dict database.

def main( ):
grampsA( android.Android( ) ).run()

if __name__ == '__main__':

donderdag 20 januari 2011

A fresh DiffusionIT install

Guide for DiffusionIT install on a freshly installed ubuntu:
sudo apt-get install python-numpy python-scipy python-matplotlib python-gnuplot git git-gui spe
sudo apt-get install python-dev
The last is needed to allow weave compiling inline.
Now configure git
git config --global user.name "Your full name"
git config --global user.email "mymail@mail.com"

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
To just use the code, we make a directory to extract the code to
mkdir diffusionit
cd diffusionit/
git init
git remote add origin git://gitorious.org/diffusionit.git
git fetch
git checkout origin/master
git checkout -b master
git branch -a
If you have commit rights, you can push to the code to update it, but you must setup your remote repo differently. You can change this in the file diffusionit/.git/config. If you are doing things from scratch, change the git remote line above by
git remote add origin git@gitorious.org:diffusionit/diffusionit.git
You do need to create a login on gitorious and set up ssh passwords to use for the connection, see eg this post.
Once that is ok, a typical development cycle is
git status # check if ok
git add . # add changed files
git diff # check your changes if ok
git commit -m "blabla
git push
To obtain changes that happened remote by somebody else
git fetch
git rebase origin/master
Those are the main commands if you don't intend to become a code-master :-)

donderdag 23 december 2010

Livebox automount of usb HD

Ok, I'm streaming from my Mobistar Livebox to my PS3, but no thumbnails, bad directory structure, ...
So, I'd also have Mediatomb installed on my laptop, and want to be able to use that too.

Mediatomb needs a mounted filesystem however, whereas I now connect to it via smb://livebox/DisquesUSB/HD204UI/data/ in Dolphin.

So here how I mount that on the different systems:
cd /media/
sudo mkdir liveboxUsbHD
test it:
sudo mount -t smbfs -o username=theuser,password=hispass //livebox/DisquesUSB/HD204UI /media/liveboxUsbHD
The directory /media/liveboxUsbHD should contain the files.
For automatic mounting:
cd /etc/init.d
sudo kate start_smb
And have this file contain the above line
sudo mount -t smbfs -o username=theuser,password=hispass //livebox/DisquesUSB/HD204UI /media/liveboxUsbHD
So we use smbfs, cifs should work too and is even needed if a real windows share. Anyway, the file contains your password, so hide it and give it correct permissions:
sudo chmod 550 start_smb
sudo update-rc.d start_smb defaults
In case the samba share is not available on start-up, you can create the link on a later time with:
sudo ./etc/init.d/start_smb
That's it!

donderdag 19 augustus 2010

sound out on Dell studio XPS

I bought some nice boxes so as to be able to have nicer sound for the radio stations I listen to, but look, the headphone out jack of my dell studio xps is not working in Kubuntu 10.04!

Apparently the default for sound is using the bios configuration, and as I see no sound option in the bios that means I cannot repear the error there. All info to fix it is on the ubuntu community wiki.

So, for this laptop, fire up eg Kinfocenter, and see under sound:
Audio devices:
0: STAC92xx Analog (Duplex)

0: IDT 92HD73C1X5

Looking at the HD audio models documention, we see

ref Reference board
no-jd BIOS setup but without jack-detection
intel Intel DG45* mobos
dell-m6-amic Dell desktops/laptops with analog mics
dell-m6-dmic Dell desktops/laptops with digital mics
dell-m6 Dell desktops/laptops with both type of mics
dell-eq Dell desktops/laptops
alienware Alienware M17x
auto BIOS setup (default)

So as said, the BIOS setting is the default. So let's change it to dell-m6:
sudo kate /etc/modprobe.d/alsa-base.conf

and add at the end of the file:
options snd-hda-intel model=dell-m6

Reboot, and yes, sound is available on one of the headphone out jacks. The above line is also what is listed on the forum. Should you know how to make both headphone out to work, let me know.

donderdag 10 juni 2010

A0 poster with latex

I had to make an A0 poster for a conference. As I had my source in LaTeX, I tried for the first time to do it with latex. It worked better than I thought.

First, at UGent, one can print the poster with http://www.elis.ugent.be/nl/designjet

Second, a latex base file using columns and posterboxes, is at http://www.sgeier.net/poster/. I had to change it a bit to get it working ok though: remove some /hfill and /vfill calls, add some \mbox{\ } as needed.

Note that in Europe, you would want to create an A3 example, then scale it by 2.8 to obtain an A0 poster. So you need the following width and height in the tex:
\def\layoutwidth{297mm} % A3 portrait, A0 when scaled 2.82
The above produces a bad dvi file when compiled with LaTeX though, you need to run the command
dvips -Ppdf -G0 -o poster.ps poster
to obtain a nice ps file okular can nicely show. You can then print this to an A3 printer with good results.

Third step is to scale it to A0 poster. You need the poster_resize script for this:
csh poster_resize poster.ps 2.8
This creates a poster.resize.ps file which is an A0 print. If you do not have csh, sudo apt-get install it!

Fourth step is to create a backup: split the A0 poster in 16 A4 sheets you can plot on a colour printer and glue together yourself:
poster -iA0 -mA4 -pA0 poster.resize.ps > posterA4.ps
That is it. If you do not have the poster program, it should be available in your package manager (sudo apt-get install poster).

vrijdag 14 augustus 2009

upgrade, reinstall scipy

So I jumped on the upgrade wagon again with ubuntu, but now I need to obtain last versions of scipy again. All is now python2.6, and only gfortran is supported anymore. Make sure g77 is completely removed, and gfortran latest distro package

The workflow:

NOTE: use the --prefix /usr flag if setup.py installs in the wrong directory.

1. make sure you do not have the repository stuff installed or old versions:
sudo apt-get remove python-scipy python-numpy python-matplotlib python-gnuplot
sudo rm -rf /usr/lib/python2.6/site-packages
sudo rm -rf /usr/lib/python2.6/dist-packages/numpy
sudo rm -rf /usr/lib/python2.6/dist-packages/scipy
sudo rm -rf /usr/lib/python2.6/dist-packages/matplotlib
sudo rm -rf /usr/lib/python2.6/dist-packages/scikits*
2. obtain source code if you do not have it yet:
svn co http://svn.scipy.org/svn/numpy/trunk numpy
svn co http://svn.scipy.org/svn/scipy/trunk scipy
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib
svn co https://gnuplot-py.svn.sourceforge.net/svnroot/gnuplot-py/trunk gnuplot-py
svn co http://svn.scipy.org/svn/scikits/trunk/odes odes

3. Make sure you have the dependencies, eg
sudo apt-get install python-dev python-setuptools
For matplotlib, gtk backend, see build depend of the ubuntu package.
I used:

sudo apt-get install libpng-dev libgtk2.0-dev python-gtk2-dev python-imaging python-qt4 python-qt4-dev python-tz python-wxgtk2.8 zlib1g-dev libfreetype6-dev

4. go to numpy, update, compile, and install. Normally you need to remove /usr/lib/python2.6/site-packages/scipy or /usr/lib/python2.6/dist-packages/scipy and same for numpy first, but as python2.6 is new, those are not present.

cd numpy
sudo rm -rf build
svn up
sudo python setup.py install --install-layout=deb

cd scipy
sudo rm -rf build
svn up
sudo python setup.py install --install-layout=deb

cd matplotlib
sudo rm -rf build
svn up
sudo python setup.py install --install-layout=deb

3. Now I can reinstall my own module in scikits

cd programs/odes
sudo rm -rf build
svn up
sudo python setup.py install --install-layout=deb
Above works only on first install. Afterwards I obtain an error with zip files?? To resolve
rm -rf /usr/lib/python2.6/dist-packages/scikits/odes
sudo rm -rf build
sudo python setup.py install --single-version-externally-managed --root / --install-layout=deb
And then it is time to test if all is working again.
Interesting resource: python distutils

donderdag 28 mei 2009

Jaunty, ati/radeon and a big desktop with xrandr

Buggers, my ati card is no longer supported by the fglrx driver of ati. Full 3D support is present though in the open source driver. Big desktop over two screens? Well 'man radeon' claims it is present. However, I noticed also bug 348332

So I waited with the upgrade, but today, I felt lucky and did the upgrade. Not a good idea.

First, although the upgrade manager said fglrx would not be installed, it did not regenerate my xorg file. So X crashed on startup. Alt+F1, a login and a "sudo dpkg-reconfigure -phigh xorg-server" later, I had my X back.

I got bit by bug 348332 very quickly though, so disabled desktop effects in the system settings for now. No option to make a big desktop in these settings though, so apparently that will be a manual install.

But first getting my effects back. A trip to http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.29.4/ and then install of the relevant components:
sudo dpkg -i linux-headers-2.6.29-02062904_2.6.29-02062904_all.deb linux-headers-2.6.29-02062904-generic_2.6.29-02062904_amd64.deb linux-image-2.6.29-02062904-generic_2.6.29-02062904_amd64.deb

After restart things looked ok:
$ uname -a Linux bmwork 2.6.29-02062904-generic #02062904 SMP Sat May 23 23:35:48 UTC 2009 x86_64 GNU/Linux
And re-enabling desktop effects was ok too. Still waiting for a crash, but all looks good so far.

So, now, how to get my big desktop back. My setup is using the default xorg.conf the radeon driver. My xorg.conf:

Section "Device"
Identifier "Configured Video Device"

Section "Monitor"
Identifier "Configured Monitor"

Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
Apparently we are supposed to use xrandr (see good intel guide) now for enabling a big desktop. First let's see if it is enabled:
$ xrandr -q
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 1280 x 1280
VGA-0 connected 1024x768+0+0 (normal left inverted right x axis y axis) 340mm x 270mm
1280x1024 60.0 + 75.0 60.0
1024x768 75.0 70.1 60.0*
800x600 75.0 60.3
640x480 75.0 59.9
720x400 70.1
DVI-0 connected 1024x768+0+0 (normal left inverted right x axis y axis) 304mm x 228mm
1024x768 60.0*+ 75.0 60.0*
800x600 75.0 60.3
640x480 75.0 59.9
720x400 70.1
OK, my VGA and DVI output are both recognized and correctly enabled, one with identifier VGA-0 and one with DVI-0. The default is clone mode though, which is what I indeed am seeing. To set my VGA left of the DVI I do:

$ xrandr --output VGA-0 --left-of DVI-0
xrandr: screen cannot be larger than 1280x1280 (desired size 2048x768)
It did not work. We need to make sure we can have a virtual screen of 2048x768 before above will work. The graphics card should be capable of this. My /var/log/Xorg.0.log file says:
(II) RADEON(0): Max desktop size set to 2560x1600
(II) RADEON(0): For a larger or smaller max desktop size, add a Virtual line to your xorg.conf
(II) RADEON(0): If you are having trouble with 3D, reduce the desktop size by adjusting the Virtual line to your xorg.conf
So add a Virtual line (see xorg.conf below), and all works.
Next, as given in the guides, you need to use xrandr commands to see if it works. Well, I can say it does not work 100% via the xrandr command in my case. The desktop got bigger indeed, but both screens kept showing the same thing. Fortunately, changing the xorg.conf file to do the xrandr settings worked like a charm. My new xorg.conf file is:

Section "Monitor"
Identifier "VGA"

Section "Monitor"
Identifier "DVI"
Option "RightOf" "VGA"

Section "Device"
Identifier "Configured Video Device"
Option "Monitor-VGA-0" "VGA"
Option "Monitor-DVI-0" "DVI"

Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"

SubSection "Display"
Depth 24
Virtual 2048 768
Things to note in the above:
  1. The options in the Device section you see, must have the identifier as given by the xrandr -q output, so Option "Monitor-VGA-0" "VGA" works but not Option "Monitor-VGA" "VGA"
  2. The Virtual 2048 768 line in Display is where the maximum virtual size is set (see xrandr error above) you need for your display. Take it as low as possible, so you can have as much as possible depth (it eats memory on the card!)
Good. Half a day to get a working set-up. Perhaps I should not upgrade so often. Fortunately, 3D does seem to work like a charm on my dual head setup :-)