generate hdlist/sysnthesis files on a debian system

Date Tags perl / rpm

Imagine you want to create hdlist/sysnthesis files from a bunch of rpms on a debian system. If you know what you need it is not actually that difficult. The mandriva svn contains the tool genhdlist2. To use it on a debian machine we need to download and install two perl modules that are contained in the same directory as above, namely, perl-URPMI and MDV-Packdrakeng. The tool we want to use is in the rpmtools directory. You can svn checkout everything from http://svn.mandriva.com/svn/soft/rpm .

Once downloaded everything you would either need to install these perl libraries system-wide (bad idea…) or locally and to fiddle a bit with the genhdlist2 script in order to specify the location of these two libraries. Personally I added these two lines at the beginning of the file :

use lib '/tmp/perl-URPM/trunk/blib/lib';
use lib '/tmp/MDV-Packdrakeng/trunk/lib';

Make also sure that you compile the URPMI.so component of the perl library and copy it to the lib directory.

Now you are ready to generate your hdlist/systhesis files just by giving a directory with all the rpms to the tool as in perl genhdlist2 rpms

et voila.

Update

I’ve committed the script and supporting modules here if you are interested. To access the forge you need a username/password: you can use mancoosi/mancoosi if you want anonymous access.


expose you command line application on the web with python and fcgi

So one day you’re too lazy to write a fcgi library for your favorite language but you want nonetheless expose an application on the web… Then use python ! There are quite a few frameworks to run fcgi with python, but if you want something easy, I think that flup is for you.

The code below takes care of few aspects for you. First flup span a server talking at port 5555 on localhost. You can configure it to be multi thread is you want to. Then using the cgi module we make sure that the input is clean and ready to use. Finally we run your fantastic application as DOSOMETHING. If your application is a simple program, of course there is no reason to write a fcgi. A common cgi will pay the bill. However, if your application can benefit from some form of caching, then maybe writing the web related stuff in python and use the application as a black box can be a nice idea.

