Show
Ignore:
Timestamp:
06/13/06 23:10:15 (18 years ago)
Author:
jerome
Message:

pkusers now supports the --email command line option.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkusers

    r2829 r2937  
    5454                        
    5555  -d | --delete        Deletes users from the quota storage. 
    56    
     56 
     57  -e | --email addr    Sets the email address for the users. 
     58                       If the addr parameter begins with @, then 
     59                       the username is prepended to addr to form 
     60                       a valid email address. 
     61 
    5762  -D | --description d Adds a textual description to users or groups. 
    5863                        
     
    154159  cost of each print job will be multiplied by zero before charging 
    155160  his account. 
     161 
     162  $ pkusers --email @example.com 
     163 
     164  This will set the email address for each user to username@example.com 
    156165""") 
    157166         
     
    165174            entry.setLimitBy(limitby) 
    166175        if not groups : 
    167             if email : 
    168                 entry.Email = email 
     176            if email is not None :      # we allow "" to empty the field 
     177                if email.startswith("@") : 
     178                    email = "%s%s" % (entry.Name, email) 
     179                if email and email.count('@') != 1 : 
     180                    raise PyKotaCommandLineError, _("Invalid email address %s") % email 
     181                entry.setEmail(email) 
    169182            if overcharge is not None : # NB : 0 is allowed !      
    170183                entry.setOverChargeFactor(overcharge) 
     
    279292            description = options["description"] 
    280293            if description : 
    281                 description = options["description"].strip() 
     294                description = description.strip() 
    282295                 
    283296            comment = options["comment"] 
    284297            if comment : 
    285                 comment = options["comment"].strip() 
     298                comment = comment.strip() 
     299            email = options["email"]     
     300            if email : 
     301                email = email.strip() 
    286302            skipexisting = options["skipexisting"]     
    287303            groups = options["groups"] 
     
    294310                    percent.setSize(len(names)) 
    295311                    for ename in names : 
    296                         email = None 
     312                        useremail = None 
    297313                        if not groups : 
    298314                            splitname = ename.split('/', 1)     # username/email 
    299315                            if len(splitname) == 1 : 
    300316                                splitname.append("") 
    301                             (ename, email) = splitname 
    302                             if email and (email.count('@') != 1) : 
    303                                 raise PyKotaCommandLineError, _("Invalid email address %s") % email 
     317                            (ename, useremail) = splitname 
    304318                        if self.isValidName(ename) : 
    305319                            reject = 0 
     
    326340                                                     description, overcharge,\ 
    327341                                                     balance, balancevalue, \ 
    328                                                      comment, email) 
     342                                                     comment, useremail or email) 
    329343                                oldentry = getattr(self.storage, "add%s" % suffix)(entry) 
    330344                                if oldentry is not None : 
     
    340354                                                     description, overcharge,\ 
    341355                                                     balance, balancevalue, \ 
    342                                                      comment, email) 
     356                                                     comment, useremail or email) 
    343357                                        oldentry.save() 
    344358                                        if not groups : 
     
    359373                            self.modifyEntry(entry, groups, limitby, description, \ 
    360374                                             overcharge, balance, balancevalue, \ 
    361                                              comment) 
     375                                             comment, email) 
    362376                            self.manageUsersGroups(usersgroups, entry, remove)                 
    363377                        entry.save()     
     
    378392                     "comment" : "", \ 
    379393                   } 
    380         short_options = "hvaD:dgl:rso:i:b:C:L" 
     394        short_options = "hvaD:dgl:rso:i:b:C:Le:" 
    381395        long_options = ["help", "version", "add", "description=", \ 
    382396                        "delete", "groups", "list", "remove", \ 
    383                         "skipexisting", "overcharge=", \ 
     397                        "skipexisting", "overcharge=", "email=", \ 
    384398                        "ingroups=", "limitby=", "balance=", "comment=", \ 
    385399                       ] 
     
    408422        options["overcharge"] = options["o"] or options["overcharge"] 
    409423        options["comment"] = options["C"] or options["comment"] or defaults["comment"] 
     424        options["email"] = options["e"] or options["email"] 
    410425         
    411426        if options["help"] : 
     
    413428        elif options["version"] : 
    414429            manager.display_version_and_quit() 
    415         elif (options["delete"] and (options["add"] or options["remove"] or options["description"])) \ 
     430        elif (options["delete"] and (options["add"] or options["remove"] or options["description"] or options["email"])) \ 
    416431           or (options["skipexisting"] and not options["add"]) \ 
    417            or (options["list"] and (options["add"] or options["delete"] or options["remove"] or options["description"])) \ 
     432           or (options["list"] and (options["add"] or options["delete"] or options["remove"] or options["description"] or options["email"])) \ 
    418433           or (options["groups"] and (options["balance"] or options["ingroups"] or options["overcharge"])) : 
    419434            raise PyKotaCommandLineError, _("incompatible options, see help.")