Créer un service Windows en Python

Prérequis

http://www.python.org/getit/

http://sourceforge.net/projects/py2exe/files/py2exe/

http://sourceforge.net/projects/pywin32/files/pywin32/

Fichier d’exemple setup.py

setup.py

Fichier d’exemple test.py

test.py

Construction

python setup.py py2exe

Liens

http://forums.devshed.com/python-programming-11/py2exe-step-by-step-guide-209432.html

http://stackoverflow.com/questions/3126379/py2exe-com-dll-problem

http://www.py2exe.org/index.cgi/py2exeAndWindowsServices

http://osdir.com/ml/python.py2exe/2007-01/msg00003.html

Garmin Etrex Legend HCX and Debian/Ubuntu

  • First, We have to disable the garmin_gps module, because the serial interface isn’t very stable
echo "blacklist garmin_gps" >> /etc/modprobe.d/blacklist.conf
  • Set the correct permissions for the usb device in /etc/udev/rules.d/51-garmin.rules
ATTRS{idVendor}=="091e", ATTRS{idProduct}=="0003", MODE="0660", GROUP="plugdev"
  • Read the stored tracks :
gpsbabel -t -i garmin -f usb:  -o gpx -F file.gpx
  • Write a track
gpsbabel -t -i gpx -f rhodon_rando.gpx  -o garmin -F usb:
  • Write geocaching points
gpsbabel -i geo -f geocaching.loc -o garmin -F usb:
  • Write POIs KML file
gpsbabel -w -i kml -f input_file.kml -o garmin -F usb:

Tips about writing tracks

  • To write the track to the current recording track, the gpx file must contain :
<trk>
 <name>ACTIVE LOG</name>
<trkseg>
  • To write the track to the stored tracks, the gpx file must contain :
<trk><name>ACTIVE LOG</name><number>1</number><trkseg>

Bootstrap Drupal