If might want to check out [flup http://trac.saddi.com/flup] and [werkzeug http://werkzeug.pocoo.org/]. I’ve not used the last one, but it seems more complete then flup.

#!/usr/bin/python
# -*- coding: UTF-8 -*-

from cgi import escape
import sys, os
from flup.server.fcgi import WSGIServer
import subprocess
import urlparse
import cgi
# expose python errors on the web
import cgitb
cgitb.enable()

def app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    yield '<html><head></head>'
    yield '<body>\n'

    form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,keep_blank_values=1)

    yield '<table border="1">'
    if form.list:
        yield '<tr><th colspan="2">Form data</th></tr>'

    for field in form.list:
        yield '<tr><td>%s</td><td>%s</td></tr>' % (field.name, field.value)

    yield '</table>'

    if form.has_key('c') and form.has_key('l'):
        cat = form.getvalue('c')
        pl = form.getlist('l')
        command = DOSOMETHING(cat,pl)
        results = subprocess.Popen(command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        (i,e) = results.communicate()
        yield '%s\n' % i
        yield '%s\n' % e

    yield '</body>\n'
    yield '</html>\n'

WSGIServer(app,bindAddress=('localhost',5555)).run()

quote of the day

Date Tags quotes

You may well ask: “Why direct action? Why sit-ins, marches and so forth? Isn’t negotiation a better path?” You are quite right in calling, for negotiation. Indeed, this is the very purpose of direct action. Nonviolent direct action seeks to create such a crisis and foster such a tension that a community which has constantly refused to negotiate is forced to confront the issue. It seeks so to dramatize the issue that it can no longer be ignored. My citing the creation of tension as part of the work of the nonviolent-resister may sound rather shocking. But I must confess that I am not afraid of the word “tension.” I have earnestly opposed violent tension, but there is a type of constructive, nonviolent tension which is necessary for growth. Just as Socrates felt that it was necessary to create a tension in the mind so that individuals could rise from the bondage of myths and half-truths to the unfettered realm of creative analysis and objective appraisal, we must we see the need for nonviolent gadflies to create the kind of tension in society that will help men rise from the dark depths of prejudice and racism to the majestic heights of understanding and brotherhood. - Martin Luther King: “Letter from Birmingham”

to read : [http://en.wikipedia.org/wiki/Civil_Disobedience_%28Thoreau%29 Civil Disobedience, an essay by Henry David Thoreau] Satyagraha - the practice of non-violent resistance developed by Mohandas Gandhi * [http://en.wikipedia.org/wiki/Letter_from_Birmingham_Jail The Letter from Birmingham Jail by Martin Luther King, Jr.]


fosdem cool stuff

Date Tags fosdem

Well… I went to fosdem 2010:) Very nice indeed as every year. Kudos to the organizers. Even though this year I didn’t manage to grab a t-shirt as I usually do …

indenti.ca

I attended a presentation about identi.ca. I’m not very much micro-blogging person. I like social networks but just to get in touch with friends and nothing else. What I like about identi.ca (as many other people at fosdem) is the FOSS side of it and it’s implementation of open standards. The talk was well delivered and informative. Thanks !

gwibber

So, during a presentation I snoop on my neighbor’s laptop and he was using twhirl, that is a nice “freeware” piece of software. Closed source ? No way ! There is a nice FOSS alternative though. Gwibber. I’ve tried it out yesterday and it does a nice job. From its homepage, this is the description.

Gwibber is an open source microblogging framework and desktop client for GNOME developed with Python and GTK+. The Gwibber backend is a stand-alone daemon that manages updates and retrieves stream data from social networks. The Gwibber backend can be accessed through D-Bus and currently uses GConf to store account configuration info.

homepage: http://live.gnome.org/Gwibber

Does it work ? uhmmm playing with it I would say that is a still a bit young. The interface does not always work (how do I replay to a message, or how to I subscribe to a specific tag on identi.ca ?) and it is not very well polished. A piece of software to be consider, but not ready for prime time, at least for me.

Nmap Scripting Engine (NSE)

I attended a very nice presentation about NSE, the nmap scripting engine that I didn’t know at all. It’s a very powerful tool to scan an analyzing networks. There is a free chapter of the nmap book available and I think it’s completely worth reading it.

This is the material from the presentation that includes a very nice handout about nse.

lua

And NSE is written in LUA that is a powerful, fast, lightweight, embeddable scripting language. I’ve already came across it and I think I’ll spend sometimes to see if it can be useful for my projects.

homepage : http://www.lua.org/about.html

Drupal

As every year I spent a few hours in the Drupal run. The drupal community is extremely active. I failed to attend the talk about the upcoming drupal 7 release. Fortunately I’ve found this keynote online that is work watching if you are interested. Drupal 7 is going to be a super release both from site designed and developers. I really looking forward to it.

During a presentation about installing and developing with Drupal, the discussions went on the dependency system of the modules and plugins in Drupal. Needless to say that this might be a nice application of the work we are doing with mancoosi. At it should also be reasonably easy to integrate it with drush. Now I just need a php binding of a sat solver that understands CUDF. AH!

guake

Guake is a quake console stile unix terminal for gnome. I’m addicted. I’ve configured guake to slide down with alt+space, in the same way I’ve ubiquity on firefox. I feel home. The console is there when I need it, it’s fast, and with the correct key-bindings is just like gnome-terminal. I’m definitely happy I’ve discover it. Next step is going to be a tiling window manager, but this is material for another post.

this is the wikipedia page about it : http://en.wikipedia.org/wiki/Guake It’s homepage seems down at the moment.

I attended many other presentations, but this is enough for one post. See you at fosdem 2011


ExtLib OptParse (part 2)

Date Tags ocaml

I’ve already wrote something about OptParse last month. Today I discovered how to create a new option (that is not a string, int or bool) and validate it within the arg parser.

So suppose we want to write an application that can output both txt and html and we want the user to specify the format with command line option. One way would be to use a StdOpt.str_option - eventually with a default option - and to retrive it in application code with OptParse.Opt.get.

However this is not satisfactory as we are mixing the application code with command line parsing. A better way is to create a new type of option with Opt.value_option .

This is the concept :

type out_t = Txt | Html
module Options = struct
  open OptParse
  exception Format
  let out_option ?default ?(metavar = "<txt|html>") () =
    let corce = function
      |"txt" -> Txt
      |"html" -> Html
      | _ -> raise Format
    in
    let error _ s = Printf.sprintf "%s format not supported" s in
    Opt.value_option metavar default corce error

  let output = out_option ~default:Txt ()

  let description = "This is an example"
  let options = OptParser.make ~description:description ()

  open OptParser
  add options ~short_name:'o' ~long_name:"out" ~help:"Output type" output;
end

Note that the function Opt.value_option get a default value, a metavar - that is the sting associated with the option in the help ( -o<txt|html>, --out=<txt|html> Output type ), a corce function, that is, a function that transforms a string in the desired type, and an error function that is used by the parser to give a meaningful error is the option is not correctly validated.

For example :

$./test.native -oooo
usage: test.native [options]

test.native: option '-o': ooo format not supported

Now when we use this new option in the application code with OptParse.Opt.get and we can be certain that it was correctly validated.