|
1 | | -# $Id: back_metakit.py,v 1.74 2004-06-11 15:50:24 wc2so1 Exp $ |
| 1 | +# $Id: back_metakit.py,v 1.75 2004-06-24 07:10:12 richard Exp $ |
2 | 2 | '''Metakit backend for Roundup, originally by Gordon McMillan. |
3 | 3 |
|
4 | 4 | Known Current Bugs: |
|
44 | 44 | from roundup import hyperdb, date, password, roundupdb, security |
45 | 45 | import metakit |
46 | 46 | from sessions_dbm import Sessions, OneTimeKeys |
47 | | -import re, marshal, os, sys, time, calendar |
| 47 | +import re, marshal, os, sys, time, calendar, shutil |
48 | 48 | from indexer_dbm import Indexer |
49 | 49 | import locking |
50 | 50 | from roundup.date import Range |
@@ -496,7 +496,7 @@ def create_inner(self, **propvalues): |
496 | 496 | ndx = self.getview(READWRITE).append(rowdict) |
497 | 497 | propvalues['#ISNEW'] = 1 |
498 | 498 | try: |
499 | | - self.set(str(newid), **propvalues) |
| 499 | + self.set_inner(str(newid), **propvalues) |
500 | 500 | except Exception: |
501 | 501 | self.maxid -= 1 |
502 | 502 | raise |
@@ -801,7 +801,7 @@ def set_inner(self, nodeid, **propvalues): |
801 | 801 | oldnode[key] = oldvalue |
802 | 802 |
|
803 | 803 | # nothing to do? |
804 | | - if not propvalues: |
| 804 | + if not isnew and not propvalues: |
805 | 805 | return propvalues, oldnode |
806 | 806 | if not propvalues.has_key('activity'): |
807 | 807 | row.activity = int(time.time()) |
@@ -1832,6 +1832,29 @@ def gen_filename(self, nodeid): |
1832 | 1832 | os.makedirs(d) |
1833 | 1833 | return os.path.join(d, nm) |
1834 | 1834 |
|
| 1835 | + def export_files(self, dirname, nodeid): |
| 1836 | + ''' Export the "content" property as a file, not csv column |
| 1837 | + ''' |
| 1838 | + source = self.gen_filename(nodeid) |
| 1839 | + x, filename = os.path.split(source) |
| 1840 | + x, subdir = os.path.split(x) |
| 1841 | + dest = os.path.join(dirname, self.classname+'-files', subdir, filename) |
| 1842 | + if not os.path.exists(os.path.dirname(dest)): |
| 1843 | + os.makedirs(os.path.dirname(dest)) |
| 1844 | + shutil.copyfile(source, dest) |
| 1845 | + |
| 1846 | + def import_files(self, dirname, nodeid): |
| 1847 | + ''' Import the "content" property as a file |
| 1848 | + ''' |
| 1849 | + dest = self.gen_filename(nodeid) |
| 1850 | + x, filename = os.path.split(dest) |
| 1851 | + x, subdir = os.path.split(x) |
| 1852 | + source = os.path.join(dirname, self.classname+'-files', subdir, |
| 1853 | + filename) |
| 1854 | + if not os.path.exists(os.path.dirname(dest)): |
| 1855 | + os.makedirs(os.path.dirname(dest)) |
| 1856 | + shutil.copyfile(source, dest) |
| 1857 | + |
1835 | 1858 | def get(self, nodeid, propname, default=_marker, cache=1): |
1836 | 1859 | if propname == 'content': |
1837 | 1860 | poss_msg = 'Possibly an access right configuration problem.' |
|
0 commit comments