<?php
chdir('/var/www/drupal');
requrire_once('./includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//Become admin
global $user;
$user = user_load(1);
//Yourcode
print_r(node_load(1))
?>

How to customize your ubuntu live usb stick

  • Install the squashfs tools
david@rifraf:/3data/iso$ sudo aptitude install squashfs-tools
  • Create the working directories
david@rifraf:/3data$ mkdir custom-squashfs
david@rifraf:/3data$ mkdir squashfs
david@rifraf:/3data$ mkdir squashfs-images
  • Become root and load the squashfs module
david@rifraf:/3data$ sudo su
[sudo] password for david:
root@rifraf:/3data# modprobe squashfs
  • Mount the current squashfs file form the usb stick
root@rifraf:/3data# mount -t squashfs -o loop /media/usb-stick/casper/filesystem.squashfs squashfs/
  • Copy the root content
root@rifraf:/3data# cp -a squashfs/* custom-squashfs
  • Cleanup
root@rifraf:/3data# umount /3data/squashfs/
root@rifraf:/3data# rm -rf squashfs/
  • Chroot the file system
root@rifraf:/3data# cp /etc/resolv.conf custom-squashfs/etc/
root@rifraf:/3data# chroot custom-squashfs
root@rifraf:/# mount -t proc none /proc/
root@rifraf:/# mount -t proc none /sys/
root@rifraf:/# export HOME=/root
  • Edit the /etc/apt/sources.list and uncomment the following lines
deb http://archive.ubuntu.com/ubuntu lucid universe
deb http://archive.ubuntu.com/ubuntu lucid multiverse
  • Update the apt sources
root@rifraf:/# aptitude update
  • Install the needed applications
root@rifraf:/# aptitude install devede vlc mplayer thunderbird gimp filezilla terminator flashplugin-installer
  • Cleanup
root@rifraf:/# apt-get clean
root@rifraf:/# rm -rf /tmp/*
root@rifraf:/# rm -f /etc/hosts /etc/resolv.conf
  • Quit the chroot
root@rifraf:/# umount /proc/
root@rifraf:/# umount /sys/
root@rifraf:/# exit
  • Create the new squashfs file
root@rifraf:/3data# mksquashfs custom-squashfs squashfs-images/filesystem.squashfs
  • Copy to the usb stick
root@rifraf:/3data# cp squashfs-images/filesystem.squashfs /media/04AB-8752/casper
  • Test the live system
david@rifraf:/3data$ qemu -hda /dev/sdb -m 256 -vga std

How to create an ubuntu live usb stick with persistent home

  • Download ubuntu iso image
david@rifraf:/3data/iso$ http://ubuntu.positive-internet.com/releases/lucid/ubuntu-10.04-desktop-i386.iso
  • Install usb creator
david@rifraf:/3data/iso$ sudo aptitude install usb-creator-gtk
  • Launch usb creator
david@rifraf:/3data/iso$ usb-creator-gtk




Roadrunner is now in maemo extras repository

3 month after the first upload to extras-devel, Roadrunner is in extras repository.

http://maemo.org/downloads/product/Maemo5/roadrunner/

Spindown usb disk on debian

Because I use the NSLU (with debian squeeze) as a multimedia box, it is online all the time.
Most of the time, I don’t use it and don’t want to have the usb hard disk running 24/7.

Modify fstab

/etc/fstab

UUID=ef8be17c-3524-46b6-864c-981a76f919e1 /               ext3    noatime,errors=remount-ro 0       1
UUID=6337cac1-c8ab-4f29-9f15-c7c1673dda8d /data           ext3    noatime,defaults        0       2
UUID=b7cc8fb0-d581-4754-b06f-2f304e7bfecc /home           ext3    noatime,defaults        0       2

Note: I specified the noatime option

Disable unwanted services

root@nslu:~# update-rc.d rsyslog remove
root@nslu:~# update-rc.d exim4 remove
root@nslu:~# update-rc.d cron remove

Disable MPD logfile

/etc/mpd.conf

#log_file            "/var/log/mpd/mpd.log"

Enable disk access tracking

root@nslu:~# echo 1 > /proc/sys/vm/block_dump
root@nslu:~# cat /proc/kmsg
<7>[ 1092.070000] mpd(1454): READ block 283720256 on sda4

Note: You can see here mpd process reading data

Install sdparm

sdparm controls the disk.

root@nslu:~# aptitude install sdparm

The spindown script

while true
do

 MyDiskStatsNow=`cat /proc/diskstats | grep "sda "`
 MyDiskStatsPrev="MyDiskStatsNow"
 while [ "$MyDiskStatsNow" != "$MyDiskStatsPrev" ]; do
 echo "Busy : $MyDiskStatsNow "
 MyDiskStatsPrev=$MyDiskStatsNow
 sleep 10
 MyDiskStatsNow=`cat /proc/diskstats | grep "sda "`
 done
 echo "Pas d activite detectee! - Spindown actif "

 sdparm --command=stop /dev/sda
 MyDiskStatsPrev=$MyDiskStatsNow

 while [ "$MyDiskStatsNow" = "$MyDiskStatsPrev" ]; do
 echo "Idle : $MyDiskStatsNow "
 sleep 10
 MyDiskStatsNow=`cat /proc/diskstats | grep "sda "`
 done
 echo "Activite disque detectee"
done

Installing lighttd with php5-cgi enabled

Installing lighttpd and php5-cgi

root@nslu:~# aptitude install php5-cgi lighttpd

/etc/lighttpd/lighttpd.conf

server.modules              = (
 "mod_access",
 "mod_alias",
 "mod_accesslog",
 "mod_compress",
 "mod_fastcgi",
)
fastcgi.server = ( ".php" =>
 ( "localhost" =>
 (
 "socket" => "/tmp/php-fastcgi.socket",
 "bin-path" => "/usr/bin/php5-cgi"
 )
 )
)
#include_shell "/usr/share/lighttpd/use-ipv6.pl"

Restarting lighttpd

root@nslu:~# service lighttpd restart

Installing and configuration lirc for Creative SoundBlaster Live! External USB

Lirc installation

root@nslu:~# aptitude install lirc

/etc/lirc/hardware.conf

LIRCD_ARGS="-d hw:External"
LOAD_MODULES=true
DRIVER="alsa_usb"
DEVICE=""
MODULES=""
LIRCD_CONF=""
LIRCMD_CONF=""

Copy the preconfigured lircd.conf file

root@nslu:~# cp /usr/share/lirc/remotes/creative/lircd.conf.alsa_usb /etc/lirc/lircd.conf

/etc/lirc/lircrc

begin
 button = next
 prog   = irexec
 repeat = 0
 config = mpc next && echo "next"
 end

 begin
 button = previous
 prog   = irexec
 repeat = 0
 config = mpc prev &&  echo "previous"
 end

 begin
 button = vol+
 prog   = irexec
 repeat = 0
 config = mpc volume +10  &&  echo "vol+"
 end

 begin
 button = vol-
 prog   = irexec
 repeat = 0
 config = mpc volume -10 &&  echo "vol-"
 end

 begin
 button = playpause
 prog   = irexec
 repeat = 0
 config = mpc toggle &&  echo "play-pause"
 end

 begin
 button = stop
 prog   = irexec
 repeat = 0
 config = mpc stop &&  echo "stop"
 end

 begin
 button = start
 prog   = irexec
 repeat = 0
 config = mpc play &&  echo "play"
 end

Restarting lirc

root@nslu:~# service lirc restart

Installing and configuring mpd on NSLU

Installing mpd

root@nslu:~# aptitude install mpd mpc

/etc/mpd.conf

db_file         "/data/mpd/mpd.db"
log_file        "/var/log/mpd/mpd.log"
error_file      "/var/log/mpd/errors.log"
pid_file        "/var/run/mpd/pid"
audio_output {
    type        "alsa"
    name        "my ALSA device"
    device      "hw:0,0" # optional
    format      "44100:16:2" #optional
}

Updating the database

root@nslu:~# service mpd stop
root@nslu:~# mpd --create-db
root@nslu:~# service mpd start