root / pykota / trunk / bin / edpykota @ 1517

Revision 1517, 29.3 kB (checked in by jalet, 20 years ago)

Improved error logging.
crashrecipient directive added.
Now exports the job's size in bytes too.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3
4# PyKota Print Quota Editor
5#
6# PyKota - Print Quotas for CUPS and LPRng
7#
8# (c) 2003-2004 Jerome Alet <alet@librelogiciel.com>
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22#
23# $Id$
24#
25# $Log$
26# Revision 1.73  2004/06/03 21:50:34  jalet
27# Improved error logging.
28# crashrecipient directive added.
29# Now exports the job's size in bytes too.
30#
31# Revision 1.72  2004/04/16 16:20:19  jalet
32# Note about not implemented limitby values
33#
34# Revision 1.71  2004/03/24 15:15:24  jalet
35# Began integration of Henrik Janhagen's work on quota-then-balance
36# and balance-then-quota
37#
38# Revision 1.70  2004/02/27 09:23:21  jalet
39# Minor code reorganisation
40#
41# Revision 1.69  2004/02/19 15:05:56  jalet
42# domain names changed to example.com in the doc, according to RFC2606
43#
44# Revision 1.68  2004/01/28 10:05:22  jalet
45# New user/group deletion code
46#
47# Revision 1.67  2004/01/15 11:19:07  jalet
48# Typos in messages wrt gettext.
49#
50# Revision 1.66  2004/01/12 21:54:36  jalet
51# User's email address can now be set at user's creation time.
52#
53# Revision 1.65  2004/01/08 16:24:49  jalet
54# edpykota now supports adding printers to printer groups.
55#
56# Revision 1.64  2004/01/08 14:10:32  jalet
57# Copyright year changed.
58#
59# Revision 1.63  2003/11/24 16:50:58  jalet
60# Old help message deletedd
61#
62# Revision 1.62  2003/11/12 23:28:38  jalet
63# More work on new backend. This commit may be unstable.
64#
65# Revision 1.61  2003/11/12 13:06:35  jalet
66# Bug fix wrt no user/group name command line argument to edpykota
67#
68# Revision 1.60  2003/10/09 21:25:24  jalet
69# Multiple printer names or wildcards can be passed on the command line
70# separated with commas.
71# Beta phase.
72#
73# Revision 1.59  2003/10/07 09:07:27  jalet
74# Character encoding added to please latest version of Python
75#
76# Revision 1.58  2003/10/03 12:27:01  jalet
77# Several optimizations, especially with LDAP backend
78#
79# Revision 1.57  2003/08/20 16:01:19  jalet
80# Comment added.
81#
82# Revision 1.56  2003/07/29 20:55:17  jalet
83# 1.14 is out !
84#
85# Revision 1.55  2003/07/28 09:11:12  jalet
86# PyKota now tries to add its attributes intelligently in existing LDAP
87# directories.
88#
89# Revision 1.54  2003/07/21 06:32:42  jalet
90# Prevents email messages to be sent at modification/creation time for
91# a user/group quota
92#
93# Revision 1.53  2003/07/09 06:03:41  jalet
94# Fixed typo when using edpykota --prototype
95#
96# Revision 1.52  2003/07/07 12:11:13  jalet
97# Small fix
98#
99# Revision 1.51  2003/07/07 11:55:50  jalet
100# Small fix
101#
102# Revision 1.50  2003/07/05 12:33:53  jalet
103# More on previous fix.
104#
105# Revision 1.49  2003/07/05 12:32:07  jalet
106# Ensure that the user don't pass more than two prices for a printer.
107#
108# Revision 1.48  2003/06/25 19:52:30  jalet
109# Should be ready for testing :-)
110#
111# Revision 1.47  2003/06/25 14:10:01  jalet
112# Hey, it may work (edpykota --reset excepted) !
113#
114# Revision 1.46  2003/06/16 11:59:09  jalet
115# More work on LDAP
116#
117# Revision 1.45  2003/06/11 19:32:00  jalet
118# Severe bug wrt account balance setting should be corrected.
119#
120# Revision 1.44  2003/04/29 22:03:38  jalet
121# Better error handling.
122#
123# Revision 1.43  2003/04/23 22:13:56  jalet
124# Preliminary support for LPRng added BUT STILL UNTESTED.
125#
126# Revision 1.42  2003/04/17 13:38:47  jalet
127# Docstring corrected for better manual page
128#
129# Revision 1.41  2003/04/16 12:35:49  jalet
130# Groups quota work now !
131#
132# Revision 1.40  2003/04/16 08:22:09  jalet
133# More strict error detection.
134# Minor code rewrite to avoid some repetitive tests.
135#
136# Revision 1.39  2003/04/16 08:01:53  jalet
137# edpykota --charge command line option works now.
138#
139# Revision 1.38  2003/04/15 22:02:43  jalet
140# More complete docstring
141#
142# Revision 1.37  2003/04/15 21:58:33  jalet
143# edpykota now accepts a --delete option.
144# Preparation to allow edpykota to accept much more command line options
145# (WARNING : docstring is OK, but code isn't !)
146#
147# Revision 1.36  2003/04/15 13:55:28  jalet
148# Options --limitby and --balance added to edpykota
149#
150# Revision 1.35  2003/04/15 13:06:39  jalet
151# Allow to add a printer without any user
152#
153# Revision 1.34  2003/04/11 16:51:11  jalet
154# Bug fix for edpykota --add with users who already had a quota on the printer.
155#
156# Revision 1.33  2003/04/10 21:47:20  jalet
157# Job history added. Upgrade script neutralized for now !
158#
159# Revision 1.32  2003/04/08 21:31:39  jalet
160# (anything or 0) = anything !!! Go back to school Jerome !
161#
162# Revision 1.31  2003/04/08 21:13:44  jalet
163# Prepare --groups option to work.
164#
165# Revision 1.30  2003/04/08 21:10:18  jalet
166# Checks --groups option presence instead of --users because --users is the default.
167#
168# Revision 1.29  2003/04/05 09:28:56  jalet
169# Unnecessary message was logged
170#
171# Revision 1.28  2003/03/29 13:45:26  jalet
172# GPL paragraphs were incorrectly (from memory) copied into the sources.
173# Two README files were added.
174# Upgrade script for PostgreSQL pre 1.01 schema was added.
175#
176# Revision 1.27  2003/03/10 00:23:04  jalet
177# Bad english
178#
179# Revision 1.26  2003/03/10 00:11:27  jalet
180# Cleaner example.
181#
182# Revision 1.25  2003/03/09 23:56:21  jalet
183# Option noquota added to do accounting only.
184#
185# Revision 1.24  2003/02/27 23:48:41  jalet
186# Correctly maps PyKota's log levels to syslog log levels
187#
188# Revision 1.23  2003/02/27 22:55:20  jalet
189# WARN log priority doesn't exist.
190#
191# Revision 1.22  2003/02/27 09:37:02  jalet
192# Wildcards seem to work now
193#
194# Revision 1.21  2003/02/27 09:04:46  jalet
195# user and group names can be passed as wildcards if the --add option
196# is not set. The default is to act on all users or groups.
197#
198# Revision 1.20  2003/02/10 12:07:30  jalet
199# Now repykota should output the recorded total page number for each printer too.
200#
201# Revision 1.19  2003/02/09 13:40:29  jalet
202# typo
203#
204# Revision 1.18  2003/02/09 12:56:53  jalet
205# Internationalization begins...
206#
207# Revision 1.17  2003/02/08 22:47:23  jalet
208# Option --reset can now be used without having to use soft and hard limits
209# on the command line.
210#
211# Revision 1.16  2003/02/08 22:39:46  jalet
212# --reset command line option added
213#
214# Revision 1.15  2003/02/08 22:20:01  jalet
215# Clarification on why we don't check with /etc/passwd to see if the user
216# name is valid or not.
217#
218# Revision 1.14  2003/02/08 22:18:15  jalet
219# Now checks user and group names for validity before adding them
220#
221# Revision 1.13  2003/02/08 22:09:02  jalet
222# Only printer was added the first time.
223#
224# Revision 1.12  2003/02/08 21:44:49  jalet
225# Python 2.1 string module doesn't define ascii_letters
226#
227# Revision 1.11  2003/02/08 09:42:44  jalet
228# Better handle wrong or bad command line arguments
229#
230# Revision 1.10  2003/02/08 09:39:20  jalet
231# typos
232#
233# Revision 1.9  2003/02/08 09:38:06  jalet
234# Badly placed test
235#
236# Revision 1.8  2003/02/07 22:53:57  jalet
237# Checks if printer name is valid before adding it
238#
239# Revision 1.7  2003/02/07 22:17:58  jalet
240# Incomplete test
241#
242# Revision 1.6  2003/02/07 22:13:13  jalet
243# Perhaps edpykota is now able to add printers !!! Oh, stupid me !
244#
245# Revision 1.5  2003/02/06 14:49:04  jalet
246# edpykota should be ok now
247#
248# Revision 1.4  2003/02/06 14:28:59  jalet
249# edpykota should be ok, minus some typos
250#
251# Revision 1.3  2003/02/06 10:47:21  jalet
252# Documentation string and command line options didn't match.
253#
254# Revision 1.2  2003/02/06 10:39:23  jalet
255# Preliminary edpykota work.
256#
257# Revision 1.1  2003/02/05 21:41:09  jalet
258# Skeletons added for all command line tools
259#
260#
261#
262
263import sys
264
265from pykota import version
266from pykota.tool import PyKotaTool, PyKotaToolError
267from pykota.config import PyKotaConfigError
268from pykota.storage import PyKotaStorageError
269
270__doc__ = """edpykota v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
271A Print Quota editor for PyKota.
272
273command line usage :
274
275  edpykota [options] user1 user2 ... userN
276 
277  edpykota [options] group1 group2 ... groupN
278
279options :
280
281  -v | --version       Prints edpykota's version number then exits.
282  -h | --help          Prints this message then exits.
283 
284  -a | --add           Adds users and/or printers if they don't
285                       exist on the Quota Storage Server.
286                       
287  -d | --delete        Deletes users/groups from the quota storage.
288                       Printers are never deleted.
289                       
290  -c | --charge p[,j]  Sets the price per page and per job to charge
291                       for a particular printer. Job price is optional.
292                       If both are to be set, separate them with a comma.
293                       Floating point values are allowed.
294 
295  -i | --ingroups g1[,g2...]  Puts the users into each of the groups
296                              listed, separated by commas. The groups
297                              must already exist in the Quota Storage.
298 
299  -u | --users         Edit users print quotas, this is the default.
300 
301  -P | --printer p     Edit quotas on printer p only. Actually p can
302                       use wildcards characters to select only
303                       some printers. The default value is *, meaning
304                       all printers.
305                       You can specify several names or wildcards,
306                       by separating them with commas.
307 
308  -G | --pgroups pg1[,pg2...] Adds the printer(s) to the printer groups
309                       pg1, pg2, etc... which must already exist.
310                       A printer group is just like a normal printer,
311                       only that it is usually unknown from the printing
312                       system. Create printer groups exactly the same
313                       way that you create printers, then add other
314                       printers to them with this option.
315                       Accounting is done on a printer and on all
316                       the printer groups it belongs to, quota checking
317                       is done on a printer and on all the printer groups
318                       it belongs to.
319 
320  -g | --groups        Edit users groups print quotas instead of users.
321                         
322  -p | --prototype u|g Uses user u or group g as a prototype to set
323                       print quotas
324                       
325  -n | --noquota       Doesn't set a quota but only does accounting.
326 
327  -r | --reset         Resets the printed page counter for the user
328                       or group to zero. The life time page counter
329                       is kept unchanged.
330                       
331  -l | --limitby l     Choose if the user/group is limited in printing                     
332                       by its account balance or by its page quota.
333                       The default value is 'quota'. Allowed values
334                       are 'quota' 'balance' 'quota-then-balance' and
335                       'balance-then-quota'.
336                       WARNING : quota-then-balance and balance-then-quota
337                       are not yet implemented.
338                       
339  -b | --balance b     Sets the user's account balance to b.                     
340                       Account balance may be increase or decreased
341                       if b is prefixed with + or -.
342                       WARNING : when decreasing account balance,
343                       the total paid so far by the user is decreased
344                       too.
345                       Groups don't have a real balance, but the
346                       sum of their users' account balance.
347                       
348  -S | --softlimit sl  Sets the quota soft limit to sl pages.                       
349 
350  -H | --hardlimit hl  Sets the quota hard limit to hl pages.
351 
352  user1 through userN and group1 through groupN can use wildcards
353  if the --add option is not set.
354 
355examples :                             
356
357  $ edpykota --add -p jerome john paul george ringo/ringo@example.com
358 
359  This will add users john, paul, george and ringo to the quota
360  database, and set their print quotas to the same values than user
361  jerome. User jerome must already exist.
362  User ringo's email address will also be set to 'ringo@example.com'
363 
364  $ edpykota --printer lp -S 50 -H 60 jerome
365 
366  This will set jerome's print quota on the lp printer to a soft limit
367  of 50 pages, and a hard limit of 60 pages. If either user jerome or
368  printer lp doesn't exist on the Quota Storage Server then nothing is done.
369
370  $ edpykota --add --printer lp --ingroups coders,it -S 50 -H 60 jerome
371 
372  Same as above, but if either user jerome or printer lp doesn't exist
373  on the Quota Storage Server they are automatically added. Also
374  user jerome is put into the groups "coders" and "it" which must
375  already exist in the Quota Storage.
376           
377  $ edpykota -g -S 500 -H 550 financial support           
378 
379  This will set print quota soft limit to 500 pages and hard limit
380  to 550 pages for groups financial and support on all printers.
381 
382  $ edpykota --reset jerome "jo*"
383 
384  This will reset jerome's page counter to zero on all printers, as
385  well as every user whose name begins with 'jo'.
386  Their life time page counter on each printer will be kept unchanged.
387 
388  $ edpykota --printer hpcolor --noquota jerome
389 
390  This will tell PyKota to not limit jerome when printing on the
391  hpcolor printer. All his jobs will be allowed on this printer, but
392  accounting of the pages he prints will still be kept.
393  Print Quotas for jerome on other printers are unchanged.
394 
395  $ edpykota --limitby balance jerome
396 
397  This will tell PyKota to limit jerome by his account's balance
398  when printing.
399 
400  $ edpykota --balance +10.0 jerome
401 
402  This will increase jerome's account balance by 10.0 (in your
403  own currency). You can decrease the account balance with a
404  dash prefix, and set it to a fixed amount with no prefix.
405 
406  $ edpykota --delete jerome rachel
407 
408  This will completely delete jerome and rachel from the Quota Storage
409  database. All their quotas and jobs will be deleted too.
410 
411  $ edpykota --printer lp --charge 0.1
412 
413  This will set the page price for printer lp to 0.1. Job price
414  will not be changed.
415 
416  $ edpykota --printer hplj1,hplj2 --pgroups Laser,HP
417 
418  This will put printers hplj1 and hplj2 in printers groups Laser and HP.
419  When printing either on hplj1 or hplj2, print quota will also be
420  checked and accounted for on virtual printers Laser and HP.
421
422This program is free software; you can redistribute it and/or modify
423it under the terms of the GNU General Public License as published by
424the Free Software Foundation; either version 2 of the License, or
425(at your option) any later version.
426
427This program is distributed in the hope that it will be useful,
428but WITHOUT ANY WARRANTY; without even the implied warranty of
429MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
430GNU General Public License for more details.
431
432You should have received a copy of the GNU General Public License
433along with this program; if not, write to the Free Software
434Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
435
436Please e-mail bugs to: %s""" % (version.__version__, version.__author__)
437       
438class EdPyKota(PyKotaTool) :       
439    """A class for edpykota."""
440    def main(self, names, options) :
441        """Edit user or group quotas."""
442       
443        suffix = (options["groups"] and "Group") or "User"       
444       
445        softlimit = hardlimit = None   
446        if not options["noquota"] :
447            if options["softlimit"] :
448                try :
449                    softlimit = int(options["softlimit"].strip())
450                except ValueError :   
451                    raise PyKotaToolError, _("Invalid softlimit value %s.") % options["softlimit"]
452            if options["hardlimit"] :
453                try :
454                    hardlimit = int(options["hardlimit"].strip())
455                except ValueError :   
456                    raise PyKotaToolError, _("Invalid hardlimit value %s.") % options["hardlimit"]
457            if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) :       
458                # error, exchange them
459                self.logger.log_message(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit))
460                (softlimit, hardlimit) = (hardlimit, softlimit)
461           
462        balance = options["balance"]
463        if balance :
464            balance = balance.strip()
465            try :
466                balancevalue = float(balance)
467            except ValueError :   
468                raise PyKotaToolError, _("Invalid balance value %s") % options["balance"]
469           
470        if options["charge"] :
471            try :
472                charges = [float(part) for part in options["charge"].split(',', 1)]
473            except ValueError :   
474                raise PyKotaToolError, _("Invalid charge amount value %s") % options["charge"]
475            else :   
476                if len(charges) > 2 :
477                    charges = charges[:2]
478                if len(charges) != 2 :
479                    charges = [charges[0], None]
480                   
481        limitby = options["limitby"]
482        if limitby :
483            limitby = limitby.strip().lower()
484        if limitby and (limitby not in ('quota', 'balance', 'quota-then-balance', 'balance-then-quota')) :   
485            raise PyKotaToolError, _("Invalid limitby value %s") % options["limitby"]
486           
487        if options["ingroups"] :   
488            groupnames = [gname.strip() for gname in options["ingroups"].split(',')]
489        else :   
490            groupnames = []
491           
492        if options["prototype"] :   
493            protoentry = getattr(self.storage, "get%s" % suffix)(options["prototype"])
494           
495        printeradded = 0
496        printers = self.storage.getMatchingPrinters(options["printer"])
497        if not printers :
498            pname = options["printer"]
499            if options["add"] and pname :
500                if self.isValidName(pname) :
501                    printers = [ self.storage.addPrinter(pname) ]
502                    if printers[0].Exists :
503                        printeradded = 1
504                    else :   
505                        raise PyKotaToolError, _("Impossible to add printer %s") % pname
506                else :   
507                    raise PyKotaToolError, _("Invalid printer name %s") % pname
508            else :
509                raise PyKotaToolError, _("There's no printer matching %s") % pname
510        if not names :   
511            if options["add"] :
512                if not printeradded :
513                    raise PyKotaToolError, _("You have to pass user or group names on the command line")
514                else :   
515                    names = getattr(self.storage, "getAll%ssNames" % suffix)()
516            else :   
517                names = [ "*" ] # all users
518               
519        printersgroups = []       
520        if options["pgroups"] :       
521            printersgroups = self.storage.getMatchingPrinters(options["pgroups"])
522           
523        todelete = {}   
524        changed = {} # tracks changes made at the user/group level
525        for printer in printers :
526            for pgroup in printersgroups :
527                pgroup.addPrinterToGroup(printer)   
528               
529            if options["charge"] :
530                (perpage, perjob) = charges
531                printer.setPrices(perpage, perjob)   
532               
533            if options["prototype"] :
534                if protoentry.Exists :
535                    protoquota = getattr(self.storage, "get%sPQuota" % suffix)(protoentry, printer)
536                    if not protoquota.Exists :
537                        self.logger.log_message(_("Prototype %s not found in Quota Storage for printer %s.") % (protoentry.Name, printer.Name))
538                        continue    # skip this printer
539                    else :   
540                        (softlimit, hardlimit) = (protoquota.SoftLimit, protoquota.HardLimit)
541                else :       
542                    self.logger.log_message(_("Prototype object %s not found in Quota Storage.") % protoentry.Name)
543                   
544            if not options["noquota"] :   
545                if hardlimit is None :   
546                    hardlimit = softlimit
547                    if hardlimit is not None :
548                        self.logger.log_message(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name))
549                if softlimit is None :   
550                    softlimit = hardlimit
551                    if softlimit is not None :
552                        self.logger.log_message(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name))
553                       
554            if options["add"] :   
555                allentries = []   
556                for name in names :
557                    email = ""
558                    if not options["groups"] :
559                        splitname = name.split('/', 1)     # username/email
560                        if len(splitname) == 1 :
561                            splitname.append("")
562                        (name, email) = splitname
563                        if email and (email.count('@') != 1) :
564                            self.logger.log_message(_("Invalid email address %s") % email)
565                            email = ""
566                    entry = getattr(self.storage, "get%s" % suffix)(name)
567                    if email and not options["groups"] :
568                        entry.Email = email
569                    entrypquota = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer)
570                    allentries.append((entry, entrypquota))
571            else :   
572                allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names)
573               
574            for (entry, entrypquota) in allentries :
575                if not changed.has_key(entry.Name) :
576                    changed[entry.Name] = {}
577                    if not options["groups"] :
578                        changed[entry.Name]["ingroups"] = []
579                       
580                if not entry.Exists :       
581                    # not found
582                    if options["add"] :
583                        # In case we want to add something, it is crucial
584                        # that we DON'T check with the system accounts files
585                        # like /etc/passwd because users may be defined
586                        # only remotely
587                        if self.isValidName(entry.Name) :
588                            entry = getattr(self.storage, "add%s" % suffix)(entry)
589                        else :   
590                            if options["groups"] :
591                                self.logger.log_message(_("Invalid group name %s") % entry.Name)
592                            else :   
593                                self.logger.log_message(_("Invalid user name %s") % entry.Name)
594                elif options["delete"] :               
595                    todelete[entry.Name] = entry
596                               
597                if entry.Exists and (not entrypquota.Exists) :
598                    # not found
599                    if options["add"] :
600                        entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer)
601                       
602                if not entrypquota.Exists :     
603                    self.logger.log_message(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name))
604                else :   
605                    if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) :
606                        entrypquota.setLimits(softlimit, hardlimit)
607                    if limitby :
608                        if changed[entry.Name].get("limitby") is None :
609                            entry.setLimitBy(limitby)
610                            changed[entry.Name]["limitby"] = limitby
611                   
612                    if not options["groups"] :
613                        if options["reset"] :
614                            entrypquota.reset()
615                           
616                        if balance :
617                            if changed[entry.Name].get("balance") is None :
618                                if balance.startswith("+") or balance.startswith("-") :
619                                    newbalance = float(entry.AccountBalance or 0.0) + balancevalue
620                                    newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue
621                                    entry.setAccountBalance(newbalance, newlifetimepaid)
622                                else :
623                                    diff = balancevalue - float(entry.AccountBalance or 0.0)
624                                    newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff
625                                    entry.setAccountBalance(balancevalue, newlifetimepaid)
626                                changed[entry.Name]["balance"] = balance
627                               
628                        for groupname in groupnames :       
629                            # not executed if option --ingroups is not used
630                            if groupname not in changed[entry.Name]["ingroups"] :
631                                group = self.storage.getGroup(groupname)
632                                if group.Exists :
633                                    self.storage.addUserToGroup(entry, group)
634                                    changed[entry.Name]["ingroups"].append(groupname)
635                                else :
636                                    self.logger.log_message(_("Group %s not found in the PyKota Storage.") % groupname)
637                                   
638                    # This line disabled to prevent sending of unwanted email                 
639                    # messages if quota is reached at creation/modification time.
640                    # The check will be done at print time anyway.
641                    # getattr(self, "warn%sPQuota" % suffix)(entrypquota)   
642                       
643        # Now delete what has to be deleted               
644        for (name, entry) in todelete.items() :               
645            entry.delete()
646                     
647if __name__ == "__main__" : 
648    retcode = 0
649    try :
650        defaults = { \
651                     "printer" : "*", \
652                   }
653        short_options = "vhdc:l:b:i:naugrp:P:S:H:G:"
654        long_options = ["help", "version", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "prototype=", "printer=", "softlimit=", "hardlimit=", "pgroups="]
655       
656        # Initializes the command line tool
657        editor = EdPyKota(doc=__doc__)
658       
659        # parse and checks the command line
660        (options, args) = editor.parseCommandline(sys.argv[1:], short_options, long_options)
661       
662        # sets long options
663        options["help"] = options["h"] or options["help"]
664        options["version"] = options["v"] or options["version"]
665        options["add"] = options["a"] or options["add"]
666        options["users"] = options["u"] or options["users"]
667        options["groups"] = options["g"] or options["groups"]
668        options["prototype"] = options["p"] or options["prototype"]
669        options["printer"] = options["P"] or options["printer"] or defaults["printer"]
670        options["softlimit"] = options["S"] or options["softlimit"]
671        options["hardlimit"] = options["H"] or options["hardlimit"] 
672        options["reset"] = options["r"] or options["reset"] 
673        options["noquota"] = options["n"] or options["noquota"]
674        options["limitby"] = options["l"] or options["limitby"]
675        options["balance"] = options["b"] or options["balance"] 
676        options["delete"] = options["d"] or options["delete"] 
677        options["ingroups"] = options["i"] or options["ingroups"]
678        options["charge"] = options["c"] or options["charge"]
679        options["pgroups"] = options["G"] or options["pgroups"]
680       
681        if options["help"] :
682            editor.display_usage_and_quit()
683        elif options["version"] :
684            editor.display_version_and_quit()
685        elif options["users"] and options["groups"] :   
686            raise PyKotaToolError, _("incompatible options, see help.")
687        elif (options["add"] or options["prototype"]) and options["delete"] :   
688            raise PyKotaToolError, _("incompatible options, see help.")
689        elif (options["softlimit"] or options["hardlimit"]) and options["prototype"] :   
690            raise PyKotaToolError, _("incompatible options, see help.")
691        elif options["noquota"] and (options["prototype"] or options["hardlimit"] or options["softlimit"]) :
692            raise PyKotaToolError, _("incompatible options, see help.")
693        elif options["groups"] and (options["balance"] or options["ingroups"]) :
694            raise PyKotaToolError, _("incompatible options, see help.")
695        else :
696            retcode = editor.main(args, options)
697    except :
698        try :
699            editor.crashed("edpykota failed")
700        except :   
701            pass
702        retcode = -1
703
704    try :
705        editor.storage.close()
706    except (TypeError, NameError, AttributeError) :   
707        pass
708       
709    sys.exit(retcode)   
Note: See TracBrowser for help on using the browser.