python + dbus FTW!!!

was just thinking it’d be nice to be able to push a button to copy my current activity from Hamster to my work XMPP status in Empathy.  couldn’t find any such options or plugins for either app.  but with dbus (and dfeet) and python, how hard can it be?  turns out, this hard:

#!/usr/bin/python

# get status from hamster, write it to empathy

myjid = "firstname.surname@example.com/" # my XMPP node and domain - any XMPP resource

from dbus import SessionBus

def busAsPath(bus):
  return "/" + bus.replace(".", "/")

def jidToDbus(jid):
  return jid.replace(".", "_2e").replace("@", "_40").replace("/", "_2f")

ogh = "org.gnome.Hamster"
mybus = "org.freedesktop.Telepathy.Connection.gabble.jabber." + jidToDbus(myjid)
sb = SessionBus()

fact = sb.get_object(ogh, busAsPath(ogh)).GetCurrentFact()['name']
for bus in sb.list_names():
  if bus.startswith(mybus):
    sb.get_object(bus, busAsPath(bus)).SetPresence("available", fact,
    dbus_interface = "org.freedesktop.Telepathy.Connection.Interface.SimplePresence")

stuck that in a file, made a custom launcher for it on the gnome panel and put that next to hamster.  lovely.

this only sets the status on that one account. if you’ve got multiple accounts which can have their presence set then empathy won’t change what it displays in its status selector until they all match. easily done by removing the account-specific code and applying the SetPresence to every bus which startswith(“org.freedesktop.Telepathy.Connection.”) – then you need a try/pass to ignore any exceptions generated by attempting to SetPresence on accounts which don’t have one. 🙂

Super-achieve! Week 43 ’09

image

Staying up all night is definitely the way forward for me. Stayed up last night and achieved…

  • First Japanese word learned in months.
  • Sent some emails I should have sent three months ago.
  • First go on Wii fit in months.
  • First cycle ride in weeks.
  • Found CDs with 400 photos I thought I’d lost forever.
  • Tucked all my loose CDs and DVDs away into folders.
  • Sorted out all my old AV and computer cables.
  • Cleared a lot of space in my room.

plus a few other bits and bobs. Woot!

And now I’m trying out posting this from my HTC Hero android phone too.

On the downside, one of the reasons for the flurry of activity is that I feel like I’ve wasted the last week or so trying to get the android SDK working on any of my Linux machines and attempting to connect the phone to Windows running in a KVM in order to update it. I’ve had to admit defeat on both of those which is why this has taken 10 minutes rather than 2 to write. Grrrr.

t-mobile 3g stickage

old skool phone modem

old skool phone modem

i’m not t-mobile’s biggest fan by any means but i do like the idea of having a selection of 3G providers to choose from.

so i’ve ended up with this 3g usb stick from t-mobile which “works on windows and osx” – *sigh*

still, i’ve seen a few of these on vodafone and you just plug them in and NetworkManager does the rest, right?

well, almost.  if you’re still back on fedora 10 (what’ve you been doing all week?!) then you’ll need to do something (called ‘usbmodeswitch’) to switch the stick from ‘zerocd’ mode into 3g modem mode – in fedora 11 that’s done for you (by hal i think).  but then when you try to connect it fails.

googling around i found lots of people saying it doesn’t work if the settings have a blank username and password – doesn’t matter what they are as long as they’re not blank.  well i tried that but it made no difference.

tried calling t-mobile support who were moderately helpful and did say that i should try “user” and “pass” but that didn’t  help either.

they also said that there’s some other software you can download that sorts it all out for you.  more googling found ‘hsoconnect’ hosted on pharscape.org which was, at that time, blacklisted by google for apparently hosting viruses!  eek.

went to the t-mobile shop today and got the same story from them.  also they can’t swap the stick for a different model and they can’t accept it back from me either – i have to call support again.

so, thought i’d have another try at hsoconnect. pharscape.org is no longer blacklisted!  bit of a problem with the latest release because it’s python2.5-based but fedora 11 has 2.6.  then i found a beta version which runs on 2.6.  hoorah!

once i’d found that you have to create folders for it before you run the installer it finally ran … and failed.  reading some more comments it turns out that hsoconnect only ever works if you configure it yourself with username, password and APN.  APN?  ah ha!

