Search Results: "ean"

24 January 2007

Martin F. Krafft: European leader

Joss, your choice of "70 years" (as opposed to, say, 100) could be called suggestive, but I'd still honestly answer Helmut Kohl and Mikhail Gorbachev before I'd get to what you were anticipating. It's easy to create chaos, it's hard to clean it up. Debian's been facing the same problems before its current leader was appointed, and before the one before that was appointed, and before the one before the one before that was appointed... We'll remember the leader who solves our problems. Why don't you run for the position at the next election with all your great ideas of how to do that, since you obviously know the solution? Or are you just being destructive? Or is the fact that our current leader actually caused a stir (or several) too much for you to handle and you'd rather get back to static rotting mode? NP: Man on Fire / Habitat

Wouter Verhelst: Ian Murdock on Solaris...

If you want another example, one from a company who any developer would agree is an outstanding engineering organization, here's one: "Sun has maintained binary compatibility between operating system releases for nearly a decade, enabling existing Solaris applications to run unmodified on Solaris 10. This means that Solaris applications developed 10 years ago will run on Solaris 10 unchanged, taking full advantage of new and advanced Solaris features."
Yes, it's true that there is outstanding backward binary compatibility in Solaris. However, if you're going to try use that as an argument in favour of Solaris, try again. Have you ever actually used a Solaris system? If you're going to say that backwards compatibility is good and that we should incorporate backwards compatibility into Linux somehow, then please do not point people towards the two ugliest operating systems on the earth with a lot of garbage baggage for the sake of backwards compatibility...

23 January 2007

Gunnar Wolf: On Trusted Computing

I came across this excellent video clip on what Trusted Computing means, and why we should stay away from it. CC-licensed and all, of course.

Raphaël Hertzog: More fun with Linux and serial ports on slow hardware

This is a never ending story for me. The first time I’ve had problems with Linux’s handling of serial UART dates back to 2005 (see my previous blog post on buffer overruns). At that time I could improve the situation by applying two patches (kernel-preempt and low latency). One year later, I have a situation where the buffer overruns are again easily reproducible at slower baudrate (54 kbauds), arguably there’s more than a serial application running this time, and it looks like the load generated by other processes (mainly watching digital I/O) renders the system less reliable with respect to its handling of serial ports. This time I follow the advice to try out the 2.6 kernel because many “real-time improvements” (coming from the -rt branch, check its wiki) and “embedded improvements” (coming from linux-tiny) have been merged. So I tried the stock kernel with very bad result. Results are better than the stock 2.4 but they are worse than the patched 2.4. So I decide to try the -rt patch on 2.6, but this patch doesn’t work on my CPU card and my bugreport didn’t lead to any fix (nobody responded even though I tried hard to include the necessary information and I was ready to do whatever I would have been asked to try). At the same time I explain my problem on the linux-kernel mailing list. The discussion doesn’t answer my questions but still brings two ideas to try out. In the end, with two simple tweaks to the stock 2.6 kernel (mainly configuring the UART to send the interrupt as soon as the first character arrives, instead of waiting for 8 chars to accumulate in the FIFO) I have been able to get something better than the patched 2.4. And it turns out my first choices for the 2.6 kernel configuration have not been very wise so the comparison between stock 2.4 and stock 2.6 above doesn’t mean much. Unfortunately, even if better than the patched Linux 2.4, it still doesn’t give good results in some conditions. So my primary question remains: is there a way to patch my kernel so that it will handle the serial related tasks (servicing interrupts from the UART mainly) as its primary job ? I don’t mind if such a change impact negatively the speed of the system if I can make sure that my serial exchanges are reliable. And by reliable I mean of course no buffer overruns, but there’s a second similar problem that has been discovered: when using software handshake, the system can send out between 10 and 25 characters after the partner has sent its XOFF. Sending up to 6 characters after the XOFF is ok, more is asking for troubles because the UART on the other side will probably encounter a buffer overrun… If you have any idea on how to resolve my problems, by any means, let me know.

22 January 2007

MJ Ray: Driving: Fear the Councillor

