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/edpykota

    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/>. 
     
    3838 
    3939  edpykota [options] user1 user2 ... userN 
    40    
     40 
    4141  edpykota [options] group1 group2 ... groupN 
    4242 
     
    4545  -v | --version       Prints edpykota's version number then exits. 
    4646  -h | --help          Prints this message then exits. 
    47    
     47 
    4848  -a | --add           Adds users or groups print quota entries if 
    4949                       they don't exist in database. 
    50                         
     50 
    5151  -d | --delete        Deletes users or groups print quota entries. 
    5252                       Users or groups are never deleted, you have 
     
    5454                       The history will be purge from all matching 
    5555                       jobs, unless -g | --groups is used. 
    56    
     56 
    5757  -P | --printer p     Edit quotas on printer p only. Actually p can 
    5858                       use wildcards characters to select only 
    5959                       some printers. The default value is *, meaning 
    60                        all printers.  
    61                        You can specify several names or wildcards,  
     60                       all printers. 
     61                       You can specify several names or wildcards, 
    6262                       by separating them with commas. 
    63    
    64   -g | --groups        Edit groups print quota entries instead of  
     63 
     64  -g | --groups        Edit groups print quota entries instead of 
    6565                       users print quota entries. 
    66                            
     66 
    6767  -L | --list          Lists users or groups print quota entries. 
    68    
     68 
    6969  -n | --noquota       Sets both soft and hard limits to None for users 
    7070                       or groups print quota entries. 
    71    
     71 
    7272  -r | --reset         Resets the actual page counter for the user 
    73                        or group to zero on the specified printers.  
     73                       or group to zero on the specified printers. 
    7474                       The life time page counter is kept unchanged. 
    75                         
     75 
    7676  -R | --hardreset     Resets the actual and life time page counters 
    77                        for the user or group to zero on the specified  
     77                       for the user or group to zero on the specified 
    7878                       printers. This is a shortcut for '--used 0'. 
    79                         
     79 
    8080  -s | --skipexisting  In combination with the --add option above, tells 
    8181                       edpykota to not modify existing print quota entries. 
    82                         
    83   -S | --softlimit sl  Sets the quota soft limit to sl pages.                        
    84    
     82 
     83  -S | --softlimit sl  Sets the quota soft limit to sl pages. 
     84 
    8585  -H | --hardlimit hl  Sets the quota hard limit to hl pages. 
    86    
     86 
    8787  -I | --increase v    Increase existing Soft and Hard limits by the value 
    8888                       of v. You can prefix v with + or -, if no sign is 
     
    104104  user1 through userN and group1 through groupN can use wildcards 
    105105  if the --add option is not set. 
    106    
    107 examples :                               
     106 
     107examples : 
    108108 
    109109  $ edpykota --add john paul george ringo 
    110    
     110 
    111111  This will create print quota entries for users john, paul, george 
    112112  and ringo on all printers. These print quota entries will have no 
    113113  limit set. 
    114    
     114 
    115115  $ edpykota --printer lp -S 50 -H 60 jerome 
    116    
     116 
    117117  This will set jerome's print quota on the lp printer to a soft limit 
    118118  of 50 pages, and a hard limit of 60 pages. Both user jerome and 
     
    120120  commands, respectively. 
    121121 
    122   $ edpykota -g -S 500 -H 550 financial support             
    123    
     122  $ edpykota -g -S 500 -H 550 financial support 
     123 
    124124  This will set print quota soft limit to 500 pages and hard limit 
    125125  to 550 pages for groups financial and support on all printers. 
    126    
     126 
    127127  $ edpykota --reset jerome "jo*" 
    128    
     128 
    129129  This will reset jerome's page counter to zero on all printers, as 
    130130  well as every user whose name begins with 'jo'. 
     
    132132  You can also reset the life time page counters by using the 
    133133  --hardreset | -R command line option. 
    134    
     134 
    135135  $ edpykota --printer hpcolor --noquota jerome 
    136    
    137   This will tell PyKota to not limit jerome when printing on the  
    138   hpcolor printer. All his jobs will be allowed on this printer, but  
     136 
     137  This will tell PyKota to not limit jerome when printing on the 
     138  hpcolor printer. All his jobs will be allowed on this printer, but 
    139139  accounting of the pages he prints will still be kept. 
    140140  Print Quotas for jerome on other printers are unchanged. 
    141    
     141 
    142142  $ edpykota --delete --printer "HP*,XER*" jerome rachel 
    143    
     143 
    144144  This will delete users jerome and rachel's print quota 
    145145  entries on all printers which name begin with 'HP' or 
    146146  'XER'. The jobs printed by these users on these printers 
    147147  will be deleted from the history. 
    148 """)  
    149          
    150 class EdPyKota(PyKotaTool) :         
     148""") 
     149 
     150class EdPyKota(PyKotaTool) : 
    151151    """A class for edpykota.""" 
    152152    def modifyPQEntry(self, pqkey, pqentry, noquota, softlimit, hardlimit, increase, reset, hardreset, suffix, used) : 
     
    155155            pqentry.setLimits(softlimit, hardlimit) 
    156156        if increase : 
    157             newsoft = (pqentry.SoftLimit or 0) + increase          
    158             newhard = (pqentry.HardLimit or 0) + increase          
     157            newsoft = (pqentry.SoftLimit or 0) + increase 
     158            newhard = (pqentry.HardLimit or 0) + increase 
    159159            if (newsoft >= 0) and (newhard >= 0) : 
    160160                pqentry.setLimits(newsoft, newhard) 
    161             else :     
     161            else : 
    162162                self.printInfo(_("You can't set negative limits for %s") % pqkey, "error") 
    163163        if reset : 
    164164            pqentry.reset() 
    165         if hardreset :     
     165        if hardreset : 
    166166            pqentry.hardreset() 
    167167        if suffix == "User" : 
    168168            if used : 
    169169                pqentry.setUsage(used) 
    170      
     170 
    171171    def main(self, names, options) : 
    172172        """Edit user or group quotas.""" 
    173173        names = self.sanitizeNames(options, names) 
    174         suffix = (options["groups"] and "Group") or "User"         
     174        suffix = (options["groups"] and "Group") or "User" 
    175175        printernames = options["printer"].split(",") 
    176              
     176 
    177177        if not options["list"] : 
    178178            percent = Percent(self) 
     
    182182        if not options["list"] : 
    183183            percent.setSize(len(printers) * len(entries)) 
    184          
     184 
    185185        if options["list"] : 
    186186            for printer in printers : 
     
    198198                            print "    %s" % (_("Warning banners printed : %s") % pqentry.WarnCount) 
    199199                        print 
    200         elif options["delete"] :     
     200        elif options["delete"] : 
    201201            percent.display("\n%s..." % _("Deletion")) 
    202202            getattr(self.storage, "deleteMany%sPQuotas" % suffix)(printers, entries) 
     
    211211                except ValueError : 
    212212                    raise PyKotaCommandLineError, _("Invalid used value %s.") % used 
    213                      
     213 
    214214            increase = options["increase"] 
    215215            if increase : 
     
    218218                except ValueError : 
    219219                    raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase 
    220              
     220 
    221221            noquota = options["noquota"] 
    222             reset = options["reset"]         
     222            reset = options["reset"] 
    223223            hardreset = options["hardreset"] 
    224224            softlimit = hardlimit = None 
     
    229229                        if softlimit < 0 : 
    230230                            raise ValueError 
    231                     except ValueError :     
     231                    except ValueError : 
    232232                        raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"] 
    233233                if options["hardlimit"] : 
     
    236236                        if hardlimit < 0 : 
    237237                            raise ValueError 
    238                     except ValueError :     
     238                    except ValueError : 
    239239                        raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"] 
    240                 if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) :         
     240                if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) : 
    241241                    # error, exchange them 
    242242                    self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) 
    243243                    (softlimit, hardlimit) = (hardlimit, softlimit) 
    244                 if hardlimit is None :     
     244                if hardlimit is None : 
    245245                    hardlimit = softlimit 
    246246                    if hardlimit is not None : 
    247247                        self.printInfo(_("Undefined hard limit set to soft limit (%s).") % str(hardlimit)) 
    248                 if softlimit is None :     
     248                if softlimit is None : 
    249249                    softlimit = hardlimit 
    250250                    if softlimit is not None : 
    251251                        self.printInfo(_("Undefined soft limit set to hard limit (%s).") % str(softlimit)) 
    252                          
    253             self.storage.beginTransaction()             
     252 
     253            self.storage.beginTransaction() 
    254254            try : 
    255255                if options["add"] : 
    256256                    percent.display("\n%s...\n" % _("Creation")) 
    257                     if not entries :     
     257                    if not entries : 
    258258                        self.printInfo(_("No entry matches %s. Please use pkusers to create them first.") % (" ".join(names)), "warn") 
    259                              
     259 
    260260                    factory = globals()["Storage%sPQuota" % suffix] 
    261261                    for printer in printers : 
     
    270270                                                        hardreset, suffix, used) 
    271271                            oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) 
    272                             if oldpqentry is not None :     
     272                            if oldpqentry is not None : 
    273273                                if skipexisting : 
    274274                                    self.logdebug("%s print quota entry %s@%s already exists, skipping." % (suffix, ename, pname)) 
    275                                 else :     
     275                                else : 
    276276                                    self.logdebug("%s print quota entry %s@%s already exists, will be modified." % (suffix, ename, pname)) 
    277277                                    self.modifyPQEntry(pqkey, oldpqentry, noquota, \ 
     
    279279                                                        increase, reset, \ 
    280280                                                        hardreset, suffix, used) 
    281                                     oldpqentry.save()                     
     281                                    oldpqentry.save() 
    282282                            percent.oneMore() 
    283                 else :         
     283                else : 
    284284                    percent.display("\n%s...\n" % _("Modification")) 
    285285                    for printer in printers : 
     
    287287                            pqkey = "%s@%s" % (entry.Name, printer.Name) 
    288288                            pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 
    289                             if pqentry.Exists :      
     289                            if pqentry.Exists : 
    290290                                self.modifyPQEntry(pqkey, pqentry, noquota, \ 
    291291                                                    softlimit, hardlimit, \ 
    292292                                                    increase, reset, \ 
    293293                                                    hardreset, suffix, used) 
    294                                 pqentry.save()         
     294                                pqentry.save() 
    295295                            percent.oneMore() 
    296             except :                     
     296            except : 
    297297                self.storage.rollbackTransaction() 
    298298                raise 
    299             else :     
     299            else : 
    300300                self.storage.commitTransaction() 
    301                              
     301 
    302302        if not options["list"] : 
    303303            percent.done() 
    304              
    305 if __name__ == "__main__" :  
     304 
     305if __name__ == "__main__" : 
    306306    retcode = 0 
    307307    try : 
     
    316316                        "printer=", "softlimit=", "hardlimit=", \ 
    317317                        "increase=", "used=", "skipexisting"] 
    318          
     318 
    319319        # Initializes the command line tool 
    320320        manager = EdPyKota(doc=__doc__) 
    321321        manager.deferredInit() 
    322          
     322 
    323323        # parse and checks the command line 
    324324        (options, args) = manager.parseCommandline(sys.argv[1:], short_options, long_options) 
    325          
     325 
    326326        # sets long options 
    327327        options["help"] = options["h"] or options["help"] 
     
    331331        options["printer"] = options["P"] or options["printer"] or defaults["printer"] 
    332332        options["softlimit"] = options["S"] or options["softlimit"] 
    333         options["hardlimit"] = options["H"] or options["hardlimit"]  
    334         options["reset"] = options["r"] or options["reset"]  
     333        options["hardlimit"] = options["H"] or options["hardlimit"] 
     334        options["reset"] = options["r"] or options["reset"] 
    335335        options["noquota"] = options["n"] or options["noquota"] 
    336         options["delete"] = options["d"] or options["delete"]  
    337         options["hardreset"] = options["R"] or options["hardreset"]  
     336        options["delete"] = options["d"] or options["delete"] 
     337        options["hardreset"] = options["R"] or options["hardreset"] 
    338338        options["used"] = options["U"] or options["used"] 
    339339        options["increase"] = options["I"] or options["increase"] 
    340340        options["list"] = options["L"] or options["list"] 
    341341        options["skipexisting"] = options["s"] or options["skipexisting"] 
    342          
     342 
    343343        if options["help"] : 
    344344            manager.display_usage_and_quit() 
     
    354354        else : 
    355355            retcode = manager.main(args, options) 
    356     except KeyboardInterrupt :         
     356    except KeyboardInterrupt : 
    357357        logerr("\nInterrupted with Ctrl+C !\n") 
    358358        retcode = -3 
    359     except PyKotaCommandLineError, msg :      
     359    except PyKotaCommandLineError, msg : 
    360360        logerr("%s : %s\n" % (sys.argv[0], msg)) 
    361361        retcode = -2 
    362     except SystemExit :         
     362    except SystemExit : 
    363363        pass 
    364364    except : 
    365365        try : 
    366366            manager.crashed("edpykota failed") 
    367         except :     
     367        except : 
    368368            crashed("edpykota failed") 
    369369        retcode = -1 
     
    371371    try : 
    372372        manager.storage.close() 
    373     except (TypeError, NameError, AttributeError) :     
     373    except (TypeError, NameError, AttributeError) : 
    374374        pass 
    375          
    376     sys.exit(retcode)     
     375 
     376    sys.exit(retcode)