Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/warnpykota

    r3411 r3413  
    99# the Free Software Foundation, either version 3 of the License, or 
    1010# (at your option) any later version. 
    11 #  
     11# 
    1212# This program is distributed in the hope that it will be useful, 
    1313# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1414# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1515# GNU General Public License for more details. 
    16 #  
     16# 
    1717# You should have received a copy of the GNU General Public License 
    1818# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2525notifications to users or groups who have reached the limit of their 
    2626printing quota.""" 
    27          
     27 
    2828import sys 
    2929import os 
     
    4141from pykota.tool import PyKotaTool 
    4242 
    43 class WarnPyKota(PyKotaTool) :         
     43class WarnPyKota(PyKotaTool) : 
    4444    """A class for warnpykota.""" 
    4545    def sendMessage(self, adminmail, touser, fullmessage) : 
    4646        """Sends an email message containing headers to some user.""" 
    4747        smtpserver = self.smtpserver 
    48         try :     
     48        try : 
    4949            server = smtplib.SMTP(smtpserver) 
    50         except socket.error, msg :     
     50        except socket.error, msg : 
    5151            self.printInfo(_("Impossible to connect to SMTP server : %(smtpserver)s") \ 
    5252                                                % locals(), \ 
     
    5555            try : 
    5656                server.sendmail(adminmail, [touser], fullmessage) 
    57             except smtplib.SMTPException, answer :     
     57            except smtplib.SMTPException, answer : 
    5858                for (k, v) in answer.recipients.items() : 
    5959                    errormsg = v[0] 
     
    6363                                   "error") 
    6464            server.quit() 
    65              
     65 
    6666    def sendMessageToUser(self, admin, adminmail, user, subject, message) : 
    6767        """Sends an email message to a user.""" 
     
    7676        msg["Date"] = email.Utils.formatdate(localtime=True) 
    7777        self.sendMessage(adminmail, usermail, msg.as_string()) 
    78          
     78 
    7979    def sendMessageToAdmin(self, adminmail, subject, message) : 
    8080        """Sends an email message to the Print Quota administrator.""" 
     
    8686        msg["To"] = adminmail 
    8787        self.sendMessage(adminmail, adminmail, msg.as_string()) 
    88          
     88 
    8989    def warnGroupPQuota(self, grouppquota) : 
    9090        """Checks a group quota and send messages if quota is exceeded on current printer.""" 
     
    9898        if group.LimitBy in ("noquota", "nochange") : 
    9999            action = "ALLOW" 
    100         else :     
     100        else : 
    101101            action = self.checkGroupPQuota(grouppquota) 
    102102            if action.startswith("POLICY_") : 
     
    111111                        if mailto != "EXTERNAL" : 
    112112                            self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printername)) 
    113                         else :     
     113                        else : 
    114114                            self.externalMailTo(arguments, action, user, printer, self.config.getHardWarn(printername)) 
    115             elif action == "WARN" :     
     115            elif action == "WARN" : 
    116116                adminmessage = _("Print Quota low for group %(groupname)s on printer %(printername)s") % locals() 
    117117                self.printInfo(adminmessage) 
    118118                if mailto in [ "BOTH", "ADMIN" ] : 
    119119                    self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    120                 if group.LimitBy and (group.LimitBy.lower() == "balance") :  
     120                if group.LimitBy and (group.LimitBy.lower() == "balance") : 
    121121                    message = self.config.getPoorWarn() 
    122                 else :      
     122                else : 
    123123                    message = self.config.getSoftWarn(printername) 
    124124                if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
     
    126126                        if mailto != "EXTERNAL" : 
    127127                            self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
    128                         else :     
     128                        else : 
    129129                            self.externalMailTo(arguments, action, user, printer, message) 
    130         return action         
    131          
     130        return action 
     131 
    132132    def warnUserPQuota(self, userpquota) : 
    133133        """Checks a user quota and send him a message if quota is exceeded on current printer.""" 
     
    139139        adminmail = self.config.getAdminMail(printername) 
    140140        (mailto, arguments) = self.config.getMailTo(printername) 
    141          
     141 
    142142        if user.LimitBy in ("noquota", "nochange") : 
    143143            action = "ALLOW" 
     
    149149                if mailto != "EXTERNAL" : 
    150150                    self.sendMessageToUser(admin, adminmail, user, _("Printing denied."), message) 
    151                 else :     
     151                else : 
    152152                    self.externalMailTo(arguments, action, user, printer, message) 
    153153            if mailto in [ "BOTH", "ADMIN" ] : 
     
    157157            if action.startswith("POLICY_") : 
    158158                action = action[7:] 
    159                  
     159 
    160160            if action == "DENY" : 
    161161                adminmessage = _("Print Quota exceeded for user %(username)s on printer %(printername)s") % locals() 
     
    165165                    if mailto != "EXTERNAL" : 
    166166                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
    167                     else :     
     167                    else : 
    168168                        self.externalMailTo(arguments, action, user, printer, message) 
    169169                if mailto in [ "BOTH", "ADMIN" ] : 
    170170                    self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    171             elif action == "WARN" :     
     171            elif action == "WARN" : 
    172172                adminmessage = _("Print Quota low for user %(username)s on printer %(printername)s") % locals() 
    173173                self.printInfo(adminmessage) 
    174174                if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
    175                     if user.LimitBy and (user.LimitBy.lower() == "balance") :  
     175                    if user.LimitBy and (user.LimitBy.lower() == "balance") : 
    176176                        message = self.config.getPoorWarn() 
    177                     else :      
     177                    else : 
    178178                        message = self.config.getSoftWarn(printername) 
    179                     if mailto != "EXTERNAL" :     
     179                    if mailto != "EXTERNAL" : 
    180180                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 
    181                     else :     
     181                    else : 
    182182                        self.externalMailTo(arguments, action, user, printer, message) 
    183183                if mailto in [ "BOTH", "ADMIN" ] : 
    184184                    self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    185         return action         
    186          
     185        return action 
     186 
    187187    def main(self, ugnames, options) : 
    188188        """Warn users or groups over print quota.""" 
     
    192192                # no username, means all usernames 
    193193                ugnames = [ "*" ] 
    194         else :         
     194        else : 
    195195            # not a PyKota administrator 
    196196            # warns only the current user 
     
    203203                if user.Exists : 
    204204                    ugnames = [ g.Name for g in self.storage.getUserGroups(user) ] 
    205                 else :     
     205                else : 
    206206                    ugnames = [ ] 
    207207            else : 
    208208                ugnames = [ username ] 
    209                  
     209 
    210210        printername = options.printer 
    211211        printers = self.storage.getMatchingPrinters(printername) 
     
    231231                            if not done : 
    232232                                alreadydone[user.Name] = (action in ('WARN', 'DENY')) 
    233                       
    234 if __name__ == "__main__" :  
     233 
     234if __name__ == "__main__" : 
    235235    parser = PyKotaOptionParser(description=_("A tool to warn users and groups who have reached the limit of their printing quota."), 
    236236                                usage="warnpykota [options] [usernames|groupnames]") 
     
    243243                            default="*", 
    244244                            help=_("Acts on this printer only. You can specify several printer names by separating them with commas. The default value is '%default', which means all printers.")) 
    245                              
     245 
    246246    parser.add_example('', 
    247247                       _("This would notify all users who have reached the limit of their printing quota on any printer.")) 
     
    250250    parser.add_example('--groups --printer "HP*,XER*" "dev*"', 
    251251                       _("This would notify all users of the groups whose name begins with 'dev' and for which the printing quota limit is reached on any printer whose name begins with 'HP' or 'XER'.")) 
    252                         
     252 
    253253    run(parser, WarnPyKota)