If any planners want to see the impact of your short-sighted regulations, please visit Bowthorpe
"planning regs mean you only have to provide one space per home. Hence families with two cars, or couples who work in opposite directions and need two cars, often have to block their roads without meaning to do so."
Surely short-sighted would be to cater for today's car parking requirements? Thanks to climate change, oil decline and other reasons, it looks like there won't be as many cars tomorrow. Two-car households may be a temporary problem. If people are parking inconsiderately, bring in a one-car-per-house permit system with edge-of-zone car parks (and let two-car houses buy permits from car-free houses). If you build roads big enough for today's peak use, then in the future, there will be oversize roads for the traffic levels when that land could have been better used for housing. Ah, criticising the barking policies of Antony Little... blogging like it's 1999.

Ian Murdock: More on the importance of backward compatibility

There were a lot of good comments on my post about the importance of backward compatibility the other day (both here and in the blogosphere), and a lot more of them were positive than I was expecting, which I find encouraging. A fair number of people called me out for using such a bad example—come on, changing the OS to fix a buggy application? Fair enough. Perhaps I diminished the point I was trying to make by referencing that extreme example, but it’s a worthwhile example for one reason: At Microsoft, the user experience comes first, notbefore developer sensibilities. Fortunately, as others (rightly) point out, it’s hard to imagine a situation where such extremes would be necessary in the Linux world—for one thing, we don’t have the sheer number of legacy binary applications to deal with, nor do we have the same volume or average user profile as Windows. But the point stands. User experience should always win. If you want another example, one from a company who any developer would agree is an outstanding engineering organization, here’s one: “Sun has maintained binary compatibility between operating system releases for nearly a decade, enabling existing Solaris applications to run unmodified on Solaris 10. This means that Solaris applications developed ten years ago will run on Solaris 10 unchanged, taking full advantage of new and advanced Solaris features.”

Petr Rockai: how things are

