Changeset 2452 for pykota/trunk/pykota

Show
Ignore:
Timestamp:
09/17/05 16:29:43 (19 years ago)
Author:
jerome
Message:

Upgraded database schema.
Added -i | --ingroups command line option to repykota.
Added -C | --comment command line option to edpykota.
Added 'noquota', 'noprint', and 'nochange' as switches for edpykota's
-l | --limitby command line option.
Severity : entirely new features, in need of testers :-)

Location:
pykota/trunk/pykota
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/reporter.py

    r2302 r2452  
    8585            warncount = int(quota.WarnCount or 0) 
    8686         
    87         #balance 
    88         if entry.LimitBy and (entry.LimitBy.lower() == "balance") :     
    89             if balance == 0.0 : 
    90                 if entry.OverCharge > 0 : 
    91                     datelimit = "DENY" 
    92                     reached = "+B" 
    93                 else :     
    94                     # overcharging by a negative or nul factor means user is always allowed to print 
    95                     # TODO : do something when printer prices are negative as well ! 
    96                     datelimit = "" 
    97                     reached = "-B" 
    98             elif balance < 0 : 
    99                 datelimit = "DENY" 
    100                 reached = "+B" 
    101             elif balance <= self.tool.config.getPoorMan() : 
    102                 datelimit = "WARNING" 
    103                 reached = "?B" 
    104             else :     
    105                 datelimit = "" 
    106                 reached = "-B" 
    107  
    108         #balance-then-quota 
    109         elif entry.LimitBy and (entry.LimitBy.lower() == "balance-then-quota") : 
    110             if balance <= 0 : 
    111                 if (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) : 
    112                     datelimit = "DENY" 
    113                 elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) : 
    114                     datelimit = "DENY" 
    115                 elif quota.DateLimit is not None : 
    116                     now = DateTime.now() 
    117                     datelimit = DateTime.ISO.ParseDateTime(quota.DateLimit) 
    118                     if now >= datelimit : 
    119                         datelimit = "QUOTA_DENY" 
    120                 else : 
    121                     datelimit = "" 
    122                 reached = ( ((datelimit == "DENY" ) and "+B") or "-Q") 
    123                 datelimit = ( ((datelimit == "QUOTA_DENY") and "DENY") or datelimit) 
    124             elif balance <= self.tool.config.getPoorMan() : 
    125                 if (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) : 
    126                     datelimit = "WARNING" 
    127                 elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) : 
    128                     datelimit = "WARNING" 
    129                 elif quota.DateLimit is not None : 
    130                     now = DateTime.now() 
    131                     datelimit = DateTime.ISO.ParseDateTime(quota.DateLimit) 
    132                     if now >= datelimit : 
    133                         datelimit = "QUOTA_DENY" 
    134                 else : 
    135                     datelimit = "" 
    136                 reached = ( ((datelimit == "WARNING" ) and "?B") or "+Q") 
    137                 datelimit = ( ((datelimit == "QUOTA_DENY") and "WARNING") or datelimit) 
    138             else : 
    139                 datelimit = "" 
    140                 reached = "-B" 
    141  
    142         #Quota-then-balance 
    143         elif entry.LimitBy and (entry.LimitBy.lower() == "quota-then-balance") : 
    144             if (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) : 
    145                 datelimit = "DENY" 
    146             elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) : 
    147                 datelimit = "DENY" 
    148             elif quota.DateLimit is not None : 
    149                 now = DateTime.now() 
    150                 datelimit = DateTime.ISO.ParseDateTime(quota.DateLimit) 
    151                 if now >= datelimit : 
    152                     datelimit = "DENY" 
    153             else : 
    154                 datelimit = "" 
    155                  
    156             reached = (((quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) and "+") or "-") + "Q" 
    157  
    158             if (datelimit == "DENY") and (reached == "-Q") and (balance > self.tool.config.getPoorMan()) : 
    159                 datelimit = "" 
    160                 reached = "-B" 
    161             else : 
    162                 reached = (((datelimit == "DENY") and (self.tool.config.getPoorMan() < balance ) and "-B") or reached) 
    163                 if (datelimit == "DENY") and (self.tool.config.getPoorMan() < balance) : 
    164                     datelimit = "" 
    165                 reached = (((datelimit == "DENY") and (0.0 < balance <= self.tool.config.getPoorMan()) and "?B") or reached) 
    166                 datelimit = (((datelimit == "DENY") and (0.0 < balance <= self.tool.config.getPoorMan()) and "WARNING") or datelimit) 
    167  
    168         #Quota 
    169         else : 
     87        if (not entry.LimitBy) or (entry.LimitBy.lower() == "quota") : 
    17088            if (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) :     
    17189                datelimit = "DENY" 
     
    18098                datelimit = "" 
    18199            reached = (((quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) and "+") or "-") + "Q" 
     100        else : 
     101            if entry.LimitBy.lower() == "balance" : 
     102                if balance == 0.0 : 
     103                    if entry.OverCharge > 0 : 
     104                        datelimit = "DENY" 
     105                        reached = "+B" 
     106                    else :     
     107                        # overcharging by a negative or nul factor means user is always allowed to print 
     108                        # TODO : do something when printer prices are negative as well ! 
     109                        datelimit = "" 
     110                        reached = "-B" 
     111                elif balance < 0 : 
     112                    datelimit = "DENY" 
     113                    reached = "+B" 
     114                elif balance <= self.tool.config.getPoorMan() : 
     115                    datelimit = "WARNING" 
     116                    reached = "?B" 
     117                else :     
     118                    datelimit = "" 
     119                    reached = "-B" 
     120            elif entry.LimitBy.lower() == "noquota" : 
     121                reached = "NQ" 
     122                datelimit = "" 
     123            elif entry.LimitBy.lower() == "nochange" : 
     124                reached = "NC" 
     125                datelimit = "" 
     126            else : 
     127                # noprint 
     128                reached = "NP" 
     129                datelimit = "DENY" 
    182130             
    183131        strbalance = ("%5.2f" % balance)[:10] 
  • pykota/trunk/pykota/storage.py

    r2451 r2452  
    5959        self.AccountBalance = float(self.AccountBalance or 0.0) - amount 
    6060         
    61     def setAccountBalance(self, balance, lifetimepaid) :     
     61    def setAccountBalance(self, balance, lifetimepaid, comment="") : 
    6262        """Sets the user's account balance in case he pays more money.""" 
    6363        diff = float(lifetimepaid or 0.0) - float(self.LifeTimePaid or 0.0) 
     
    6565        try : 
    6666            self.parent.writeUserAccountBalance(self, balance, lifetimepaid) 
    67             self.parent.writeNewPayment(self, diff) 
     67            self.parent.writeNewPayment(self, diff, comment) 
    6868        except PyKotaStorageError, msg :     
    6969            self.parent.rollbackTransaction() 
     
    8080        except AttributeError :     
    8181            limitby = "quota" 
    82         if limitby in ["quota", "balance", "quota-then-balance", "balance-then-quota"] : 
     82        if limitby in ["quota", "balance", \ 
     83                       "noquota", "noprint", "nochange"] : 
    8384            self.parent.writeUserLimitBy(self, limitby) 
    8485            self.LimitBy = limitby 
     
    120121        except AttributeError :     
    121122            limitby = "quota" 
    122         if limitby in ["quota", "balance"] : 
     123        if limitby in ["quota", "balance", "noquota"] : 
    123124            self.parent.writeGroupLimitBy(self, limitby) 
    124125            self.LimitBy = limitby 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2418 r2452  
    382382                user.Payments = [] 
    383383                for payment in fields.get("pykotaPayments", []) : 
    384                     (date, amount) = payment.split(" # ") 
    385                     user.Payments.append((date, float(amount))) 
     384                    try : 
     385                        (date, amount, description) = payment.split(" # ") 
     386                    except ValueError : 
     387                        # Payment with no description (old Payment) 
     388                        (date, amount) = payment.split(" # ") 
     389                        description = "" 
     390                    else :     
     391                        description = self.databaseToUserCharset(description) 
     392                    user.Payments.append((date, float(amount), description)) 
    386393            user.Exists = 1 
    387394        return user 
     
    935942        return self.doModify(user.idbalance, fields)          
    936943             
    937     def writeNewPayment(self, user, amount) :         
     944    def writeNewPayment(self, user, amount, comment="") : 
    938945        """Adds a new payment to the payments history.""" 
    939946        payments = [] 
    940947        for payment in user.Payments : 
    941             payments.append("%s # %s" % (payment[0], str(payment[1]))) 
    942         payments.append("%s # %s" % (str(DateTime.now()), str(amount))) 
     948            payments.append("%s # %s # %s" % (payment[0], str(payment[1]), payment[2])) 
     949        payments.append("%s # %s # %s" % (str(DateTime.now()), str(amount), self.userCharsetToDatabase(comment))) 
    943950        fields = { 
    944951                   "pykotaPayments" : payments, 
     
    13041311        entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames(uname)] if u.Exists] 
    13051312        if entries : 
    1306             result = [ ("username", "amount", "date") ] 
     1313            result = [ ("username", "amount", "date", "description") ] 
    13071314            for entry in entries : 
    1308                 for (date, amount) in entry.Payments : 
    1309                     result.append((entry.Name, amount, date)) 
     1315                for (date, amount, description) in entry.Payments : 
     1316                    result.append((entry.Name, amount, date, description)) 
    13101317            return result         
    13111318         
  • pykota/trunk/pykota/storages/sql.py

    r2388 r2452  
    514514            self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident))) 
    515515             
    516     def writeNewPayment(self, user, amount) :         
     516    def writeNewPayment(self, user, amount, comment="") : 
    517517        """Adds a new payment to the payments history.""" 
    518         self.doModify("INSERT INTO payments (userid, amount) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(amount))) 
     518        self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(comment))) 
    519519         
    520520    def writeLastJobSize(self, lastjob, jobsize, jobprice) :         
  • pykota/trunk/pykota/tool.py

    r2409 r2452  
    485485        # first we check any group the user is a member of 
    486486        for group in self.storage.getUserGroups(user) : 
    487             grouppquota = self.storage.getGroupPQuota(group, printer) 
    488             # for the printer and all its parents 
    489             for gpquota in [ grouppquota ] + grouppquota.ParentPrintersGroupPQuota : 
    490                 if gpquota.Exists : 
    491                     action = self.checkGroupPQuota(gpquota) 
    492                     if action == "DENY" : 
    493                         return action 
    494                     elif action == "WARN" :     
    495                         warned = 1 
     487            # No need to check anything if the group is in noquota mode 
     488            if group.LimitBy != "noquota" : 
     489                grouppquota = self.storage.getGroupPQuota(group, printer) 
     490                # for the printer and all its parents 
     491                for gpquota in [ grouppquota ] + grouppquota.ParentPrintersGroupPQuota : 
     492                    if gpquota.Exists : 
     493                        action = self.checkGroupPQuota(gpquota) 
     494                        if action == "DENY" : 
     495                            return action 
     496                        elif action == "WARN" :     
     497                            warned = 1 
    496498                         
    497499        # Then we check the user's account balance 
  • pykota/trunk/pykota/version.py

    r2447 r2452  
    2222# 
    2323 
    24 __version__ = "1.23alpha29_unofficial" 
     24__version__ = "1.23alpha30_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS and LPRng."