Changeset 1582

Show
Ignore:
Timestamp:
07/01/04 19:45:49 (20 years ago)
Author:
jalet
Message:

Added code to handle the description field for printers

Location:
pykota/trunk
Files:
14 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r1546 r1582  
    2424# 
    2525# $Log$ 
     26# Revision 1.12  2004/07/01 17:45:47  jalet 
     27# Added code to handle the description field for printers 
     28# 
    2629# Revision 1.11  2004/06/18 13:34:48  jalet 
    2730# Now all tracebacks include PyKota's version number 
     
    8790                        
    8891  -d | --delete        Deletes printers from the quota storage. 
     92   
     93  -D | --description   Adds a textual description to printers. 
    8994                        
    9095  -c | --charge p[,j]  Sets the price per page and per job to charge. 
     
    122127examples :                               
    123128 
    124   $ pkprinters --add --charge 0.05,0.1 hp2100 hp2200 hp8000 
     129  $ pkprinters --add -D "HP Printer" --charge 0.05,0.1 hp2100 hp2200 hp8000 
    125130   
    126131  Will create three printers named hp2100, hp2200 and hp8000. 
     
    128133  per job will be set at 0.1 unit. Units are in your own currency, 
    129134  or whatever you want them to mean. 
    130   If any of these printers already exists, it is not modified at 
    131   all. 
     135  All of their descriptions will be set to the string "HP Printer". 
     136  If any of these printers already exists, it will also be modified  
     137  unless the -s|--skipexisting command line option is also used. 
    132138             
    133139  $ pkprinters --delete "*" 
     
    191197                if printer.Exists : 
    192198                    if options["skipexisting"] : 
    193                         self.logger.log_message(_("Printer %s already exists, skipping.") % printer.Name, "warn") 
     199                        self.printError(_("Printer %s already exists, skipping.") % printer.Name) 
    194200                    else :     
    195                         self.logger.log_message(_("Printer %s already exists, will be modified.") % printer.Name, "warn") 
     201                        self.printError(_("Printer %s already exists, will be modified.") % printer.Name) 
    196202                        printers.append(printer) 
    197203                else : 
     
    216222                if parents :  
    217223                    parents = "%s %s" % (_("in"), parents) 
    218                 print "%s (%s + #*%s) %s" % \ 
    219                       (printer.Name, printer.PricePerJob, \ 
     224                print "%s [%s] (%s + #*%s) %s" % \ 
     225                      (printer.Name, printer.Description, printer.PricePerJob, \ 
    220226                       printer.PricePerPage, parents) 
    221227            else :     
    222228                if options["charge"] : 
    223229                    printer.setPrices(perpage, perjob)     
     230                if options["description"] is not None : 
     231                    printer.setDescription(options["description"].strip()) 
    224232                if options["groups"] :     
    225233                    for pgroup in printersgroups : 
     
    232240    retcode = 0 
    233241    try : 
    234         short_options = "hvac:dg:lrs" 
    235         long_options = ["help", "version", "add", "charge=", "delete", "groups=", "list", "remove", "skipexisting"] 
     242        short_options = "hvac:D:dg:lrs" 
     243        long_options = ["help", "version", "add", "charge=", "description=", "delete", "groups=", "list", "remove", "skipexisting"] 
    236244         
    237245        # Initializes the command line tool 
     
    246254        options["add"] = options["a"] or options["add"] 
    247255        options["charge"] = options["c"] or options["charge"] 
     256        options["description"] = options["D"] or options["description"] 
    248257        options["delete"] = options["d"] or options["delete"]  
    249258        options["groups"] = options["g"] or options["groups"] 
     
    256265        elif options["version"] : 
    257266            manager.display_version_and_quit() 
    258         elif (options["delete"] and (options["add"] or options["groups"] or options["charge"] or options["remove"])) \ 
     267        elif (options["delete"] and (options["add"] or options["groups"] or options["charge"] or options["remove"] or options["description"])) \ 
    259268           or (options["skipexisting"] and not options["add"]) \ 
    260            or (options["list"] and (options["add"] or options["delete"] or options["groups"] or options["charge"] or options["remove"])) : 
     269           or (options["list"] and (options["add"] or options["delete"] or options["groups"] or options["charge"] or options["remove"] or options["description"])) : 
    261270            raise PyKotaToolError, _("incompatible options, see help.") 
    262271        elif options["remove"] and not options["groups"] :     
  • pykota/trunk/cgi-bin/printquota.cgi

    r1525 r1582  
    2323# 
    2424# $Log$ 
     25# Revision 1.30  2004/07/01 17:45:48  jalet 
     26# Added code to handle the description field for printers 
     27# 
    2528# Revision 1.29  2004/06/06 21:07:55  jalet 
    2629# Improved CGI script to allow history on printers and hostnames. 
     
    189192        for printer in printers : 
    190193            if printer.Name in selectednames : 
    191                 message += '<option value="%s" selected="selected">%s</option>' % (printer.Name, printer.Name) 
     194                message += '<option value="%s" selected="selected">%s (%s)</option>' % (printer.Name, printer.Name, printer.Description) 
    192195            else : 
    193                 message += '<option value="%s">%s</option>' % (printer.Name, printer.Name) 
     196                message += '<option value="%s">%s (%s)</option>' % (printer.Name, printer.Name, printer.Description) 
    194197        message += '</select></td></tr></table>' 
    195198        return message 
  • pykota/trunk/man/edpykota.1

    r1578 r1582  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH EDPYKOTA "1" "June 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH EDPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44edpykota \- manual page for edpykota 1.19alpha28_unofficial 
  • pykota/trunk/man/pkhint.1

    r1578 r1582  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH PKHINT "1" "June 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH PKHINT "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44pkhint \- manual page for pkhint 1.19alpha28_unofficial 
  • pykota/trunk/man/pkprinters.1

    r1578 r1582  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH PKPRINTERS "1" "June 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH PKPRINTERS "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44pkprinters \- manual page for pkprinters 1.19alpha28_unofficial 
     
    2626\fB\-d\fR | \fB\-\-delete\fR 
    2727Deletes printers from the quota storage. 
     28.TP 
     29\fB\-D\fR | \fB\-\-description\fR 
     30Adds a textual description to printers. 
    2831.TP 
    2932\fB\-c\fR | \fB\-\-charge\fR p[,j] 
     
    6568examples : 
    6669.IP 
    67 \f(CW$ pkprinters --add --charge 0.05,0.1 hp2100 hp2200 hp8000\fR 
     70\f(CW$ pkprinters --add -D "HP Printer" --charge 0.05,0.1 hp2100 hp2200 hp8000\fR 
    6871.IP 
    6972Will create three printers named hp2100, hp2200 and hp8000. 
     
    7174per job will be set at 0.1 unit. Units are in your own currency, 
    7275or whatever you want them to mean. 
    73 If any of these printers already exists, it is not modified at 
    74 all. 
     76All of their descriptions will be set to the string "HP Printer". 
     77If any of these printers already exists, it will also be modified 
     78unless the \fB\-s\fR|--skipexisting command line option is also used. 
    7579.IP 
    7680\f(CW$ pkprinters --delete "*"\fR 
  • pykota/trunk/man/pykotme.1

    r1578 r1582  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH PYKOTME "1" "June 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH PYKOTME "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44pykotme \- manual page for pykotme 1.19alpha28_unofficial 
  • pykota/trunk/man/repykota.1

    r1578 r1582  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH REPYKOTA "1" "June 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH REPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44repykota \- manual page for repykota 1.19alpha28_unofficial 
  • pykota/trunk/man/warnpykota.1

    r1578 r1582  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33. 
    2 .TH WARNPYKOTA "1" "June 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH WARNPYKOTA "1" "July 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44warnpykota \- manual page for warnpykota 1.19alpha28_unofficial 
  • pykota/trunk/NEWS

    r1578 r1582  
    2424    - 1.19alpha28 : 
    2525     
     26        - The description field for printers can now be set, 
     27          and is displayed in reports. 
     28           
     29        - Fixed a small problem in SQL backend code. 
     30           
    2631        - Improved pkhint 
    2732         
  • pykota/trunk/pykota/reporter.py

    r1418 r1582  
    2222# 
    2323# $Log$ 
     24# Revision 1.9  2004/07/01 17:45:49  jalet 
     25# Added code to handle the description field for printers 
     26# 
    2427# Revision 1.8  2004/03/24 15:15:24  jalet 
    2528# Began integration of Henrik Janhagen's work on quota-then-balance 
     
    7073         
    7174    def getPrinterTitle(self, printer) :      
    72         return _("Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name) 
     75        return (_("Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name)) + (" (%s)" % printer.Description) 
    7376         
    7477    def getPrinterGraceDelay(self, printer) :     
     
    100103        balance = float(entry.AccountBalance or 0.0) 
    101104        lifetimepaid = float(entry.LifeTimePaid or 0.0) 
    102          
     105         
    103106        #balance 
    104107        if entry.LimitBy and (entry.LimitBy.lower() == "balance") :     
  • pykota/trunk/pykota/storage.py

    r1523 r1582  
    2222# 
    2323# $Log$ 
     24# Revision 1.56  2004/07/01 17:45:49  jalet 
     25# Added code to handle the description field for printers 
     26# 
    2427# Revision 1.55  2004/06/05 22:18:04  jalet 
    2528# Now catches some exceptions earlier. 
     
    317320        self.PricePerPage = None 
    318321        self.PricePerJob = None 
     322        self.Description = None 
    319323         
    320324    def __getattr__(self, name) :     
     
    353357            self.PricePerJob = float(priceperjob) 
    354358        self.parent.writePrinterPrices(self) 
     359         
     360    def setDescription(self, description = None) :     
     361        """Sets the printer's prices.""" 
     362        if description is None : 
     363            description = self.Description 
     364        else :     
     365            self.Description = str(description) 
     366        self.parent.writePrinterDescription(self) 
    355367         
    356368    def delete(self) :     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1534 r1582  
    2222# 
    2323# $Log$ 
     24# Revision 1.71  2004/07/01 17:45:49  jalet 
     25# Added code to handle the description field for printers 
     26# 
    2427# Revision 1.70  2004/06/10 20:50:25  jalet 
    2528# Better log message 
     
    535538        """Extracts printer information given its name : returns first matching printer.""" 
    536539        printer = StoragePrinter(self, printername) 
    537         result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" % (printername, self.info["printerrdn"], printername), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "uniqueMember"], base=self.info["printerbase"]) 
     540        result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" % (printername, self.info["printerrdn"], printername), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "uniqueMember", "description"], base=self.info["printerbase"]) 
    538541        if result : 
    539542            fields = result[0][1]       # take only first matching printer, ignore the rest 
     
    543546            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    544547            printer.uniqueMember = fields.get("uniqueMember", []) 
     548            printer.Description = fields.get("description", [""])[0] 
    545549            printer.Exists = 1 
    546550        return printer     
     
    700704        printers = [] 
    701705        # see comment at the same place in pgstorage.py 
    702         result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)(%s=%s)" % (pname, self.info["printerrdn"], pname) for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "uniqueMember"], base=self.info["printerbase"]) 
     706        result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)(%s=%s)" % (pname, self.info["printerrdn"], pname) for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "uniqueMember", "description"], base=self.info["printerbase"]) 
    703707        if result : 
    704708            for (printerid, fields) in result : 
     
    709713                printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    710714                printer.uniqueMember = fields.get("uniqueMember", []) 
     715                printer.Description = fields.get("description", [""])[0] 
    711716                printer.Exists = 1 
    712717                printers.append(printer) 
     
    895900                   "pykotaPricePerPage" : str(printer.PricePerPage), 
    896901                   "pykotaPricePerJob" : str(printer.PricePerJob), 
     902                 } 
     903        self.doModify(printer.ident, fields) 
     904         
     905    def writePrinterDescription(self, printer) :     
     906        """Write the printer's description back into the storage.""" 
     907        fields = { 
     908                   "description" : str(printer.Description), 
    897909                 } 
    898910        self.doModify(printer.ident, fields) 
  • pykota/trunk/pykota/storages/sql.py

    r1531 r1582  
    2222# 
    2323# $Log$ 
     24# Revision 1.43  2004/07/01 17:45:49  jalet 
     25# Added code to handle the description field for printers 
     26# 
    2427# Revision 1.42  2004/06/08 17:44:43  jalet 
    2528# Payment now gets deleted when the user is deleted 
     
    115118            printer.ident = fields.get("id") 
    116119            printer.Name = fields.get("printername", printername) 
    117             printer.PricePerJob = fields.get("priceperjob") 
    118             printer.PricePerPage = fields.get("priceperpage") 
     120            printer.PricePerJob = fields.get("priceperjob") or 0.0 
     121            printer.PricePerPage = fields.get("priceperpage") or 0.0 
     122            printer.Description = fields.get("description") or "" 
    119123            printer.Exists = 1 
    120124        return printer     
     
    228232                    printer = StoragePrinter(self, record["printername"]) 
    229233                    printer.ident = record.get("id") 
    230                     printer.PricePerJob = record.get("priceperjob") 
    231                     printer.PricePerPage = record.get("priceperpage") 
     234                    printer.PricePerJob = record.get("priceperjob") or 0.0 
     235                    printer.PricePerPage = record.get("priceperpage") or 0.0 
     236                    printer.Description = record.get("description") or "" 
    232237                    printer.Exists = 1 
    233238                    printers.append(printer) 
     
    313318        self.doModify("UPDATE printers SET priceperpage=%s, priceperjob=%s WHERE id=%s" % (self.doQuote(printer.PricePerPage), self.doQuote(printer.PricePerJob), self.doQuote(printer.ident))) 
    314319         
     320    def writePrinterDescription(self, printer) :     
     321        """Write the printer's description back into the storage.""" 
     322        self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(printer.Description), self.doQuote(printer.ident))) 
     323         
    315324    def writeUserLimitBy(self, user, limitby) :     
    316325        """Sets the user's limiting factor.""" 
  • pykota/trunk/pykota/tool.py

    r1565 r1582  
    2222# 
    2323# $Log$ 
     24# Revision 1.109  2004/07/01 17:45:49  jalet 
     25# Added code to handle the description field for printers 
     26# 
    2427# Revision 1.108  2004/06/24 23:09:30  jalet 
    2528# Also prints read size on last block 
     
    475478        if self.debug : 
    476479            self.logger.log_message(message, "debug") 
     480             
     481    def printError(self, message) :         
     482        """Sends a message to standard error.""" 
     483        sys.stderr.write("%s\n" % message) 
     484        sys.stderr.flush() 
    477485         
    478486    def clean(self) :