Changeset 729 for pykota/trunk

Show
Ignore:
Timestamp:
02/07/03 00:20:03 (22 years ago)
Author:
jalet
Message:

warnpykota doesn't need any user/group name argument, mimicing the
warnquota disk quota tool.

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/warnpykota

    r728 r729  
    1717# 
    1818# $Log$ 
     19# Revision 1.3  2003/02/06 23:20:02  jalet 
     20# warnpykota doesn't need any user/group name argument, mimicing the 
     21# warnquota disk quota tool. 
     22# 
    1923# Revision 1.2  2003/02/06 22:54:33  jalet 
    2024# warnpykota should be ok 
     
    3337command line usage : 
    3438 
    35   warnpykota [options] user1 user2 ... userN 
    36   warnpykota [options] group1 group2 ... groupN 
     39  warnpykota [options]  
    3740 
    3841options : 
     
    8689class WarnPyKota(PyKotaTool) :         
    8790    """A class for warnpykota.""" 
    88     def main(self, names, options) : 
     91    def main(self, options) : 
    8992        """Warn users or groups over print quota.""" 
     93         
    9094        printernames = self.storage.getMatchingPrinters(options["printer"]) 
    9195        if not printernames : 
    9296            raise PyKotaToolError, "There's no printer matching %s" % options["printer"] 
    9397        for printer in printernames : 
    94             for name in names : 
    95                 if options["users"] : 
     98            if options["users"] : 
     99                for name in self.storage.getPrinterUsers(printer) : 
    96100                    self.warnUserPQuota(name, printer) 
    97                 else : 
     101            else : 
     102                for name in self.storage.getPrinterGroups(printer) : 
    98103                    self.warnGroupPQuota(name, printer) 
    99104                      
     
    112117         
    113118        # parse and checks the command line 
    114         (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options) 
     119        (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) 
    115120         
    116121        # sets long options 
     
    129134        elif options["groups"] :     
    130135            raise PyKotaToolError, "warnpykota: options --groups is currently not implemented." 
     136        elif args :     
     137            raise PyKotaToolError, "warnpykota: unused arguments [%s]. Aborting." % ", ".join(args) 
    131138        else : 
    132             sys.exit(sender.main(args, options)) 
     139            sys.exit(sender.main(options)) 
    133140    except PyKotaToolError, msg :             
    134141        sys.stderr.write("%s\n" % msg) 
  • pykota/trunk/pykota/storages/sql.py

    r723 r729  
    1515# 
    1616# $Log$ 
     17# Revision 1.12  2003/02/06 23:20:03  jalet 
     18# warnpykota doesn't need any user/group name argument, mimicing the 
     19# warnquota disk quota tool. 
     20# 
    1721# Revision 1.11  2003/02/06 15:05:13  jalet 
    1822# self was forgotten 
     
    7175        return printerslist         
    7276             
     77    def getPrinterUsers(self, printername) :         
     78        """Returns the list of usernames which uses a given printer.""" 
     79        result = self.doQuery("SELECT DISTINCT username FROM users WHERE id IN (SELECT userid FROM userpquota WHERE printerid IN (SELECT printerid FROM printers WHERE printername=%s));" % self.doQuote(printername)) 
     80        result = result.doParseResult(result) 
     81        if result is None : 
     82            return [] 
     83        else :     
     84            return [record["username"] for record in result] 
     85         
     86    def getPrinterGroups(self, printername) :         
     87        """Returns the list of groups which uses a given printer.""" 
     88        result = self.doQuery("SELECT DISTINCT groupname FROM groups WHERE id IN (SELECT groupid FROM grouppquota WHERE printerid IN (SELECT printerid FROM printers WHERE printername=%s));" % self.doQuote(printername)) 
     89        result = result.doParseResult(result) 
     90        if result is None : 
     91            return [] 
     92        else :     
     93            return [record["groupname"] for record in result] 
     94         
    7395    def getUserId(self, username) : 
    7496        """Returns a userid given a username.""" 
  • pykota/trunk/pykota/tool.py

    r728 r729  
    1515# 
    1616# $Log$ 
     17# Revision 1.12  2003/02/06 23:20:02  jalet 
     18# warnpykota doesn't need any user/group name argument, mimicing the 
     19# warnquota disk quota tool. 
     20# 
    1721# Revision 1.11  2003/02/06 22:54:33  jalet 
    1822# warnpykota should be ok 
     
    9498        sys.exit(0) 
    9599         
    96     def parseCommandline(self, argv, short, long) : 
     100    def parseCommandline(self, argv, short, long, allownothing=0) : 
    97101        """Parses the command line, controlling options.""" 
    98102        # split options in two lists: those which need an argument, those which don't need any 
     
    146150                        # should never occur 
    147151                        raise PyKotaToolError, "Unexpected problem when parsing command line" 
    148             elif (not args) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty 
     152            elif (not args) and (not allownothing) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty 
    149153                self.display_usage_and_quit() 
    150154        except getopt.error, msg :