changeset 39:0c769ba7957c

fixed problem with file creation in RESTwrtie2File
author root@chinagis.mpiwg-berlin.mpg.de
date Wed, 01 Sep 2010 21:01:49 +0200
parents f6d9a3caf986
children f94fc5a51a38
files RestDbInterface.py
diffstat 1 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbInterface.py	Wed Sep 01 19:58:16 2010 +0200
+++ b/RestDbInterface.py	Wed Sep 01 21:01:49 2010 +0200
@@ -762,19 +762,19 @@
 # End for GoogleMaps creation
 
     def RESTwrite2File(self,datadir, name,text):
-#        try:
-            fileid=name
-            if fileid in datadir.objectIds():
-                datadir.manage_delObjects(fileid)
-            newfile=open(name,'w')
-            newfile.write(text)
-            newfile.close()
-            file4Read=open(name,'r')
-            fileInZope=datadir.manage_addFile(id=fileid,file=file4Read)
-            return "Write successful"
-#        except:
-#            return "Could not write"
+        logging.debug("RESTwrite2File datadir=%s name=%s"%(datadir,name))
+        try:
+            import cStringIO as StringIO
+        except:
+            import StringIO
 
+        # make filehandle from string
+        textfile = StringIO.StringIO(text)
+        fileid=name
+        if fileid in datadir.objectIds():
+            datadir.manage_delObjects(fileid)
+        fileInZope=datadir.manage_addFile(id=fileid,file=textfile)
+        return "Write successful"
         
     def manage_editRestDbInterface(self, title=None, connection_id=None,
                      REQUEST=None):