Changeset 3167 for pykota/trunk
- Timestamp:
- 04/17/07 00:13:44 (18 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r3165 r3167 1574 1574 self.doDelete(code.ident) 1575 1575 1576 def sortRecords(self, fields, records, default, ordering) : 1577 """Sort records based on list of fields prefixed with '+' (ASC) or '-' (DESC).""" 1578 fieldindexes = {} 1579 for i in range(len(fields)) : 1580 fieldindexes[fields[i]] = i 1581 if not ordering : 1582 ordering = default 1583 orderby = [] 1584 for orderkey in ordering : 1585 if orderkey.startswith("-") : 1586 orderby.append((-1, fieldindexes[orderkey[1:]])) 1587 elif orderkey.startswith("+") : 1588 orderby.append((+1, fieldindexes[orderkey[1:]])) 1589 else : 1590 orderby.append((+1, fieldindexes[orderkey])) 1591 1592 def compare(x, y, orderby=orderby) : 1593 """Compares two records.""" 1594 i = 0 1595 nbkeys = len(orderby) 1596 while i < nbkeys : 1597 (sign, index) = orderby[i] 1598 result = cmp(x[i], y[i]) 1599 if not result : 1600 i += 1 1601 else : 1602 return sign * result 1603 return 0 # identical keys 1604 1605 records.sort(compare) 1606 return records 1607 1576 1608 def extractPrinters(self, extractonly={}, ordering=[]) : 1577 1609 """Extracts all printer records.""" … … 1579 1611 entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 1580 1612 if entries : 1581 result = [ ("dn", "printername", "priceperpage", "priceperjob", "description", "maxjobsize", "passthrough") ] 1613 fields = ("dn", "printername", "priceperpage", "priceperjob", "description", "maxjobsize", "passthrough") 1614 result = [] 1582 1615 for entry in entries : 1583 1616 if entry.PassThrough in (1, "1", "t", "true", "T", "TRUE", "True") : … … 1586 1619 passthrough = "f" 1587 1620 result.append((entry.ident, entry.Name, entry.PricePerPage, entry.PricePerJob, entry.Description, entry.MaxJobSize, passthrough)) 1588 return result1621 return [fields] + self.sortRecords(fields, result, ["+dn"], ordering) 1589 1622 1590 1623 def extractUsers(self, extractonly={}, ordering=[]) : … … 1593 1626 entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames(uname)] if u.Exists] 1594 1627 if entries : 1595 result = [ ("dn", "username", "balance", "lifetimepaid", "limitby", "email", "description", "overcharge") ] 1628 fields = ("dn", "username", "balance", "lifetimepaid", "limitby", "email", "description", "overcharge") 1629 result = [] 1596 1630 for entry in entries : 1597 1631 result.append((entry.ident, entry.Name, entry.AccountBalance, entry.LifeTimePaid, entry.LimitBy, entry.Email, entry.Description, entry.OverCharge)) 1598 return result1632 return [fields] + self.sortRecords(fields, result, ["+dn"], ordering) 1599 1633 1600 1634 def extractBillingcodes(self, extractonly={}, ordering=[]) : … … 1603 1637 entries = [b for b in [self.getBillingCode(label) for label in self.getAllBillingCodes(billingcode)] if b.Exists] 1604 1638 if entries : 1605 result = [ ("dn", "billingcode", "balance", "pagecounter", "description") ] 1639 fields = ("dn", "billingcode", "balance", "pagecounter", "description") 1640 result = [] 1606 1641 for entry in entries : 1607 1642 result.append((entry.ident, entry.BillingCode, entry.Balance, entry.PageCounter, entry.Description)) 1608 return result1643 return [fields] + self.sortRecords(fields, result, ["+dn"], ordering) 1609 1644 1610 1645 def extractGroups(self, extractonly={}, ordering=[]) : … … 1613 1648 entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames(gname)] if g.Exists] 1614 1649 if entries : 1615 result = [ ("dn", "groupname", "limitby", "balance", "lifetimepaid", "description") ] 1650 fields = ("dn", "groupname", "limitby", "balance", "lifetimepaid", "description") 1651 result = [] 1616 1652 for entry in entries : 1617 1653 result.append((entry.ident, entry.Name, entry.LimitBy, entry.AccountBalance, entry.LifeTimePaid, entry.Description)) 1618 return result1654 return [fields] + self.sortRecords(fields, result, ["+dn"], ordering) 1619 1655 1620 1656 def extractPayments(self, extractonly={}, ordering=[]) : … … 1626 1662 entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames(uname)] if u.Exists] 1627 1663 if entries : 1628 result = [ ("username", "amount", "date", "description") ] 1664 fields = ("username", "amount", "date", "description") 1665 result = [] 1629 1666 for entry in entries : 1630 1667 for (date, amount, description) in entry.Payments : … … 1634 1671 ((date >= startdate) and (date <= enddate)) : 1635 1672 result.append((entry.Name, amount, date, description)) 1636 return result1673 return [fields] + self.sortRecords(fields, result, ["+date"], ordering) 1637 1674 1638 1675 def extractUpquotas(self, extractonly={}, ordering=[]) : … … 1641 1678 entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 1642 1679 if entries : 1643 result = [ ("username", "printername", "dn", "userdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit") ] 1680 fields = ("username", "printername", "dn", "userdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit") 1681 result = [] 1644 1682 uname = extractonly.get("username") 1645 1683 for entry in entries : 1646 1684 for (user, userpquota) in self.getPrinterUsersAndQuotas(entry, names=[uname or "*"]) : 1647 1685 result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit)) 1648 return result1686 return [fields] + self.sortRecords(fields, result, ["+userdn"], ordering) 1649 1687 1650 1688 def extractGpquotas(self, extractonly={}, ordering=[]) : … … 1653 1691 entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 1654 1692 if entries : 1655 result = [ ("groupname", "printername", "dn", "groupdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit") ] 1693 fields = ("groupname", "printername", "dn", "groupdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit") 1694 result = [] 1656 1695 gname = extractonly.get("groupname") 1657 1696 for entry in entries : 1658 1697 for (group, grouppquota) in self.getPrinterGroupsAndQuotas(entry, names=[gname or "*"]) : 1659 1698 result.append((group.Name, entry.Name, grouppquota.ident, group.ident, entry.ident, grouppquota.LifePageCounter, grouppquota.PageCounter, grouppquota.SoftLimit, grouppquota.HardLimit, grouppquota.DateLimit)) 1660 return result1699 return [fields] + self.sortRecords(fields, result, ["+groupdn"], ordering) 1661 1700 1662 1701 def extractUmembers(self, extractonly={}, ordering=[]) : … … 1665 1704 entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames(gname)] if g.Exists] 1666 1705 if entries : 1667 result = [ ("groupname", "username", "groupdn", "userdn") ] 1706 fields = ("groupname", "username", "groupdn", "userdn") 1707 result = [] 1668 1708 uname = extractonly.get("username") 1669 1709 for entry in entries : … … 1671 1711 if (uname is None) or (member.Name == uname) : 1672 1712 result.append((entry.Name, member.Name, entry.ident, member.ident)) 1673 return result1713 return [fields] + self.sortRecords(fields, result, ["+groupdn", "+userdn"], ordering) 1674 1714 1675 1715 def extractPmembers(self, extractonly={}, ordering=[]) : … … 1678 1718 entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 1679 1719 if entries : 1680 result = [ ("pgroupname", "printername", "pgroupdn", "printerdn") ] 1720 fields = ("pgroupname", "printername", "pgroupdn", "printerdn") 1721 result = [] 1681 1722 pgname = extractonly.get("pgroupname") 1682 1723 for entry in entries : … … 1684 1725 if (pgname is None) or (parent.Name == pgname) : 1685 1726 result.append((parent.Name, entry.Name, parent.ident, entry.ident)) 1686 return result1727 return [fields] + self.sortRecords(fields, result, ["+pgroupdn", "+printerdn"], ordering) 1687 1728 1688 1729 def extractHistory(self, extractonly={}, ordering=[]) : … … 1703 1744 entries = self.retrieveHistory(user, printer, hostname=extractonly.get("hostname"), billingcode=extractonly.get("billingcode"), jobid=extractonly.get("jobid"), limit=None, start=startdate, end=enddate) 1704 1745 if entries : 1705 result = [ ("username", "printername", "dn", "jobid", "pagecounter", "jobsize", "action", "jobdate", "filename", "title", "copies", "options", "jobprice", "hostname", "jobsizebytes", "md5sum", "pages", "billingcode", "precomputedjobsize", "precomputedjobprice") ] 1746 fields = ("username", "printername", "dn", "jobid", "pagecounter", "jobsize", "action", "jobdate", "filename", "title", "copies", "options", "jobprice", "hostname", "jobsizebytes", "md5sum", "pages", "billingcode", "precomputedjobsize", "precomputedjobprice") 1747 result = [] 1706 1748 for entry in entries : 1707 1749 result.append((entry.UserName, entry.PrinterName, entry.ident, entry.JobId, entry.PrinterPageCounter, entry.JobSize, entry.JobAction, entry.JobDate, entry.JobFileName, entry.JobTitle, entry.JobCopies, entry.JobOptions, entry.JobPrice, entry.JobHostName, entry.JobSizeBytes, entry.JobMD5Sum, entry.JobPages, entry.JobBillingCode, entry.PrecomputedJobSize, entry.PrecomputedJobPrice)) 1708 return result1750 return [fields] + self.sortRecords(fields, result, ["+dn"], ordering) 1709 1751 1710 1752 def getBillingCodeFromBackend(self, label) : -
pykota/trunk/TODO
r3165 r3167 29 29 normal page accounting. 30 30 31 - --orderby and --order ASC|DESC for dumpykota (or --asc | --desc)32 Now works for SQL backends, not with LDAP yet.33 34 31 - Document the PYKOTA_HOME environment variable. 35 32