(17.1.2007) I haven't written a blog in aeons. I have been busy with life, as many of you know. For one, i have a girlfriend (her name is Lucy)... And, no matter what i have thought not so long ago, things are better than ever before. She's probably all that i have been looking for. We spend most of the weekends together (she lives and studies in western Slovakia, while i'm in the west-neighbouring Czech Republic (Moravia) -- somewhat surprizingly, this doesn't seem to be a problem so far). Anyway, that's probably boring for those of you that aren't me (ha), so to move on to other things. Work and school is busy these days (exam tomorrow (aaagh)), so i don't have much more free time than that i spend with Lucy. Despite that, i have done some cleaning-up on libept and adept codebases after importing them (with tailor) into darcs. Will blog about that separately i suppose, when i have more time and more stuff to report on. The exam tomorrow is on graph algorithms, and i should be actually studying instead of writing this, but i never change, do i? (19.1.2007) So the results of the exams will be available following monday. No idea whether i'm going to pass or not though. Anyway, i am sitting in a train to Slovakia, alone in a compartment, the window open wide, wind in hair. Sun is obscured by clouds at times, air is somewhat colder than it used to be. Maybe winter will finally arrive? Another exam is monday (same day as i get the results from yesterday's one)... Algorithms for NP hard problems. I'm still somewhat undermotivated to learn, and apart from that i should be hacking dmeventd (work stuff), working on my bachelor's thesis, learning to play a (soprano) recorder, learning russian and probably a ton of other things. Ah and adept, libept and friends need some attention too. I suppose i am a lost existence, given my total laziness. The train is speeding towards Breclav, last (and the only one apart from Brno on my route) station in Czech Republic. As usual, i intended to blog a ton of things, but can't recall of one them... That's life, i will hopefully get to blog a bit more again.

Evan Prodromou: 1 Pluvi se CCXV

I managed to miss the Igloofest by Piknic lectronik this weekend, which was kind of a bummer since it seemed like it would be such an awesome event. But with a downturn in the temperature -- another -20C day yesterday, with wind chill bringing it down to -28C -- it was just too hard to justify bringing a 1-year-old to an outdoor event. We did manage to do some fun things this weekend, anyways. Saturday was our first day house-hunting. We're planning to buy an apartment or condo in the Plateau Mont-Royal this year, before July 1. July 1 is the traditional Moving Day in Quebec -- the day that every renter in the province either renews their year-long lease or moves to a new apartment. We're going to move out of Renterhood this year altogether, and get into the fun of home ownership. Wish us luck. Anyways, we saw a great place this Saturday, and we plan to do some more house hunting over the next few weeks. We're going to make a decision about whether to stay in our current apartment or not before March 1, when we begin our big road trip down to Austin for South by Southwest. tags:
 

Bruncher This afternoon we had a great bruncher with friends at our (current) apartment. We invited over Jeremy and Lina and their two girls Syvlie and Clea, who arrived at our door like an advertisement for a skiing school. I love talking to the girls -- they're really smart and sweet people. We also had over Maj's friend Emmy and her husband Stef, as well as their daughter Isadora. Emmy is originally from Oaxaca (city), and Stef is German. They moved here a few months ago, and Maj and Amita June met Emmy and Isadora at their playgroup. This was the first time I met Stef; I got to use my German introduction lessons for this week on him. Guten Tag! Ich hei e Evan! Freut Mich! Isadora speaks Spanish with her mother and German with her father. She'll grow up bilingual, but unfortunately not speaking either of the languages of the bilingual city she's living in. My guess is that she'll probably be pretty expert at four languages by the time she's 10 or so. Maj cooked today, and made a really great smoked salmon gratin, white bean vegetable soup, and hors d'oeuvres. I put together a green salad to round it out. We opened up a couple of bottles of crispy vinho verde and had a very nice afternoon time. The kids got along great; Sylvie and Clea are several years older than Amita and Isadora (one day apart!), but they were really gentle and nice with the little ones. tags:

21 January 2007

Ross Burton: Postr 0.4

Postr 0.4 is finally out. This has an all-new Flickr library that uses Twisted, so I don't need to use threads any more. I've had lots of contributions to this release, in fact the change log is too long to summarise... Special features include a Nautilus context menu, GtkUnique support, and a lack of thread related crashes. Thanks to Germán Poó Caamaño, Emmanuele Bassi, Dean Sas and Daniel Stone for their patches and feedback. You can follow the development in the Bazaar branch, or get the Postr 0.4 tarball.

Daniel Baumann: Re: Package Maintenance

My last entry is maybe not so well understandable. In a mail between Alberto Gonzalez Iniesta and me, he put it in much better words than I could:
	Date: Sun, 21 Jan 2007 14:05:29 +0100
	From: Alberto Gonzalez Iniesta <agi@inittab.org>
	To: Daniel Baumann <daniel@debian.org>
	Subject: Re: [late]Thanks for your work
	On Sun, Jan 21, 2007 at 01:08:48PM +0100, Daniel Baumann wrote:
	> Hi agi,
	>
	> the orphaning of some packages wasn't ment as a signal to get 'please
	> thank me' or so, nevertheless, thanks for your mail.
	I know it wasn't meant to be that. But I really appreciate the work of
	some DDs, specially those that do their job, mind their businesses AND
	don't make of it a power position. Those hundreds of DDs or the like,
	that simply like this as is, and don't make of it a power struggle or a
	cabal thing. And you are one of them, as others I could name are.
	> I was taking care about 2 to 5 hours every day and nearly all of the
	> weekends to keep my packages in shape. All I got from this is rants
	> withouth any concrete background like 'look at him, he has so much
	> packages, they can't be good. They must be crap, it's impossible for one
	> person'. Also, some people in Debian do have a problem when people do
	> more than they do themself, and they're hating the others for that.
	Yep, that's what I meant. Those that are looking for competition... In
	a free software community. Morons.
	> Now, I'm just tired of that and went down from ~150 to ~100 packages. I
	> think, I did not point that out very clearly.
However, I am not going MIA now. I still care about my packages, but for a smaller number of them (reducing them in a second orphaning round down to ~50 in a few weeks). And don't worry, there will be no more entries about this topic from me. Thanks Alberto and the few others who replied.

Daniel Burrows: How to Breathe, Functionally (part 2)

In a previous post, I pointed out some ways that you can acheive the "compute this, now save it and compute this, ..." style of coding in a functional language such as Haskell without going mad. This is a continuation of that post.

There's one other purely syntactic feature of Haskell that I rather like for readability: Haskell lets you define variables after you use them.


GoToTheNextTrickyBit someVal
where someVal = DoThisAndThisAndThat...


Although it isn't always appropriate to do this, there are times when I find it extremely intuitive to define my variables after they're used. For instance, to take a "practical" example, compare


mailTo customer =
let customerName = getCustomerName customer
customerAddr = getCustomerAddr customer
in
makeMailingTo customerName customerAddr


with


mailTo customer = makeMailingTo customerName customerAddr
where
customerName = getCustomerName customer
customerAddr = getCustomerAddr customer


I don't know about anyone else, but when I read the first definition I mentally go "huh. Why are we extracting the customer name?", then skip down to where the name gets used, and finally re-parse the name in that context. The "where" form lets me write the code in the same order that I would read it, giving the code a natural flow. It's very important, of course, to keep the number of auxiliary definitions small; otherwise you leave too many "open questions" for the reader of your code to carry around as she works her way down to the definitions.

But it isn't all roses at the low syntactic level. IMO, the biggest practical problem with writing Haskell code is the syntactically significant indentation.

Python, of course, also has significant whitespace -- but it works mainly because it's extremely simple. Any line ending in a ":" introduces a new block, and statements within a block have the same amount of indentation. In contrast, Haskell's rule...well, just read that link above. You can write code that has the same meaning under any indentation, but it's not idiomatic to do so -- and worse, since the statement terminators are not obligatory, a missed terminator might work fine, might change the meaning of your code, or might fail to compile in an obscure way.

A side effect of the complicated indentation rules in Haskell is that the Emacs Haskell mode doesn't work very well at indenting my code. It usually chooses an indentation that I don't want, and often one that doesn't even compile. I'm sure Emacs could do better, but I would be willing to live with a little more punctuation if it meant that the code was easier for programming tools to process correctly. Functional coding advocates assert, correctly IMO, that side-effects are problematic because even smart programmers will write more bugs in their presence. I think the same logic should apply to syntax: making the language harder for humans and machines to parse has negative overall effects, even if it is possible with sufficient effort to parse it correctly.

I think that conceptually, Haskell is a great language -- the problems I see with it are issues of syntax, tool support, libraries and speed (laziness has a high price). Oh, and also the fact that, as with most programming languages that are pleasant to use, you can't get a real paying job writing in it unless you have a PhD. :-(

Daniel Burrows: How to Breathe, Functionally (part 1)

David Welton writes that the problem with functional languages is that you don't get to mentally "catch your breath" between computations; piling function invocations on function invocations makes it hard to understand what's actually being calculated. He has an amusing summary of how functional code can become unreadable:


Do this with the result of this with what this produces when given this input that is derived from this function which takes the result of this other thing after calculating the result of something that is derived from the output of a function that ...


Indeed, I've seen functional code like this (much of it written by myself). Here's a particular gem:


f splitPoints = map fst $ tail $ scanl (flip ($) . snd) ([], toSplit) $
map splitAt splitPoints


I wrote this code a year ago, and I don't know what it does! It's hard to read and hard to understand. So, however, is imperative code that says


Add 5 to A, now if B is not zero we jump to where we subtract one from B and if C is less than 3 we add 4 to C otherwise we divide C by 2 and then add it to A, then we ...


The reason both pieces of pseudocode are hard to understand is that they don't use the abstraction features built into the language. Good imperative code uses meaningful variable names, uses the structured-programming primitives the language provides, and abstracts complex operations into functions.

My rule of thumb (which is, heh, not always religiously followed) is that a piece of program structure that does more than about 3-6 things is probably too complicated; it seems like that's about as much local context as I can hold in my head comfortably (and the number is more 3 than 6 these days, if you get my drift). As David puts it,


If you'll bear with a poor comparison, sometimes programming is like a song. You do the tricky section, then you go back to an easier section and catch your breath for a bit.


The problem seems to be that people trained on imperative languages, when they're tossed into the ocean of functional coding, can't find the guideposts and landmarks that would help them impose some structure on the water. Should I put this complicated expression inside a "let", or break it out into another function? When do I use a higher-order function to unify two dissimilar pieces of code? Should I write this code in terms of higher-order library functions or directly? It's easy to wander off down a chain of nested invocations of anonymous higher-order functions, or composed partially applied library functions, just "because you can" and end up forgetting what you were trying to do in the first place.

Luckily, some of the basic rules of keeping your code readable remain more or less the same: assign intermediate results to variables with meaningful names, and abstract complicated operations into separate functions. To tackle David's example:


You get sections with DoThisAndThisAndThatWithTheResultsOfSelectThisFromTableXYZ that you have to slow down to think through.

...

GoToTheNextTrickyBit where ManyThingsHappen.

All in all, you wind up with a sort of ebb and flow that works out pretty well if you're in tune with the code being written, going from intense calculations, to a line or two where you do no more than store things in a variable, take a breather, and prepare for the next important stanza.


The way to "take a breath" in a functional language is generally to assign an intermediate result to a variable, or to extract a complicated operation into a function and give it a meaningful name. One Haskell approximation to David's example is


do DoThis
AndThis
results - SelectThisFromTableXYZ
someVal - AndThat results
GoToTheNextTrickyBit someval


If you're writing pure functional code, you might write


let
results = SelectThisFromTableXYZ
someVal = AndThat results
in
GoToTheNextTrickyBit someVal


Of course, this will become unreadable if you write a huge complicated nested "let" expression in place of "AndThat". For a truly dreadful example of this kind of coding, check out the Gnucash Scheme code that generates the "Cash Flow" report (warning: read this in short bursts, or you WILL go blind). This is exactly analogous to writing too many nested loops and conditionals in imperative code, and the fix is the same: find logically distinct bits of code and extract them into separate functions.

I have a few more thoughts, but this post is getting too long, so I'll inflict them on the world in another post. The rule that short things are easier to understand applies to blog posts as well as code. :-)

20 January 2007

Erich Schubert: The end of the world 2.0 is near.

I'm convinced the Web 2.0 bubble will impact soon. Granted, some will survive, some will struggle - but some will just blow up. Time to sell for these. There are several reasons why I believe this will happen "soon": Many people have been keeping an hungry eye on YouTube, Rapidshare and others. It's just a matter of time until some of these predators goes for the kill. My predictions for the post-web2.0-bubble time:

Eddy Petri&#537;or: HOWTO test PPPoE without having PPPoE (long)

I don't have an ISP which uses PPPoE or more than a laptop on my desk, but still, thanks to free software, I can test PPPoE installations (to some degree).

I have set up with qemu machines a virtual LAN that is made totally in user space via a TCP socket on port 1234. I needed this in order to test the changes I am working on for the ppp-udeb Debian installer module that supports (or should I say, should support) configuration of PPPoE connections.

These are the tools whose authors and maintainers deserve kudos:


This is the tutorial I followed to configure the PPPoE server http://www.freeantennas.com/PPPoE-Server-HOWTO.html, but until then I had to make the network.

In case someone is interested, here's how I did it (these are Debian centric instructions, but I don't see anything that would stop someone to do the same even on a windows machine).
I won't repeat that tutorial, but now I can create a virtual machine (well, I'll use an existing virtual machine) and test my custom D-I images and test the changes done in ppp-udeb.

