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:

# -*- coding: iso-8859-1 -*-
from entropy.client.interfaces import Client
import time

client = Client()
repo = client.open_repository("")
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]


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

The database is located here:
or here