[maemo-developers] Obtaining flash memory serial numbers on Nokia N800

From: Marius Gedminas marius at pov.lt
Date: Sun Aug 12 22:31:43 EEST 2007
On Sun, Aug 12, 2007 at 03:01:06PM -0400, Tony Maro wrote:
> Just read the text file at the specified location.  Where we said "cat
> XXXXXX", cat was just meaning dump the contents of that file to the console,
> so you could just open that file like any text file and read the serial
> number out of it.  That's Linux 101, but certainly is alien to anyone who
> has done Palm, PocketPC or Windows development.
> So in Python for instance, you might do:
> mypath = '/sys/devices/platform/mmci-omap.1/mmc1*/cid'
> srcfile = open(mypath,'r')

Ah, no, Python's open won't process shell wildcards.  You want glob for

import glob
mypath = glob.glob('/sys/devices/platform/mmci-omap.1/mmc1*/cid')[0]
srcfile = open(mypath, 'r')

Be prepared to catch a KeyError if the path doesn't exist (because you
don't have a card inserted) and glob.glob() returns an empty list.

(It might be better to use that other file to determine the actual
directory name rather than globbing.)

> myserial = srcfile.readline()
> srcfile.close()
> # tada! no need for any include's either.  Nice and simple.

Marius Gedminas
Press any key to continue, or any other key to cancel.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.maemo.org/pipermail/maemo-developers/attachments/20070812/be74edc8/attachment.pgp 
More information about the maemo-developers mailing list