Skip to content

Commit 6044f9f

Browse files
author
Richard Jones
committed
all backends implement the retired check in getnodeids [SF#1290560]
1 parent c7eea32 commit 6044f9f

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Fixed:
3131
- HTTP authorization takes precedence over session cookie (sf bug 1396134)
3232
- enforce correct encoding of PostgreSQL backend (sf bug 1374235)
3333
- grouping/sorting on link to same class fixed (sf bug 1404930)
34+
- all backends implement the retired check in getnodeids (sf bug 1290560)
3435

3536

3637
2005-10-07 0.9.0b1

roundup/backends/back_anydbm.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.192 2006-01-20 02:40:56 richard Exp $
18+
#$Id: back_anydbm.py,v 1.193 2006-01-23 05:24:33 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -1515,25 +1515,43 @@ def list(self):
15151515
l.sort()
15161516
return l
15171517

1518-
def getnodeids(self, db=None):
1518+
def getnodeids(self, db=None, retired=None):
15191519
''' Return a list of ALL nodeids
1520+
1521+
Set retired=None to get all nodes. Otherwise it'll get all the
1522+
retired or non-retired nodes, depending on the flag.
15201523
'''
15211524
res = []
15221525

15231526
# start off with the new nodes
15241527
if self.db.newnodes.has_key(self.classname):
15251528
res += self.db.newnodes[self.classname].keys()
15261529

1530+
must_close = False
15271531
if db is None:
15281532
db = self.db.getclassdb(self.classname)
1529-
res = res + db.keys()
1533+
must_close = True
1534+
try:
1535+
res = res + db.keys()
15301536

1531-
# remove the uncommitted, destroyed nodes
1532-
if self.db.destroyednodes.has_key(self.classname):
1533-
for nodeid in self.db.destroyednodes[self.classname].keys():
1534-
if db.has_key(nodeid):
1535-
res.remove(nodeid)
1537+
# remove the uncommitted, destroyed nodes
1538+
if self.db.destroyednodes.has_key(self.classname):
1539+
for nodeid in self.db.destroyednodes[self.classname].keys():
1540+
if db.has_key(nodeid):
1541+
res.remove(nodeid)
15361542

1543+
# check retired flag
1544+
if retired is False or retired is True:
1545+
l = []
1546+
for nodeid in res:
1547+
node = self.db.getnode(self.classname, nodeid, db)
1548+
is_ret = node.has_key(self.db.RETIRED_FLAG)
1549+
if retired == is_ret:
1550+
l.append(nodeid)
1551+
res = l
1552+
finally:
1553+
if must_close:
1554+
db.close()
15371555
return res
15381556

15391557
def filter(self, search_matches, filterspec, sort=(None,None),

roundup/backends/back_metakit.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.99 2006-01-20 02:40:56 richard Exp $
1+
# $Id: back_metakit.py,v 1.100 2006-01-23 05:24:33 richard Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -1156,14 +1156,18 @@ def list(self):
11561156
l.append(str(row.id))
11571157
return l
11581158

1159-
def getnodeids(self):
1159+
def getnodeids(self, retired=None):
11601160
''' Retrieve all the ids of the nodes for a particular Class.
11611161
11621162
Set retired=None to get all nodes. Otherwise it'll get all the
11631163
retired or non-retired nodes, depending on the flag.
11641164
'''
11651165
l = []
1166-
for row in self.getview():
1166+
if retired is False or retired is True:
1167+
result = self.getview().select(_isdel=retired)
1168+
else:
1169+
result = self.getview()
1170+
for row in result:
11671171
l.append(str(row.id))
11681172
return l
11691173

test/db_test_base.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.62 2006-01-13 01:18:07 richard Exp $
18+
# $Id: db_test_base.py,v 1.63 2006-01-23 05:24:33 richard Exp $
1919

20-
import unittest, os, shutil, errno, imp, sys, time, pprint
20+
import unittest, os, shutil, errno, imp, sys, time, pprint, sets
2121

2222
from roundup.hyperdb import String, Password, Link, Multilink, Date, \
2323
Interval, DatabaseError, Boolean, Number, Node
@@ -398,18 +398,36 @@ def testRetire(self):
398398
self.db.issue.create(title="spam", status='1')
399399
b = self.db.status.get('1', 'name')
400400
a = self.db.status.list()
401+
nodeids = self.db.status.getnodeids()
401402
self.db.status.retire('1')
403+
others = nodeids[:]
404+
others.remove('1')
405+
406+
self.assertEqual(sets.Set(self.db.status.getnodeids()),
407+
sets.Set(nodeids))
408+
self.assertEqual(sets.Set(self.db.status.getnodeids(retired=True)),
409+
sets.Set(['1']))
410+
self.assertEqual(sets.Set(self.db.status.getnodeids(retired=False)),
411+
sets.Set(others))
412+
413+
self.assert_(self.db.status.is_retired('1'))
414+
402415
# make sure the list is different
403416
self.assertNotEqual(a, self.db.status.list())
417+
404418
# can still access the node if necessary
405419
self.assertEqual(self.db.status.get('1', 'name'), b)
406420
self.assertRaises(IndexError, self.db.status.set, '1', name='hello')
407421
self.db.commit()
422+
self.assert_(self.db.status.is_retired('1'))
408423
self.assertEqual(self.db.status.get('1', 'name'), b)
409424
self.assertNotEqual(a, self.db.status.list())
425+
410426
# try to restore retired node
411427
self.db.status.restore('1')
412428

429+
self.assert_(not self.db.status.is_retired('1'))
430+
413431
def testCacheCreateSet(self):
414432
self.db.issue.create(title="spam", status='1')
415433
a = self.db.issue.get('1', 'title')

0 commit comments

Comments
 (0)