Changeset 66

Show
Ignore:
Timestamp:
01/16/05 17:20:39 (19 years ago)
Author:
jerome
Message:

Now retrieves printers too

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykoticon/trunk/bin/pykoticon

    r65 r66  
    9898class User : 
    9999    """A class for PyKota users.""" 
    100     def __init__(self, username, userinfo, userquotas) : 
     100    def __init__(self, username, userinfo, userquotas, printers) : 
    101101        """Initialize user datas.""" 
    102102        self.UserName = username 
     
    110110        except (ValueError, TypeError) : 
    111111            self.LifeTimePaid = 0.0 
    112         self.Quotas = [] 
     112        self.Printers = {}     
     113        self.Quotas = {} 
    113114        for i in range(len(userquotas["printername"])) : 
    114115            printername = userquotas["printername"][i] 
     116            try : 
     117                pindex = printers["printername"].index(printername) 
     118            except (ValueError, KeyError) : 
     119                pass 
     120            else :     
     121                self.Printers[printername] = Printer(printername, \ 
     122                                              printers["priceperpage"][pindex],\ 
     123                                              printers["priceperjob"][pindex]) 
    115124            pagecounter = userquotas["pagecounter"][i] 
    116125            softlimit = userquotas["softlimit"][i] 
    117126            hardlimit = userquotas["hardlimit"][i] 
    118127            datelimit = userquotas["datelimit"][i] 
    119             self.Quotas.append(UserQuota(printername, pagecounter, softlimit, \ 
    120                                          hardlimit, datelimit)) 
     128            self.Quotas[printername] = UserQuota(printername, pagecounter, \ 
     129                                                   softlimit, hardlimit, \ 
     130                                                              datelimit) 
    121131             
    122132class CGINetworkInterface : 
     
    155165        return answer 
    156166         
    157     def getPrinterNames(self) : 
     167    def getPrinters(self) : 
    158168        """Retrieve the printer's names.""" 
    159169        arguments = { "report" : 1, 
     
    161171                      "datatype" : "printers", 
    162172                    }   
    163         return self.retrieveDatas(arguments, ["printername"])["printername"] 
    164          
    165     def getUserInfo(self, username) : 
     173        return self.retrieveDatas(arguments, ["printername", "priceperpage", \ 
     174                                              "priceperjob"]) 
     175         
     176    def getUser(self, username) : 
    166177        """Retrieve the user's information.""" 
    167178        arguments = { "datatype" : "users", 
     
    180191                                              "datelimit")) 
    181192                                               
    182     def getUser(self, username) : 
     193    def getUserInfo(self, username) : 
    183194        """Retrieves the user account and quota information.""" 
    184         info = self.getUserInfo(username) 
     195        info = self.getUser(username) 
    185196        if info : 
    186197            quotas = self.getUserPQuotas(username) 
    187             return User(username, info, quotas) 
     198            return User(username, info, \ 
     199                                  self.getUserPQuotas(username), \ 
     200                                  self.getPrinters()) 
    188201     
    189202class PyKotIconGrid(gridlib.Grid) :     
    190203    """A class for user print quota entries.""" 
    191     def __init__(self, parent, quotas) : 
     204    def __init__(self, parent, user) : 
    192205        gridlib.Grid.__init__(self, parent, -1) 
    193206        sys.stderr.write("%s\n" % dir(self)) 
    194         self.CreateGrid(len(quotas), 4) 
     207        self.CreateGrid(len(user.Quotas.keys()), 4) 
    195208        self.EnableEditing(False) 
    196209        self.SetColLabelValue(0, _("Page Counter")) 
     
    208221        attr.SetReadOnly(True) 
    209222        self.SetColAttr(3, attr) 
    210         for i in range(len(quotas)) : 
    211             q = quotas[i] 
    212             self.SetRowLabelValue(i, quotas[i].PrinterName) 
    213             self.SetCellValue(i, 0, str(q.PageCounter)) 
    214             self.SetCellValue(i, 1, str(q.SoftLimit)) 
    215             self.SetCellValue(i, 2, str(q.HardLimit)) 
    216             self.SetCellValue(i, 3, str(q.DateLimit)) 
     223        i = 0 
     224        for printername in user.Quotas.keys() : 
     225            quota = user.Quotas[printername] 
     226            self.SetRowLabelValue(i, printername) 
     227            self.SetCellValue(i, 0, str(quota.PageCounter)) 
     228            self.SetCellValue(i, 1, str(quota.SoftLimit)) 
     229            self.SetCellValue(i, 2, str(quota.HardLimit)) 
     230            self.SetCellValue(i, 3, str(quota.DateLimit)) 
    217231            attr = gridlib.GridCellAttr() 
    218232            colour = wx.GREEN 
    219             if q.SoftLimit is not None : 
    220                 if q.PageCounter >= q.SoftLimit : 
     233            if quota.SoftLimit is not None : 
     234                if quota.PageCounter >= quota.SoftLimit : 
    221235                    colour = wx.RED 
    222             elif q.HardLimit is not None :         
    223                 if q.PageCounter >= q.HardLimit : 
     236            elif quota.HardLimit is not None :         
     237                if quota.PageCounter >= quota.HardLimit : 
    224238                    colour = wx.RED 
    225239            attr.SetBackgroundColour(colour)         
    226240            self.SetRowAttr(i, attr) 
     241            i += 1 
    227242        self.AutoSize() 
    228243             
     
    233248               _("PyKota Print Quota for user %s") % getCurrentUserName(), \ 
    234249               size = (460, -1), \ 
    235                style = wxPython.wx.wxDEFAULT_FRAME_STYLE | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 
     250               style = wxPython.wx.wxDEFAULT_FRAME_STYLE \ 
     251                     | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) 
    236252        self.greenicon = wxPython.wx.wxIcon(os.path.join("..", "icons", "pykoticon-green.ico"), \ 
    237253                                  wxPython.wx.wxBITMAP_TYPE_ICO) 
     
    275291        if self.inTimer is False : # avoids re-entrance 
    276292            self.inTimer = True 
    277             self.User = self.networkInterface.getUser(getCurrentUserName()) 
     293            self.User = self.networkInterface.getUserInfo(getCurrentUserName()) 
    278294            if self.User.LimitBy == "balance" : 
    279295                if self.User.Balance <= 0.0 : 
     
    283299            else :         
    284300                isRed = False 
    285                 for q in self.User.Quotas : 
    286                     if q.SoftLimit is not None : 
    287                         if q.PageCounter >= q.SoftLimit : 
     301                for q in self.User.Quotas.keys() : 
     302                    quota = self.User.Quotas[q] 
     303                    if quota.SoftLimit is not None : 
     304                        if quota.PageCounter >= quota.SoftLimit : 
    288305                            isRed = True 
    289306                            break 
    290                     elif q.HardLimit is not None :         
    291                         if q.PageCounter >= q.HardLimit : 
     307                    elif quota.HardLimit is not None :         
     308                        if quota.PageCounter >= quota.HardLimit : 
    292309                            isRed = True 
    293310                            break 
     
    300317                    self.quotasgrid.Destroy() 
    301318                    del self.quotasgrid 
    302                 self.quotasgrid = PyKotIconGrid(self, self.User.Quotas)     
     319                self.quotasgrid = PyKotIconGrid(self, self.User)     
    303320            self.inTimer = False 
    304321        # Now we want it every 3 minutes     
     
    320337            self.chrono.Stop() 
    321338            del self.chrono 
     339        if hasattr(self, "quotasgrid") : 
     340            self.quotasgrid.Close() 
     341            self.quotasgrid.Destroy() 
     342            del self.quotasgrid 
    322343        if hasattr(self, "menu") : 
    323344            self.menu.Destroy() 
     
    375396        username = getCurrentUserName() 
    376397    net = CGINetworkInterface(DUMPYKOTA_URL) 
    377     user = net.getUser(username) 
     398    user = net.getUserInfo(username) 
    378399    print "UserName : ", user.UserName 
    379400    print "LimitBy : ", user.LimitBy 
    380401    print "Balance : ", user.Balance 
    381     for q in user.Quotas : 
    382         print "\tPrinterName : ", q.PrinterName 
    383         print "\tPageCounter : ", q.PageCounter 
    384         print "\tSoftLimit : ", q.SoftLimit 
    385         print "\tHardLimit : ", q.HardLimit 
    386         print "\tDateLimit : ", q.DateLimit 
     402    for printername in user.Quotas.keys() : 
     403        quota = user.Quotas[printername] 
     404        print "\tPrinterName : ", printername 
     405        print "\tPageCounter : ", quota.PageCounter 
     406        print "\tSoftLimit : ", quota.SoftLimit 
     407        print "\tHardLimit : ", quota.HardLimit 
     408        print "\tDateLimit : ", quota.DateLimit 
    387409        print 
     410    for printername in user.Printers.keys() : 
     411        printer = user.Printers[printername] 
     412        print "\tPrinterName : ", printername 
     413        print "\tPrice per Page : ", printer.PricePerPage 
     414        print "\tPrice per Job : ", printer.PricePerJob 
     415        print 
     416         
     417         
    388418 
    389419if __name__ == '__main__':