root / pykota / trunk / contributed / mysql_history / mysql_history.py @ 3492

Revision 2611, 1.5 kB (checked in by matt, 19 years ago)

Added a mysql_history program and support files. It's not full blown mysql
support, but it's a start! :-)

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3import MySQLdb, pwd, string, sys
4from ConfigParser import *
5from os import environ
6
7try:
8        pykotauser = pwd.getpwnam("pykota")
9except KeyError:
10        pykotauser = None
11        confdir = "/etc/pykota"
12else:
13        confdir = pykotauser[5]
14
15configfile = confdir + "/mysql_history.conf"
16
17config = ConfigParser()
18config.read(configfile)
19mysqlserver = config.get("default", "server").strip()
20mysqluser = config.get("default", "username").strip()
21mysqlpass = config.get("default", "password").strip()
22mysqldb = config.get("default", "database").strip()
23mysqltable = config.get("default", "table").strip()
24
25try:
26        db = MySQLdb.connect(mysqlserver,mysqluser,mysqlpass,mysqldb)
27except:
28        print "Unable to connect to MySQL database."
29        sys.exit(1)
30
31cursor = db.cursor()
32
33cursor.execute("""INSERT INTO %s (id, jobid, username, printername, pgroups,
34        jobsize, jobprice, action, title, copies, options,
35        printeroriginatinghostname, md5sum, precomputedjobsize,
36        precomputedjobprice) VALUES
37        ("", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")""" % 
38        (mysqltable, environ['PYKOTAJOBID'], environ['PYKOTAUSERNAME'], environ['PYKOTAPRINTERNAME'], environ['PYKOTAPGROUPS'], environ['PYKOTAJOBSIZE'],environ['PYKOTAJOBPRICE'], environ['PYKOTAACTION'], environ['PYKOTATITLE'],environ['PYKOTACOPIES'],environ['PYKOTAOPTIONS'],environ['PYKOTAJOBORIGINATINGHOSTNAME'],environ['PYKOTAMD5SUM'],environ['PYKOTAPRECOMPUTEDJOBSIZE'],environ['PYKOTAPRECOMPUTEDJOBPRICE']))
39
40cursor.close()
41
42# vim:tabstop=4
Note: See TracBrowser for help on using the browser.