comparison roundup/hyperdb.py @ 2496:682eefe8ef23

WIP
author Richard Jones <richard@users.sourceforge.net>
date Thu, 24 Jun 2004 06:39:07 +0000
parents c5e5e9e176d2
children 091711fb2f8c
comparison
equal deleted inserted replaced
2494:ea7fb2f416db 2496:682eefe8ef23
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.98 2004-05-18 21:53:18 richard Exp $ 18 # $Id: hyperdb.py,v 1.99 2004-06-24 06:39:06 richard Exp $
19 19
20 """Hyperdatabase implementation, especially field types. 20 """Hyperdatabase implementation, especially field types.
21 """ 21 """
22 __docformat__ = 'restructuredtext' 22 __docformat__ = 'restructuredtext'
23 23
24 # standard python modules 24 # standard python modules
25 import sys, os, time, re 25 import sys, os, time, re, shutil
26 26
27 # roundup modules 27 # roundup modules
28 import date, password 28 import date, password
29 29
30 # configure up the DEBUG and TRACE captures 30 # configure up the DEBUG and TRACE captures
585 """ 585 """
586 try: 586 try:
587 return self.get(nodeid, propname) 587 return self.get(nodeid, propname)
588 except IndexError: 588 except IndexError:
589 return default 589 return default
590
591 def export_propnames(self):
592 '''List the property names for export from this Class.'''
593 propnames = self.getprops().keys()
594 propnames.sort()
595 return propnames
596
590 597
591 class HyperdbValueError(ValueError): 598 class HyperdbValueError(ValueError):
592 ''' Error converting a raw value into a Hyperdb value ''' 599 ''' Error converting a raw value into a Hyperdb value '''
593 pass 600 pass
594 601
756 763
757 class FileClass: 764 class FileClass:
758 ''' A class that requires the "content" property and stores it on 765 ''' A class that requires the "content" property and stores it on
759 disk. 766 disk.
760 ''' 767 '''
761 pass 768 def export_propnames(self):
769 ''' Don't export the "content" property
770 '''
771 propnames = self.getprops().keys()
772 propnames.remove('content')
773 propnames.sort()
774 return propnames
775
776 def export_files(self, dirname, nodeid):
777 ''' Export the "content" property as a file, not csv column
778 '''
779 source = self.db.filename(self.classname, nodeid)
780 x, filename = os.path.split(source)
781 x, subdir = os.path.split(x)
782 dest = os.path.join(dirname, self.classname+'-files', subdir, filename)
783 if not os.path.exists(os.path.dirname(dest)):
784 os.makedirs(os.path.dirname(dest))
785 shutil.copyfile(source, dest)
786
787 def import_files(self, dirname, nodeid):
788 ''' Import the "content" property as a file
789 '''
790 dest = self.db.filename(self.classname, nodeid)
791 x, filename = os.path.split(dest)
792 x, subdir = os.path.split(x)
793 source = os.path.join(dirname, self.classname+'-files', subdir,
794 filename)
795 if not os.path.exists(os.path.dirname(dest)):
796 os.makedirs(os.path.dirname(dest))
797 shutil.copyfile(source, dest)
762 798
763 class Node: 799 class Node:
764 ''' A convenience wrapper for the given node 800 ''' A convenience wrapper for the given node
765 ''' 801 '''
766 def __init__(self, cl, nodeid, cache=1): 802 def __init__(self, cl, nodeid, cache=1):

Roundup Issue Tracker: http://roundup-tracker.org/