Rock on!

Martin F. Krafft: No-fly list to be scrubbed?

Nori points me to this article by Bruce Schneier, which seems like good news for me. Does it mean I'll be able to visit the US again sometime in the future? I don't think so; travel to the US is among the most unattractive things I can currently think of. I might reconsider when the US stops treating visitors like terrorists, taking their fingerprints and requiring so-called "Passenger Name Records" to be made available by the airline companies transporting passengers into the US, with the sole purpose to build a criminal file for everyone entering the country, just in case they become a threat to national security or an obstacle in the path of the neo-conservatives to forge ahead. In addition, I'd fear for my laptop, which US immigration officers can now seize without reasons and scrutinise; I do not own a laptop because I can do without one for weeks on end. Furthermore, all my data are encrypted for good reasons. As the old saying goes: "only the guilty have something to hide", I'd surely make it into their prisons as a suspected terrorist (which has happened to people before). What the US doesn't understand is that even though I may be guilty and therefore hiding something, it doesn't mean I am hiding it from them. So no, I don't think I'll enter the US anytime soon. NP: I Love You but I've Chosen Darkness / Fear Is on Our Side

Eddy Petri&#537;or: RC bugs, what about important ones?

I was wondering if is right to our users that we are following only the RC bugs before a release. I think not. Don't get me wrong, I don't want important bugs count to be 0, or something similar; that would be insane to have as a goal.

