[apycotlib] update the refresh-log method using the new append-to-file controller
authorPaul Tonelli <paul.tonelli@logilab.fr>
Wed, 16 Apr 2014 17:57:25 +0200
changeset 1487 c9c9ccc9fd07
parent 1486 882e316ee83b
child 1488 05ddbef90877
[apycotlib] update the refresh-log method using the new append-to-file controller
_apycotlib/writer.py
--- a/_apycotlib/writer.py	Fri Apr 25 11:07:13 2014 +0200
+++ b/_apycotlib/writer.py	Wed Apr 16 17:57:25 2014 +0200
@@ -106,6 +106,7 @@
         self.cnxh = cnxh
         # eid of the execution entity
         self._url = target_url
+        self._log_file_eid = None
         self._logs = []
         self._logs_sent = 0
 
@@ -148,13 +149,18 @@
     def refresh_log(self):
         log = self._logs
         if self._logs_sent < len(log):
-            files = {'data': ('log_file.txt', u'\n'.join(log[self._logs_sent:]) + '\n' )}
-            self.cnxh.http_post(self.instance_url() +
-                    'file-upload',
-                    rname='log_file',
-                    files=files,
-                    eid=self.target_eid()
-                    )
+            files = {'data': ('dummy', u'\n'.join(log[self._logs_sent:]) + '\n' )}
+            if not self._log_file_eid:
+                data = self.cnxh.http_post(self._url, vid='create_subentity',
+                                            __cwetype__='File',
+                                            __cwrel__='reverse_log_file',
+                                            data_name=u'log_file.txt',
+                                            data_encoding='utf-8')[0]
+                self._log_file_eid = data['eid']
+            self.cnxh.http_post(url=self.instance_url() + '/narval-file-append',
+                                files=files,
+                                eid=self._log_file_eid)
+
             self._logs_sent = len(log)