Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 278:a5dabf2430c5
Added database importing and exporting through CSV files.
Uses the csv module from object-craft for exporting if it's available.
Requires the csv module for importing.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 10 Oct 2001 03:54:57 +0000 |
| parents | 1cc866cec608 |
| children | fb1b67a8fd98 |
comparison
equal
deleted
inserted
replaced
| 277:20fed9cad7b4 | 278:a5dabf2430c5 |
|---|---|
| 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.23 2001-10-09 23:58:10 richard Exp $ | 18 # $Id: hyperdb.py,v 1.24 2001-10-10 03:54:57 richard Exp $ |
| 19 | 19 |
| 20 # standard python modules | 20 # standard python modules |
| 21 import cPickle, re, string | 21 import cPickle, re, string |
| 22 | 22 |
| 23 # roundup modules | 23 # roundup modules |
| 213 if key == self.key: | 213 if key == self.key: |
| 214 raise ValueError, 'key property "%s" is required'%key | 214 raise ValueError, 'key property "%s" is required'%key |
| 215 if isinstance(prop, Multilink): | 215 if isinstance(prop, Multilink): |
| 216 propvalues[key] = [] | 216 propvalues[key] = [] |
| 217 else: | 217 else: |
| 218 propvalues[key] = None | 218 propvalues[key] = '' |
| 219 | 219 |
| 220 # convert all data to strings | 220 # convert all data to strings |
| 221 for key, prop in self.properties.items(): | 221 for key, prop in self.properties.items(): |
| 222 if isinstance(prop, Date): | 222 if isinstance(prop, Date): |
| 223 propvalues[key] = propvalues[key].get_tuple() | 223 propvalues[key] = propvalues[key].get_tuple() |
| 803 ''' A convenience wrapper for the given node | 803 ''' A convenience wrapper for the given node |
| 804 ''' | 804 ''' |
| 805 def __init__(self, cl, nodeid): | 805 def __init__(self, cl, nodeid): |
| 806 self.__dict__['cl'] = cl | 806 self.__dict__['cl'] = cl |
| 807 self.__dict__['nodeid'] = nodeid | 807 self.__dict__['nodeid'] = nodeid |
| 808 def keys(self): | 808 def keys(self, protected=1): |
| 809 return self.cl.getprops().keys() | 809 return self.cl.getprops(protected=protected).keys() |
| 810 def values(self, protected=1): | |
| 811 l = [] | |
| 812 for name in self.cl.getprops(protected=protected).keys(): | |
| 813 l.append(self.cl.get(self.nodeid, name)) | |
| 814 return l | |
| 815 def items(self, protected=1): | |
| 816 l = [] | |
| 817 for name in self.cl.getprops(protected=protected).keys(): | |
| 818 l.append((name, self.cl.get(self.nodeid, name))) | |
| 819 return l | |
| 810 def has_key(self, name): | 820 def has_key(self, name): |
| 811 return self.cl.getprops().has_key(name) | 821 return self.cl.getprops().has_key(name) |
| 812 def __getattr__(self, name): | 822 def __getattr__(self, name): |
| 813 if self.__dict__.has_key(name): | 823 if self.__dict__.has_key(name): |
| 814 return self.__dict__['name'] | 824 return self.__dict__[name] |
| 815 try: | 825 try: |
| 816 return self.cl.get(self.nodeid, name) | 826 return self.cl.get(self.nodeid, name) |
| 817 except KeyError, value: | 827 except KeyError, value: |
| 818 raise AttributeError, str(value) | 828 raise AttributeError, str(value) |
| 819 def __getitem__(self, name): | 829 def __getitem__(self, name): |
| 837 cl.create(name=option[i], order=i) | 847 cl.create(name=option[i], order=i) |
| 838 return hyperdb.Link(name) | 848 return hyperdb.Link(name) |
| 839 | 849 |
| 840 # | 850 # |
| 841 # $Log: not supported by cvs2svn $ | 851 # $Log: not supported by cvs2svn $ |
| 852 # Revision 1.23 2001/10/09 23:58:10 richard | |
| 853 # Moved the data stringification up into the hyperdb.Class class' get, set | |
| 854 # and create methods. This means that the data is also stringified for the | |
| 855 # journal call, and removes duplication of code from the backends. The | |
| 856 # backend code now only sees strings. | |
| 857 # | |
| 842 # Revision 1.22 2001/10/09 07:25:59 richard | 858 # Revision 1.22 2001/10/09 07:25:59 richard |
| 843 # Added the Password property type. See "pydoc roundup.password" for | 859 # Added the Password property type. See "pydoc roundup.password" for |
| 844 # implementation details. Have updated some of the documentation too. | 860 # implementation details. Have updated some of the documentation too. |
| 845 # | 861 # |
| 846 # Revision 1.21 2001/10/05 02:23:24 richard | 862 # Revision 1.21 2001/10/05 02:23:24 richard |
