#!/usr/bin/python

# Copyright (C) 2006 Peter Poeml.  All rights reserved.
# This program is free software; it may be used, copied, modified
# and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version.


import sys, os, MySQLdb
import ConfigParser

conffile = '/etc/mirrorbrain.conf'

cp = ConfigParser.SafeConfigParser()
cp.read(conffile)
cfg = dict(cp.items('general'))

servername = sys.argv[1]
score = sys.argv[2]

dbh = MySQLdb.connect(host=cfg['dbhost'], port=int(cfg['dbport']), 
                      user=cfg['dbuser'], passwd=cfg['dbpass'], 
                      db=cfg['dbname'])

cursor = dbh.cursor(MySQLdb.cursors.DictCursor)

sqlraw = 'update server set score=%s where identifier=%s'
cursor.execute(sqlraw, [score, servername])

cursor.close()
dbh.commit()
dbh.close()
