Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 728)
+++ /pykota/trunk/pykota/tool.py (revision 729)
@@ -15,4 +15,8 @@
 #
 # $Log$
+# Revision 1.12  2003/02/06 23:20:02  jalet
+# warnpykota doesn't need any user/group name argument, mimicing the
+# warnquota disk quota tool.
+#
 # Revision 1.11  2003/02/06 22:54:33  jalet
 # warnpykota should be ok
@@ -94,5 +98,5 @@
         sys.exit(0)
         
-    def parseCommandline(self, argv, short, long) :
+    def parseCommandline(self, argv, short, long, allownothing=0) :
         """Parses the command line, controlling options."""
         # split options in two lists: those which need an argument, those which don't need any
@@ -146,5 +150,5 @@
                         # should never occur
                         raise PyKotaToolError, "Unexpected problem when parsing command line"
-            elif (not args) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty
+            elif (not args) and (not allownothing) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty
                 self.display_usage_and_quit()
         except getopt.error, msg :
Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 723)
+++ /pykota/trunk/pykota/storages/sql.py (revision 729)
@@ -15,4 +15,8 @@
 #
 # $Log$
+# Revision 1.12  2003/02/06 23:20:03  jalet
+# warnpykota doesn't need any user/group name argument, mimicing the
+# warnquota disk quota tool.
+#
 # Revision 1.11  2003/02/06 15:05:13  jalet
 # self was forgotten
@@ -71,4 +75,22 @@
         return printerslist        
             
+    def getPrinterUsers(self, printername) :        
+        """Returns the list of usernames which uses a given printer."""
+        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))
+        result = result.doParseResult(result)
+        if result is None :
+            return []
+        else :    
+            return [record["username"] for record in result]
+        
+    def getPrinterGroups(self, printername) :        
+        """Returns the list of groups which uses a given printer."""
+        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))
+        result = result.doParseResult(result)
+        if result is None :
+            return []
+        else :    
+            return [record["groupname"] for record in result]
+        
     def getUserId(self, username) :
         """Returns a userid given a username."""
Index: /pykota/trunk/bin/warnpykota
===================================================================
--- /pykota/trunk/bin/warnpykota (revision 728)
+++ /pykota/trunk/bin/warnpykota (revision 729)
@@ -17,4 +17,8 @@
 #
 # $Log$
+# Revision 1.3  2003/02/06 23:20:02  jalet
+# warnpykota doesn't need any user/group name argument, mimicing the
+# warnquota disk quota tool.
+#
 # Revision 1.2  2003/02/06 22:54:33  jalet
 # warnpykota should be ok
@@ -33,6 +37,5 @@
 command line usage :
 
-  warnpykota [options] user1 user2 ... userN
-  warnpykota [options] group1 group2 ... groupN
+  warnpykota [options] 
 
 options :
@@ -86,14 +89,16 @@
 class WarnPyKota(PyKotaTool) :        
     """A class for warnpykota."""
-    def main(self, names, options) :
+    def main(self, options) :
         """Warn users or groups over print quota."""
+        
         printernames = self.storage.getMatchingPrinters(options["printer"])
         if not printernames :
             raise PyKotaToolError, "There's no printer matching %s" % options["printer"]
         for printer in printernames :
-            for name in names :
-                if options["users"] :
+            if options["users"] :
+                for name in self.storage.getPrinterUsers(printer) :
                     self.warnUserPQuota(name, printer)
-                else :
+            else :
+                for name in self.storage.getPrinterGroups(printer) :
                     self.warnGroupPQuota(name, printer)
                      
@@ -112,5 +117,5 @@
         
         # parse and checks the command line
-        (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options)
+        (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
         
         # sets long options
@@ -129,6 +134,8 @@
         elif options["groups"] :    
             raise PyKotaToolError, "warnpykota: options --groups is currently not implemented."
+        elif args :    
+            raise PyKotaToolError, "warnpykota: unused arguments [%s]. Aborting." % ", ".join(args)
         else :
-            sys.exit(sender.main(args, options))
+            sys.exit(sender.main(options))
     except PyKotaToolError, msg :            
         sys.stderr.write("%s\n" % msg)
