1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import MySQLdb, pwd, string, sys |
---|
4 | from ConfigParser import * |
---|
5 | from os import environ |
---|
6 | |
---|
7 | try: |
---|
8 | pykotauser = pwd.getpwnam("pykota") |
---|
9 | except KeyError: |
---|
10 | pykotauser = None |
---|
11 | confdir = "/etc/pykota" |
---|
12 | else: |
---|
13 | confdir = pykotauser[5] |
---|
14 | |
---|
15 | configfile = confdir + "/mysql_history.conf" |
---|
16 | |
---|
17 | config = ConfigParser() |
---|
18 | config.read(configfile) |
---|
19 | mysqlserver = config.get("default", "server").strip() |
---|
20 | mysqluser = config.get("default", "username").strip() |
---|
21 | mysqlpass = config.get("default", "password").strip() |
---|
22 | mysqldb = config.get("default", "database").strip() |
---|
23 | mysqltable = config.get("default", "table").strip() |
---|
24 | |
---|
25 | try: |
---|
26 | db = MySQLdb.connect(mysqlserver,mysqluser,mysqlpass,mysqldb) |
---|
27 | except: |
---|
28 | print "Unable to connect to MySQL database." |
---|
29 | sys.exit(1) |
---|
30 | |
---|
31 | cursor = db.cursor() |
---|
32 | |
---|
33 | cursor.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 | |
---|
40 | cursor.close() |
---|
41 | |
---|
42 | # vim:tabstop=4 |
---|