Show
Ignore:
Timestamp:
02/06/03 11:39:23 (21 years ago)
Author:
jalet
Message:

Preliminary edpykota work.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r696 r715  
    1717# 
    1818# $Log$ 
     19# Revision 1.2  2003/02/06 10:39:23  jalet 
     20# Preliminary edpykota work. 
     21# 
    1922# Revision 1.1  2003/02/05 21:41:09  jalet 
    2023# Skeletons added for all command line tools 
     
    2326# 
    2427 
     28import sys 
     29 
     30from pykota import version 
     31from pykota.tool import PyKotaTool, PyKotaToolError 
     32 
     33__doc__ = """edpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres 
     34A Print Quota editor for PyKota. 
     35 
     36command line usage : 
     37 
     38  edpykota [-u] [-p username] [-f printername] username ... 
     39  edpykota -g [-p groupname] [-f printername] groupname ... 
     40 
     41options : 
     42 
     43  -v | --version       Prints edpykota's version number then exits. 
     44  -h | --help          Prints this message then exits. 
     45   
     46  -a | --add           Adds users and/or printers if they don't  
     47                       exist on the Quota Storage Server. 
     48                        
     49  -u | --users         Edit users print quotas, this is the default. 
     50   
     51  -P | --printer p     Edit quotas on printer p only. 
     52   
     53  -g | --groups        Edit groups print quotas instead of users. 
     54                           
     55  -p | --prototype u|g Uses user u or group g as a prototype to set 
     56                       print quotas 
     57                        
     58  -S | --softlimit sl  Sets the quota soft limit to sl pages.                        
     59   
     60  -H | --hardlimit hl  Sets the quota hard limit to hl pages. 
     61   
     62examples :                               
     63 
     64  $ edpykota -p jerome john paul george ringo 
     65   
     66  This will set print quotas for the users john, paul, george and ringo 
     67  to the same values than user jerome. User jerome must exist. 
     68   
     69  $ edpykota --printer lp -S 50 -H 60 jerome 
     70   
     71  This will set jerome's print quota on the lp printer to a soft limit 
     72  of 50 pages, and a hard limit of 60 pages. If either user jerome or 
     73  printer lp doesn't exist on the Quota Storage Server then nothing is done. 
     74 
     75  $ edpykota --add --printer lp -S 50 -H 60 jerome 
     76   
     77  Same as above, but if either user jerome or printer lp doesn't exist  
     78  on the Quota Storage Server they are automatically added.  
     79  WARNING : the CUPS PPD file for this printer must still be modified 
     80            manually, as well as pykota's configuration file for a 
     81            new printer to be managed successfully. 
     82             
     83  $ edpykota -g -S 500 -H 550 financial support             
     84   
     85  This will set print quota soft limit to 500 pages and hard limit 
     86  to 550 pages for groups financial and support on all printers. 
     87 
     88This program is free software; you can redistribute it and/or modify 
     89it under the terms of the GNU General Public License as published by 
     90the Free Software Foundation; either version 2 of the License, or 
     91(at your option) any later version. 
     92 
     93This program is distributed in the hope that it will be useful, 
     94but WITHOUT ANY WARRANTY; without even the implied warranty of 
     95MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     96GNU General Public License for more details. 
     97 
     98You should have received a copy of the GNU General Public License 
     99along with this program; if not, write to the Free Software 
     100Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
     101 
     102Please e-mail bugs to: %s""" % (version.__version__, version.__author__) 
     103         
     104def main(arguments, options) : 
     105    """Edit user or group quotas.""" 
     106    pass 
     107     
     108if __name__ == "__main__" :  
     109    try : 
     110        tool = PyKotaTool(doc=__doc__) 
     111         
     112        defaults = { \ 
     113                     "users"  : 1, \ 
     114                     "groups" : 0, \ 
     115                   } 
     116        short_options = "vhaugp:P:S:H:" 
     117        long_options = ["help", "version", "add", "users", "groups", "prototype=", "printer=", "softlimit=", "hardlimit="] 
     118         
     119        # Initializes the command line tool 
     120        tool = PyKotaTool(doc=__doc__) 
     121         
     122        # parse and checks the command line 
     123        (options, args) = tool.parseCommandline(sys.argv[1:], short_options, long_options) 
     124         
     125        # sets long options 
     126        options["help"] = options["h"] or options["help"] 
     127        options["version"] = options["v"] or options["version"] 
     128        options["add"] = options["a"] or options["add"] 
     129        options["users"] = options["u"] or options["users"] or defaults["users"] 
     130        options["groups"] = options["g"] or options["groups"] or defaults["groups"] 
     131        options["prototype"] = options["p"] or options["prototype"] 
     132        options["printer"] = options["P"] or options["printer"] 
     133        options["softlimit"] = options["S"] or options["softlimit"] 
     134        options["hardlimit"] = options["H"] or options["hardlimit"]  
     135         
     136        if options["help"] : 
     137            tool.display_usage_and_quit() 
     138        elif options["version"] : 
     139            tool.display_version_and_quit() 
     140        elif options["users"] and options["groups"] :     
     141            raise PyKotaToolError, "edpykota: options --users and --groups are incompatible.\n" 
     142        elif options["groups"] : # TODO : add support for group quotas     
     143            raise PyKotaToolError, "edpykota: group quotas are currently not implemented, sorry.\n" 
     144        else : 
     145            apply(main, args, options) 
     146    except PyKotaToolError, msg :             
     147        sys.stderr.write("%s\n" % msg) 
     148        sys.stderr.flush() 
     149        sys.exit(-1) 
     150