root / pykoticon / trunk / bin / pykoticon @ 50

Revision 50, 3.1 kB (checked in by jerome, 19 years ago)

Id property

Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3
4# PyKotIcon - Windows System Tray Icon for PyKota
5#
6# (c) 2003-2004 Jerome Alet <alet@librelogiciel.com>
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20#
21# $Id$
22#
23#
24
25import sys
26import os
27import pwd
28import time
29import urllib
30import urllib2
31
32DUMPYKOTA_URL = "http://cgi.librelogiciel.com/cgi-bin/dumpykota.cgi"
33USERNAME = "jerome"
34
35def getPrinterNames() :
36    """Retrieve the printer's names."""
37    arguments = { "report" : 1,
38                  "format" : "csv",
39                  "datatype" : "printers",
40                } 
41    return retrieveDatas(arguments, ["printername"])["printername"]
42   
43def getUserInfo(username) :
44    """Retrieve the user's information."""
45    arguments = { "datatype" : "users",
46                  "filter" : "username=%s" % username,
47                } 
48    return retrieveDatas(arguments, ("limitby", "balance", "lifetimepaid"))
49   
50def getUserPQuotas(username) :
51    """Retrieve the user's print quota information."""
52    arguments = { "datatype" : "upquotas",
53                  "filter" : "username=%s" % username,
54                } 
55    return retrieveDatas(arguments, ("printername", "pagecounter", "softlimit", "datelimit"))
56   
57def retrieveDatas(args, fieldnames) :
58    """Retrieve datas from the CGI script."""
59    arguments = { "report" : 1,
60                  "format" : "csv",
61                } 
62    arguments.update(args)           
63    answer = {}
64    try :           
65        url = "%s?%s" % (DUMPYKOTA_URL, urllib.urlencode(arguments))
66        u = urllib2.urlopen(url)
67        lines = u.readlines()
68    except :   
69        sys.stderr.write("Unable to retrieve %s\n" % url)
70    else :   
71        u.close()
72        try :
73            lines = [ line.strip().split(",") for line in lines ]
74            fields = [field[1:-1] for field in lines[0]]
75            indices = [fields.index(fname) for fname in fieldnames]
76            answer = dict([ (fieldname, \
77                            [ line[fields.index(fieldname)][1:-1] for line in lines[1:] ]) \
78                            for fieldname in fieldnames ])
79        except :   
80            sys.stderr.write("Invalid datas retrieved from %s\n" % url)
81    return answer
82   
83if __name__ == "__main__" :
84    #printernames = getPrinterNames()
85    #print "List of printers : ", printernames
86   
87    userinfo = getUserInfo("jerome")
88    print "User jerome : ", userinfo
89   
90    userpquotas = getUserPQuotas("jerome")
91    print "User jerome's print quotas : ", userpquotas
Note: See TracBrowser for help on using the browser.