tracked down the APN here … success!  then i thought, maybe that’s what the problem was all along …. and now i’m typing this using the 3g stick connected by NetworkManager! (well, i was, right up until t-mobile blocked me from finding a picture on flickr – even though the chap who sold it to me assured me he’d removed the block.  grrr.)

so, if you’ve got fedora 11 and a new uk t-mobile 3g stick you need to know:

go to the ‘connection settings’ in NetworkManager.

go to the mobile broadband connection and edit it.

set the username and password to anything non-blank.

set the APN to general.t-mobile.uk

success!  😀

fedora 9 on the eee pc 901

i need to make a note of all the behaviours of fedora 9 on my eee pc 901 before installing fedora 10 beta on it.

main points are:

  • have to build wireless drivers from source from here – currently version 1.8.0 – which is, hopefully, the same as the 1.7.0 i used plus the patches i had to apply!
  • the wireless driver doesn’t appear to have a monitor mode
  • without a usb dvd drive you have to boot from the SD slot or an external usb hard drive. this works with livecd (if you’ve got the livecd creator tools) but not with the DVD image.
  • after a suspend/resume the brightness control doesn’t work
  • suspend by closing the lid works fine but suspend on idle does a hibernate instead
  • there’s noise from the speakers if they’re not muted – which is a shame on an utterly silent system
  • occasionally the back-light switches off (possibly only after screensaver and screen blank when on AC) and it doesn’t come back on until you use a Fn brightness key. it’s still possible it’s actually any key and it’s just gone to sleep
  • 3D works pretty well for compiz but it goes a bit wrong when you try running a 3D or Xv (video) app at the same time – particularly troublesome when that app defaults to fullscreen mode – e.g. blender or miro. watching DVDs or using stellarium or blender is fine with compiz disabled
  • no middle mouse button (big problem in blender) and we’ve moved to xinput driver so it’s a bit of a pain enabling support again – i created /etc/hal/fdi/policy/3button.fdi with
    <match key="info.product" string="ImPS/2 Logitech Wheel Mouse">
     <merge key="input.x11_options.Emulate3Buttons" type="string">true</merge>
    </match>

    in it.  can’t remember where i read that – i think it’s the sum of several hints and previous hal experience.

  • sometimes if you type too fast keystrokes (especially shift keys) are missed
  • when compiz is enabled you get a brief flash of the desktop before the password prompt is displayed when the system has been locked or suspended
  • sometimes networkmanager disables networking entirely – not sure why.  i think it only happens after a suspend/resume – but only occasionally.
  • 3D does have its limits – flightgear manages only a couple of frames per second (might not have anything to do with the 3D and might be fixable in the settings) – celestia doesn’t work at all and google-earth runs a several seconds per frame.  also i’ve switched off the compiz cube as there’s a little bit of tearing when it spins.  the left/right slide is much more understated anyway.
  • many bad apps assume you’ll have 600 vertical pixels to play with.  i think there might be a compiz plugin to run the entire screen like a virtual display scaled down – i’ll see if i can find that.
  • everything looks sooo pretty on it that  a) i’ve forgotten how hideous the ‘pearl white’ plastic is and b) i really don’t want to do a clean re-install.

on the plus side:

  • the screen is very nice
  • it plays DVDs – we’ll see how it copes with HD content soon
  • desktop effects, google gadgets and cairo-dock look great
  • it’s completely silent
  • battery life is good – 4-6 hours
  • i’ve installed all the good office, internet and graphics apps without problems
  • it fits in a small bag
  • i can afford it
  • it certainly runs F10 to some extent
  • you can jam a custom touch screen and 3G slot inside it!

happy days.

well, that’s as much as i can remember for now.  on with the show – let’s trash it and stick F10 beta on instead.

oh yes, the 901 actually has two SSDs – 4G + 16G for linux, 4G + 8G for windows.  nice.  so i tried partitioning them with some RAID stuff.  here’s some hdparm numbers for F9:

cached reads (memory speed) are around 550MB/s

the 4G disk goes at around 26-28MB/s

the 16G at around 24-27MB/s

RAID1 at around 24-26MB/s

RAID0 at around 30MB/s

with O_DIRECT (unbuffered):

4G 31MB/s

16G 28.5MB/s

RAID1 31MB/s

RAID0 30MB/s

STYG

how CJK is your page?

i made a python app that scans the content of a web page to see how Japanese it is based on the characters used. so it could be Japanese, Chinese etc. here it is:

# -*- coding: utf-8 -*-

from sys import argv
from urllib2 import build_opener
from HTMLParser import HTMLParser

