Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 844:982a5abb01ea maint-0.4
[SF#571170] gdbm deadlock
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 10 Jul 2002 06:30:47 +0000 |
| parents | 4409798dfa15 |
| children | b3db3c26d7ad |
comparison
equal
deleted
inserted
replaced
| 816:f75aa15caa7d | 844:982a5abb01ea |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: hyperdb.py,v 1.69 2002-06-17 23:15:29 richard Exp $ | 18 # $Id: hyperdb.py,v 1.69.2.1 2002-07-10 06:30:47 richard Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Hyperdatabase implementation, especially field types. | 21 Hyperdatabase implementation, especially field types. |
| 22 """ | 22 """ |
| 23 | 23 |
| 767 'keyvalue' matches one of the values for the key property among | 767 'keyvalue' matches one of the values for the key property among |
| 768 the nodes in this class, the matching node's id is returned; | 768 the nodes in this class, the matching node's id is returned; |
| 769 otherwise a KeyError is raised. | 769 otherwise a KeyError is raised. |
| 770 """ | 770 """ |
| 771 cldb = self.db.getclassdb(self.classname) | 771 cldb = self.db.getclassdb(self.classname) |
| 772 for nodeid in self.db.getnodeids(self.classname, cldb): | 772 try: |
| 773 node = self.db.getnode(self.classname, nodeid, cldb) | 773 for nodeid in self.db.getnodeids(self.classname, cldb): |
| 774 if node.has_key(self.db.RETIRED_FLAG): | 774 node = self.db.getnode(self.classname, nodeid, cldb) |
| 775 continue | 775 if node.has_key(self.db.RETIRED_FLAG): |
| 776 if node[self.key] == keyvalue: | 776 continue |
| 777 return nodeid | 777 if node[self.key] == keyvalue: |
| 778 return nodeid | |
| 779 finally: | |
| 780 cldb.close() | |
| 778 raise KeyError, keyvalue | 781 raise KeyError, keyvalue |
| 779 | 782 |
| 780 # XXX: change from spec - allows multiple props to match | 783 # XXX: change from spec - allows multiple props to match |
| 781 def find(self, **propspec): | 784 def find(self, **propspec): |
| 782 """Get the ids of nodes in this class which link to a given node. | 785 """Get the ids of nodes in this class which link to a given node. |
| 799 raise ValueError, '%s has no node %s'%(prop.classname, nodeid) | 802 raise ValueError, '%s has no node %s'%(prop.classname, nodeid) |
| 800 | 803 |
| 801 # ok, now do the find | 804 # ok, now do the find |
| 802 cldb = self.db.getclassdb(self.classname) | 805 cldb = self.db.getclassdb(self.classname) |
| 803 l = [] | 806 l = [] |
| 804 for id in self.db.getnodeids(self.classname, db=cldb): | 807 try: |
| 805 node = self.db.getnode(self.classname, id, db=cldb) | 808 for id in self.db.getnodeids(self.classname, db=cldb): |
| 806 if node.has_key(self.db.RETIRED_FLAG): | 809 node = self.db.getnode(self.classname, id, db=cldb) |
| 807 continue | 810 if node.has_key(self.db.RETIRED_FLAG): |
| 808 for propname, nodeid in propspec: | |
| 809 # can't test if the node doesn't have this property | |
| 810 if not node.has_key(propname): | |
| 811 continue | 811 continue |
| 812 prop = self.properties[propname] | 812 for propname, nodeid in propspec: |
| 813 property = node[propname] | 813 # can't test if the node doesn't have this property |
| 814 if isinstance(prop, Link) and nodeid == property: | 814 if not node.has_key(propname): |
| 815 l.append(id) | 815 continue |
| 816 elif isinstance(prop, Multilink) and nodeid in property: | 816 prop = self.properties[propname] |
| 817 l.append(id) | 817 property = node[propname] |
| 818 if isinstance(prop, Link) and nodeid == property: | |
| 819 l.append(id) | |
| 820 elif isinstance(prop, Multilink) and nodeid in property: | |
| 821 l.append(id) | |
| 822 finally: | |
| 823 cldb.close() | |
| 818 return l | 824 return l |
| 819 | 825 |
| 820 def stringFind(self, **requirements): | 826 def stringFind(self, **requirements): |
| 821 """Locate a particular node by matching a set of its String | 827 """Locate a particular node by matching a set of its String |
| 822 properties in a caseless search. | 828 properties in a caseless search. |
| 830 if isinstance(not prop, String): | 836 if isinstance(not prop, String): |
| 831 raise TypeError, "'%s' not a String property"%propname | 837 raise TypeError, "'%s' not a String property"%propname |
| 832 requirements[propname] = requirements[propname].lower() | 838 requirements[propname] = requirements[propname].lower() |
| 833 l = [] | 839 l = [] |
| 834 cldb = self.db.getclassdb(self.classname) | 840 cldb = self.db.getclassdb(self.classname) |
| 835 for nodeid in self.db.getnodeids(self.classname, cldb): | 841 try: |
| 836 node = self.db.getnode(self.classname, nodeid, cldb) | 842 for nodeid in self.db.getnodeids(self.classname, cldb): |
| 837 if node.has_key(self.db.RETIRED_FLAG): | 843 node = self.db.getnode(self.classname, nodeid, cldb) |
| 838 continue | 844 if node.has_key(self.db.RETIRED_FLAG): |
| 839 for key, value in requirements.items(): | 845 continue |
| 840 if node[key] and node[key].lower() != value: | 846 for key, value in requirements.items(): |
| 841 break | 847 if node[key] and node[key].lower() != value: |
| 842 else: | 848 break |
| 843 l.append(nodeid) | 849 else: |
| 850 l.append(nodeid) | |
| 851 finally: | |
| 852 cldb.close() | |
| 844 return l | 853 return l |
| 845 | 854 |
| 846 def list(self): | 855 def list(self): |
| 847 """Return a list of the ids of the active nodes in this class.""" | 856 """Return a list of the ids of the active nodes in this class.""" |
| 848 l = [] | 857 l = [] |
| 849 cn = self.classname | 858 cn = self.classname |
| 850 cldb = self.db.getclassdb(cn) | 859 cldb = self.db.getclassdb(cn) |
| 851 for nodeid in self.db.getnodeids(cn, cldb): | 860 try: |
| 852 node = self.db.getnode(cn, nodeid, cldb) | 861 for nodeid in self.db.getnodeids(cn, cldb): |
| 853 if node.has_key(self.db.RETIRED_FLAG): | 862 node = self.db.getnode(cn, nodeid, cldb) |
| 854 continue | 863 if node.has_key(self.db.RETIRED_FLAG): |
| 855 l.append(nodeid) | 864 continue |
| 865 l.append(nodeid) | |
| 866 finally: | |
| 867 cldb.close() | |
| 856 l.sort() | 868 l.sort() |
| 857 return l | 869 return l |
| 858 | 870 |
| 859 # XXX not in spec | 871 # XXX not in spec |
| 860 def filter(self, search_matches, filterspec, sort, group, | 872 def filter(self, search_matches, filterspec, sort, group, |
| 913 filterspec = l | 925 filterspec = l |
| 914 | 926 |
| 915 # now, find all the nodes that are active and pass filtering | 927 # now, find all the nodes that are active and pass filtering |
| 916 l = [] | 928 l = [] |
| 917 cldb = self.db.getclassdb(cn) | 929 cldb = self.db.getclassdb(cn) |
| 918 for nodeid in self.db.getnodeids(cn, cldb): | 930 try: |
| 919 node = self.db.getnode(cn, nodeid, cldb) | 931 for nodeid in self.db.getnodeids(cn, cldb): |
| 920 if node.has_key(self.db.RETIRED_FLAG): | 932 node = self.db.getnode(cn, nodeid, cldb) |
| 921 continue | 933 if node.has_key(self.db.RETIRED_FLAG): |
| 922 # apply filter | 934 continue |
| 923 for t, k, v in filterspec: | 935 # apply filter |
| 924 # this node doesn't have this property, so reject it | 936 for t, k, v in filterspec: |
| 925 if not node.has_key(k): break | 937 # this node doesn't have this property, so reject it |
| 926 | 938 if not node.has_key(k): break |
| 927 if t == 0 and node[k] not in v: | 939 |
| 928 # link - if this node'd property doesn't appear in the | 940 if t == 0 and node[k] not in v: |
| 929 # filterspec's nodeid list, skip it | 941 # link - if this node'd property doesn't appear in the |
| 930 break | 942 # filterspec's nodeid list, skip it |
| 931 elif t == 1: | 943 break |
| 932 # multilink - if any of the nodeids required by the | 944 elif t == 1: |
| 933 # filterspec aren't in this node's property, then skip | 945 # multilink - if any of the nodeids required by the |
| 934 # it | 946 # filterspec aren't in this node's property, then skip |
| 935 for value in v: | 947 # it |
| 936 if value not in node[k]: | 948 for value in v: |
| 937 break | 949 if value not in node[k]: |
| 938 else: | 950 break |
| 939 continue | 951 else: |
| 940 break | 952 continue |
| 941 elif t == 2 and (node[k] is None or not v.search(node[k])): | 953 break |
| 942 # RE search | 954 elif t == 2 and (node[k] is None or not v.search(node[k])): |
| 943 break | 955 # RE search |
| 944 elif t == 6 and node[k] != v: | 956 break |
| 945 # straight value comparison for the other types | 957 elif t == 6 and node[k] != v: |
| 946 break | 958 # straight value comparison for the other types |
| 947 else: | 959 break |
| 948 l.append((nodeid, node)) | 960 else: |
| 961 l.append((nodeid, node)) | |
| 962 finally: | |
| 963 cldb.close() | |
| 949 l.sort() | 964 l.sort() |
| 950 | 965 |
| 951 # filter based on full text search | 966 # filter based on full text search |
| 952 if search_matches is not None: | 967 if search_matches is not None: |
| 953 k = [] | 968 k = [] |
| 1167 cl.create(name=options[i], order=i) | 1182 cl.create(name=options[i], order=i) |
| 1168 return hyperdb.Link(name) | 1183 return hyperdb.Link(name) |
| 1169 | 1184 |
| 1170 # | 1185 # |
| 1171 # $Log: not supported by cvs2svn $ | 1186 # $Log: not supported by cvs2svn $ |
| 1187 # Revision 1.69 2002/06/17 23:15:29 richard | |
| 1188 # Can debug to stdout now | |
| 1189 # | |
| 1172 # Revision 1.68 2002/06/11 06:52:03 richard | 1190 # Revision 1.68 2002/06/11 06:52:03 richard |
| 1173 # . #564271 ] find() and new properties | 1191 # . #564271 ] find() and new properties |
| 1174 # | 1192 # |
| 1175 # Revision 1.67 2002/06/11 05:02:37 richard | 1193 # Revision 1.67 2002/06/11 05:02:37 richard |
| 1176 # . #565979 ] code error in hyperdb.Class.find | 1194 # . #565979 ] code error in hyperdb.Class.find |
