[apycotlib] use new http_upload for uploading logs (closes #3241603)
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 06 Aug 2013 09:57:26 +0200
changeset 1433 6c8893df6244
parent 1432 71952d5c0bfd
child 1434 a9f785f79a3c
[apycotlib] use new http_upload for uploading logs (closes #3241603) this avoids issues with character encoding and is better for big files.
_apycotlib/writer.py
--- a/_apycotlib/writer.py	Fri Nov 22 16:30:06 2013 +0100
+++ b/_apycotlib/writer.py	Tue Aug 06 09:57:26 2013 +0200
@@ -111,6 +111,12 @@
         self._logs = []
         self._logs_sent = 0
 
+    def target_eid(self):
+        return self._url.rsplit('/',1)[-1]
+
+    def instance_url(self):
+        return '{0}/'.format(self._url.rsplit('/',1)[0])
+
     def start(self):
         pass
 
@@ -144,8 +150,13 @@
     def refresh_log(self):
         log = self._logs
         if self._logs_sent < len(log):
-            self._cnxh.http_post(self._url, vid='set_attributes',
-                                 log=u'\n'.join(log))
+            files = {'log': ('file', u'\n'.join(log))}
+            self._cnxh.http_post(self.instance_url() +
+                    'file-upload',
+                    files=files,
+                    eid=self.target_eid(),
+                    is_execution_log='',
+                    _cw_fields='eid,is_execution_log,log')
             self._log_sent = len(log)
 
 
@@ -171,9 +182,17 @@
 
     def end(self, status):
         """Register the given checker as closed with status <status>"""
+        if self._logs:
+            files = {'log': ('file', u'\n'.join(self._logs))}
+            self._cnxh.http_post(self.instance_url() +
+                    'file-upload',
+                    files=files,
+                    eid=self.target_eid(),
+                    is_execution_log='',
+                    _cw_fields='eid,is_execution_log,log')
         self._cnxh.http_post(self._url, vid='set_attributes',
-                             status=self._unicode(status), endtime=datetime.now(),
-                             log=u'\n'.join(self._logs),)
+                             status=self._unicode(status),
+                             endtime=datetime.now(),)
 
 
 class TestDataWriter(BaseDataWriter):