class jaHTMLParser(HTMLParser):

ja = nonja = 0
encoding = “utf-8”

def handle_starttag(self, tag, attrs):
     for attr in attrs:
         if tag == ‘meta’ and attr[0] == “content” and attr[1].find(“charset=”) != -1 :
         self.encoding = attr[1].split(“charset=”)[1]

def handle_data(self, data):
     if data in (“/*”, “*/”) or data.isspace(): return
    uni = data.decode(self.encoding)
     for c in uni:
         u8 = c.encode(“utf-8”)
        if u8 >= ‘⺀’ and u8 <= ‘𯨟’: self.ja += 1 # very approximate
         else: self.nonja += 1

def unknown_decl(self, data): pass # CDATA is not an error!

opener = build_opener()
opener.addheaders = [(‘User-agent’, ‘Mozilla/5.0’)] # avoid 403 forbidden

reader = jaHTMLParser()
reader.CDATA_CONTENT_ELEMENTS = [] # don’t treat any CDATA as textual content
reader.feed(opener.open(argv[1]).read())
reader.close()
print “%d%%” % (float(100 * reader.ja) / float(reader.nonja + reader.ja))

🙂

barcoded

well, i’ve scanned over 200 barcodes now. but what have i learned?

  • you can get away with a lot of noise in the picture.
  • all those silly things that we try at supermarkets to get the scan to work are actually very sensible.
  • with my dodgy setup it’s only very slightly quicker than typing. but lots more geeky fun.
  • shiny things are bad.

geek goodness

last night was proper geek time for me. last year i hacked together an old webcam and a 35mm lens cap so that i could attach a second-hand zoom lens to the webcam. it kind of worked but the pictures were weird (see my little profile icon here) and it was hard to use.

say cheese

well, now i’ve found a use for it – as a barcode scanner!

i’ve got another webcam but it can’t produce a big enough image of a normal barcode. my zoom lens cam works well. mind you, the webcam isn’t great quality and the lens is old and dirty and i’ve not looked after either whilst sticking them together or since, so the pictures are a bit iffy.

muck

so, i found zebra – a bit of FOSS software that can scan in barcodes. had to install a few devel packages on fedora 8 to get it to compile. then i had to modify the code to get it to talk to the second webcam, not the first.

it still refused – turns out the webcam only supports GREY or YUV420p formats but the code only supports RGB24. a quick bit of googling and wikipediaing and coding and we had it accepting YUV420p and reading the black and white data correctly. … and barcodes appeared!!

can you tell what it is yet?

another fix was required to the zebra scanner so that it includes the check digit in its output – the searches didn’t work without it.

EAN-13: 0702727136221
EAN-13: 5060067000844
EAN-13: 5060034578109
EAN-13: 5022366552943
EAN-13: 5055201800763

the next nice find on the net was barcodepedia. loverly. great idea. didn’t have many of the DVDs i scanned. plus it looks like i might have broken it by pestering it with searches. sorry about that.

5022366552943 – Ghost in the Shell [Region 2] on Barcodepedia.com
5023965343321 – Katakuri-ke no kôfuku on Barcodepedia.com
5023965347428 – Mou gaan dou on Barcodepedia.com
5023965350220 on Barcodepedia.com
5023965351227 on Barcodepedia.com

however, it did know about manufacturer codes, so even if it doesn’t know what DVD it is you can still find out who made it.

whilst looking at these extra details and trying it out on a book i saw that the barcode is actually the ISBN number. so i googled for an online ISBN search and was reminded to look at amazon.

and that made me think of just passing the barcode values to amazon in the first place – which works!

a little bit of scripting later and i can now point books and DVDs at my hacked up webcam and the titles from amazon pop up on the screen. 🙂

Tenchi Muyo! DVD Ultimate Collection (NTSC)
Wario Ware: Smooth Moves (Wii)
Azumanga Daioh – Vol. 1
Azumanga Daioh – Vol. 2
My Wrongs #8245-8249 & 117 [2002]
At The Height Of Summer [2001]
Ghost in the Shell: Stand Alone Complex – Solid State
Ghost In The Shell [1995]
The Happiness Of The Katakuris [2003]
Infernal Affairs [2004]
The Hitchhikers Guide to the Galaxy (2 Disc Edition) [2005]

next up – get more details from amazon and/or barcodepedia and save them to a CSV or XML file that gcstar can read.