I am thinking that we should (during the freeze) poke more of those important bugs that our and/or others' packages have. If you are like me, you will feel that you can't do anything/too much to improve the quality of the release during the freeze since some of the RC bugs are corner cases, not reproducible on your arch, already taken or you don't have the knowledge to fix them.

Many of the important bugs are broken functionalities that affect the users on a daily basis, and living 2 years with the same set of bugs is a pain. I don't know how that would feel, but I can imagine. I used Woody for only a half an year and after 2 months I started using backports. After 3, I started pulling things from Sarge (at the time it was testing). At the end of that half of year I was using mostly Sarge stuff and decided to go entirely into testing.


So, what do I propose? Maybe we should make some pages in the style of the RC bugs count pages which follow the important bugs.

As a bonus we might see some interesting things like bugs which were downgraded from RC - the RC graph would go down, while the important graph would rise. Of course, that wouldn't mean too much since that would be the product of badly assigned severities or downgraded and judged as non-RC bugs, but it would interesting to follow such tendencies.

Andrew Pollock: [life] Christmas in Vegas

(almost caught up on the blogging backlog) We had five days off over the Christmas period, from Christmas Eve on the Friday through to what we call Boxing Day (America doesn't do it, but Google gave us the day off). We spent the time in Las Vegas with our friends Craig and Sarah and their daughter Kes, in their "fifth wheel" trailer, as we had previously in Glamis. The drive was good. We stuffed around getting away on Friday, so didn't leave Mountain View until around 10am, so Craig and Sarah beat us there, when we were expecting to beat them (they couldn't leave until the end of business on Friday). It took us something like 9 hours to drive there. I think the thing I love the most about California is the diversity you get. We've seen snow, forests, beaches, desert. All without having to leave the state. One of the highlights of the trip was going through Bakersfield, which had heaps of oilwells all over the place. We also drove past one of the commercial aeroplane dumping grounds in the Mojave desert. Vegas itself was something to behold. It had a reality distortion field around it that made Google's pale into insignificance. The strip was great to walk up and down to just take in the architectural wonders that are the casinos on it. The adult industry is incredibly in your face. People are on the sidewalk handing out "calling cards" for what I thought were hookers, but I'm told are technically strippers, with catchlines such as "nude to your door in 15 minutes". What would normally dispense newspapers in any other city gave out free catalogues of what the adult industry had to offer. I thought all of that was a bit seedy. The casinos themselves where all much of a muchness inside. Far too smokey for my liking. I'm not a big gambler. I think blackjack is about the only game I can wrap my head around, and even then you can lose too much money too quickly on the tables, so I mainly played video blackjack with 25 cent bets. It's not a bad way to blow five bucks. The second hand smoke was a great deterrent against staying inside for too long. We caught Zumanity at New York New York, and had a humungous buffet lunch for Christmas Day at Mirage. We were staying in the trailer park attached to Circus Circus. It's pretty cool that there's a trailer park right on the strip. The one thing that I hadn't associated with Las Vegas was the shopping. Every one of the casinos on the strip had a massive shopping mall associated with it, and I mean massive. Paris' in particular took forever to escape from. The Forum Shops in Caesars Palace also felt like they went on forever. I initially thought how they painted the sky with clouds on the ceiling was quite clever, until I discovered that every mall did the same thing. Then it got a bit old. You could go to Vegas just for the shopping and the day spas, and never have to set foot in a casino gaming room. I'd like to make one more trip, and this time stay in a hotel, just for the hotel experience. I think Venice was my favourite looking casino (from the outside). Photos from the trip are here.

19 January 2007

Enrico Zini: tagminer

Cute things one could do with debtags While answering to a long message in the debtags-devel mailing list I accidentally put together the pieces of a fun idea. This is the bit of message I was answering:
  • It would be very useful if the means for indicating the supported
    data formats was more comprehensive. This could mean a lot of
    expanding in the "works-with-format" section of the vocabulary, which
    doesn't even include formats such as gif or mpg at the moment. I don't
    know how feasible it is to alter underlying debtags functionality, but
    perhaps it would be the easiest to make "works-with-format" a special
    case tag which allows for formats not listed in the vocabulary.
This is my answer:
Good point. The idea has popped up in the past to list supported mime types among the package metadata, so that one could point to a file and get a list of all the packages that can work with it. I'm not sure it's a good idea to encode mime types in debtags and I'd like to see something ad-hoc for it. In the meantime works-with-format is the best we can do, but we should limit it to the most common formats.
This is the fun idea: if works-with-format is the best we can do, what can we do with it? Earlier today I worked on resurrecting some old code of mine to expand Zack's ls2rss with Dublin Core metadata extracted from the files. The mime type scanner was ready for action. Some imports:
import sys
# Requires python-extractor, python-magic, python-apt
# and an unreleased python-debtags from http://bzr.debian.org/bzr/pkg-python-debian/trunk/
import extractor
import magic
from debian_bundle import debtags
import re
from optparse import OptionParser
import apt
A tenative mapping between mime types and debtags tags:
mime_map = (
        ( r'text/html\b', ("works-with::text","works-with-format::html") ),
        ( r'text/plain\b', ("works-with::text","works-with-format::plaintext") ),
        ( r'text/troff\b', ("works-with::text", "works-with-format::man") ),
        ( r'image/', ("works-with::image",) ),
        ( r'image/jpeg\b', ("works-with::image:raster","works-with-format::jpg") ),
        ( r'image/png\b', ("works-with::image:raster","works-with-format::png") ),
        ( r'application/pdf\b', ("works-with::text","works-with-format::pdf")),
        ( r'application/postscript\b', ("works-with::text","works-with-format::postscript")),
        ( r'application/x-iso9660\b', ('works-with-format::iso9660',)),
        ( r'application/zip\b', ('works-with::archive', 'works-with-format::zip')),
        ( r'application/x-tar\b', ('works-with::archive', 'works-with-format::tar')),
        ( r'audio/', ("works-with::audio",) ),
        ( r'audio/mpeg\b', ("works-with-format::mp3",) ),
        ( r'audio/x-wav\b', ("works-with-format::wav",) ),
        ( r'message/rfc822\b', ("works-with::mail",) ),
        ( r'video/', ("works-with::video",)),
        ( r'application/x-debian-package\b', ("works-with::software:package",)),
        ( r'application/vnd.oasis.opendocument.text\b', ("works-with::text",)),
        ( r'application/vnd.oasis.opendocument.graphics\b', ("works-with::image:vector",)),
        ( r'application/vnd.oasis.opendocument.spreadsheet\b', ("works-with::spreadsheet",)),
        ( r'application/vnd.sun.xml.base\b', ("works-with::db",)),
        ( r'application/rtf\b', ("works-with::text",)),
        ( r'application/x-dbm\b', ("works-with::db",)),
)
Code that does its best to extract a mime type:
extractor = extractor.Extractor()
magic = magic.open(magic.MAGIC_MIME)
magic.load()
def mimetype(fname):
    keys = extractor.extract(fname)
    xkeys =  
    for k, v in keys:
        if xkeys.has_key(k):
            xkeys[k].append(v)
        else:
            xkeys[k] = [v]
    namemagic =  magic.file(fname)
    contentmagic = magic.buffer(file(fname, "r").read(4096))
    return xkeys.has_key("mimetype") and xkeys['mimetype'][0] or contentmagic or namemagic
Command line parser:
parser = OptionParser(usage="usage: %prog [options] filename",
        version="%prog "+ VERSION,
        description="search Debian packages that can handle a given file")
parser.add_option("--tagdb", default="/var/lib/debtags/package-tags", help="Tag database to use (default: %default)")
parser.add_option("--action", default=None, help="Show the packages that allow the given action on the file (default: %default)")
(options, args) = parser.parse_args()
if len(args) == 0:
    parser.error("Please provide the name of a file to scan")
And here starts the fun: first we load the debtags data:
# Read full database 
fullcoll = debtags.DB()
tagFilter = re.compile(r"^special::.+$ ^.+::TODO$")
fullcoll.read(open(options.tagdb, "r"), lambda x: not tagFilter.match(x))
Then we scan the mime type and look up tags in the mime_map above:
type = mimetype(args[0])
#print >>sys.stderr, "Mime type:", type
found = set()
for match, tags in mime_map:
    match = re.compile(match)
    if match.match(type):
        for t in tags:
            found.add(t)
if len(found) == 0:
    print >>sys.stderr, "Unhandled mime type:", type
else:
If the user only gave the file name, let's show what Debian can do with that file:
    if options.action == None:
        print "Debtags query:", " && ".join(found)
        query = found.copy()
        query.add("role::program")
        subcoll = fullcoll.filterPackagesTags(lambda pt: query.issubset(pt[1]))
        uses = map(lambda x:x[5:], filter(lambda x:x.startswith("use::"), subcoll.iterTags()))
        print "Available actions:", ", ".join(uses)
If the user picked one of the available actions, let's show the packages that do it:
    else:
        aptCache = apt.Cache()
        query = found.copy()
        query.add("role::program")
        query.add("use::"+options.action)
        print "Debtags query:", " && ".join(query)
        subcoll = fullcoll.filterPackagesTags(lambda pt: query.issubset(pt[1]))
        for i in subcoll.iterPackages():
            aptpkg = aptCache[i]
            desc = aptpkg.rawDescription.split("\n")[0]
            print i, "-", desc
\o/ The morale of the story:

Christian Perrier: Junichi is my hero

Really. After MJ Ray summarized very useful information about building methods, I finally reconsidered my method for building packages. I usually use pbuilder but I'm pretty much annoyed with its slowness when unpackaking the base.tgz file. As a consequence, when I'm in a hurry, I sometimes just "debuild" packages on my live system. Booooo. Of course, this often leads to errors (two, recently, with samba. Booooo). On the other hand, using pbuilder is a very clean way to build packages...but is very slow, which is a pain when working on the "blitz NMU" uploads which I blogged about a few days ago. So, discovering cowdancer which is able to dance fast along with the safety of pbuilder was exactly what I was needing. Thanks, again, Junichi for that nice piece of work...and MJ for blogging about it!

Erich Schubert: Preinstalling Linux

I read today that Ubuntu is working on an "install.exe" for Ubuntu. Which apparently will install an Ubuntu image into C:\UBUNTU so you can boot that. It's not meant to wipe out or replace windows, but live alongside on the existing partition. (I'm curious how well that works with NTFS...) I'm looking forward to that - and crazy people bringing this Ubuntu.exe along on a CD whenever they go into some computer store and install Ubuntu on all the laptops on display. If the manufactures don't preinstall Linux, why shouldn't we help them out? We're not installing a virus there or deleting preinstalled software... Would be fun for a flashmob, too. Go into the shop with a dozen people, a few to distract the employees (asking difficult questions, eventually even buying something; since there is no reason to do any harm to the shop!) and others using CDs to preinstall Ubuntu. Of course it would be even more fun if the laptop booted Ubuntu the next day... All laptops looking different, but welcoming and friendly and with lots of powerful applications. Maybe one or another will think "whoa, did microsoft upgrade them to vista overnight?" :-)

Next.

Previous.