- Timestamp:
- 01/14/05 21:00:43 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykoticon/trunk/bin/pykoticon
r55 r56 24 24 25 25 import sys 26 import os27 import pwd28 import time29 26 import urllib 30 27 import urllib2 31 28 32 29 DUMPYKOTA_URL = "http://cgi.librelogiciel.com/cgi-bin/dumpykota.cgi" 33 USERNAME = "jerome"34 30 31 class UserQuota : 32 """A class for PyKota User Print Quota entries.""" 33 def __init__(self, printername, pagecount, softlimit, hardlimit, datelimit): 34 """Initialize user print quota datas.""" 35 self.PrinterName = printername 36 try : 37 self.PageCounter = int(pagecount) 38 except (ValueError, TypeError) : 39 self.PageCounter = 0 40 try : 41 self.SoftLimit = int(softlimit) 42 except (ValueError, TypeError) : 43 self.SoftLimit = None 44 try : 45 self.HardLimit = int(hardlimit) 46 except (ValueError, TypeError) : 47 self.HardLimit = None 48 self.DateLimit = datelimit 49 50 class User : 51 """A class for PyKota users.""" 52 def __init__(self, username, userinfo, userquotas) : 53 """Initialize user datas.""" 54 self.Name = username 55 self.LimitBy = userinfo["limitby"][0].lower() 56 try : 57 self.Balance = float(userinfo["balance"][0]) 58 except (ValueError, TypeError) : 59 self.Balance = 0.0 60 try : 61 self.LifeTimePaid = float(userinfo["lifetimepaid"][0]) 62 except (ValueError, TypeError) : 63 self.LifeTimePaid = 0.0 64 self.Quotas = [] 65 for i in range(len(userquotas["printername"])) : 66 printername = userquotas["printername"][i] 67 pagecounter = userquotas["pagecounter"][i] 68 softlimit = userquotas["softlimit"][i] 69 hardlimit = userquotas["hardlimit"][i] 70 datelimit = userquotas["datelimit"][i] 71 self.Quotas.append(UserQuota(printername, pagecounter, softlimit, \ 72 hardlimit, datelimit)) 73 35 74 class CGINetworkInterface : 36 75 """A class for all network interactions.""" 37 def __init__(self, url, username=None, password=None) :76 def __init__(self, cgiurl, authname=None, authpw=None) : 38 77 """Initialize CGI connection datas.""" 39 self. url =url40 self. username = username41 self. password = password78 self.cgiurl = cgiurl 79 self.authname = authname 80 self.authpw = authpw 42 81 43 82 def retrieveDatas(self, arguments, fieldnames) : … … 49 88 answer = {} 50 89 try : 51 url = "%s?%s" % (self. url, urllib.urlencode(args))90 url = "%s?%s" % (self.cgiurl, urllib.urlencode(args)) 52 91 u = urllib2.urlopen(url) 53 92 lines = u.readlines() … … 61 100 indices = [fields.index(fname) for fname in fieldnames] 62 101 answer = dict([ (fieldname, \ 63 [ line[fields.index(fieldname)][1:-1] for line in lines[1:] ]) \ 102 [ line[fields.index(fieldname)][1:-1] \ 103 for line in lines[1:] ]) \ 64 104 for fieldname in fieldnames ]) 65 105 except : … … 87 127 "filter" : "username=%s" % username, 88 128 } 89 return self.retrieveDatas(arguments, ("printername", "pagecounter", "softlimit", "datelimit")) 129 return self.retrieveDatas(arguments, ("printername", "pagecounter", \ 130 "softlimit", "hardlimit", "datelimit")) 131 132 def getUser(self, username) : 133 """Retrieves the user account and quota information.""" 134 info = self.getUserInfo(username) 135 quotas = self.getUserPQuotas(username) 136 return User(username, info, quotas) 90 137 91 138 if __name__ == "__main__" : 92 139 net = CGINetworkInterface(DUMPYKOTA_URL) 93 print "List of printers : ", net.getPrinterNames()140 #print "List of printers : ", net.getPrinterNames() 94 141 95 print "User : ", net.getUserInfo("jerome")142 #print "User : ", net.getUserInfo("jerome") 96 143 97 print "User print quotas : ", net.getUserPQuotas("jerome") 144 #print "User print quotas : ", net.getUserPQuotas("jerome") 145 jerome = net.getUser("jerome") 98 146