Thursday, April 15, 2010

Scripting with the Entropy codebase

I'm not a python developer myself at all, but I was just curious about the great codebase that Fabio wrote and documented.

Knowing I have the repository database on my hard disc I figured it should be simple to let it list the last 100 changed packages.
This is how its done:


#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
from entropy.client.interfaces import Client
import time

client = Client()
repo = client.open_repository("sabayonlinux.org")
cur = repo._cursor().execute

for row in repo._cursor().execute('SELECT `extrainfo`.`datecreation`,`baseinfo`.`atom` FROM `baseinfo`,`extrainfo` WHERE `baseinfo`.`idpackage` = `extrainfo`.`idpackage` ORDER BY `extrainfo`.`datecreation` DESC LIMIT 100'):
my_time = float(row[0])
human_time = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(my_time))
print human_time,' ',row[1]

client.shutdown()

http://www.sabayon.org/entropy/api/docs/

If you want to know about the table layout, visually, you can use dev-db/sqlitebrowser

The database is located here:
/var/lib/entropy/client/database/x86/sabayonlinux.org/standard/x86/5/packages.db
or here
/var/lib/entropy/client/database/amd64/sabayonlinux.org/standard/amd64/5/packages.db

No comments: