[apycotlib] make cnxh attribute from writer public
authorPaul Tonelli <paul.tonelli@logilab.fr>
Mon, 24 Mar 2014 10:17:30 +0100
changeset 1477 c91d4e6d72fd
parent 1476 419c81116273
child 1478 0f8d3902bb11
[apycotlib] make cnxh attribute from writer public the connection handler is used directly, for example to get the cubicweb instance url.
_apycotlib/atest.py
_apycotlib/narvalactions.py
_apycotlib/writer.py
test/unittest_preprocessors.py
--- a/_apycotlib/atest.py	Tue Apr 22 12:33:16 2014 +0200
+++ b/_apycotlib/atest.py	Mon Mar 24 10:17:30 2014 +0100
@@ -112,8 +112,8 @@
         try:
             return self._configs[pe['eid']]
         except KeyError:
-            tconfig_url = self.writer._cnxh.instance_url + str(self.tconfig['eid'])
-            config = self.writer._cnxh.http_get(tconfig_url,
+            tconfig_url = self.writer.cnxh.instance_url + str(self.tconfig['eid'])
+            config = self.writer.cnxh.http_get(tconfig_url,
                                                 vid='apycot.get_configuration',
                                                 environment=pe['eid'])[0]
             self._configs[pe['eid']] = config
--- a/_apycotlib/narvalactions.py	Tue Apr 22 12:33:16 2014 +0200
+++ b/_apycotlib/narvalactions.py	Mon Mar 24 10:17:30 2014 +0100
@@ -17,8 +17,8 @@
         self.test.clean()
 
 def install_environment(test):
-    texec_url = test.writer._cnxh.instance_url + str(test.texec['eid'])
-    data = test.writer._cnxh.http_get(texec_url, vid='apycot.get_dependencies')
+    texec_url = test.writer.cnxh.instance_url + str(test.texec['eid'])
+    data = test.writer.cnxh.http_get(texec_url, vid='apycot.get_dependencies')
     for dep in data[0]:
         test.checkout(dep)
         test.call_preprocessor('install', dep)
--- a/_apycotlib/writer.py	Tue Apr 22 12:33:16 2014 +0200
+++ b/_apycotlib/writer.py	Mon Mar 24 10:17:30 2014 +0100
@@ -103,7 +103,7 @@
     """
 
     def __init__(self, cnxh, target_url):
-        self._cnxh = cnxh
+        self.cnxh = cnxh
         # eid of the execution entity
         self._url = target_url
         self._logs = []
@@ -122,7 +122,7 @@
         pass
 
     def set_exec_status(self, status):
-        self._cnxh.http_post(self._url, vid='set_attributes', status=status)
+        self.cnxh.http_post(self._url, vid='set_attributes', status=status)
 
     def execution_info(self, *args, **kwargs):
         msg = self._msg_info(*args, **kwargs)[-1]
@@ -138,7 +138,7 @@
 
     def raw(self, name, value, type=None):
         """give some raw data"""
-        self._cnxh.http_post(self._url, vid='create_subentity',
+        self.cnxh.http_post(self._url, vid='create_subentity',
                              __cwetype__='CheckResultInfo',
                              __cwrel__='for_check',
                              label=self._unicode(name),
@@ -149,7 +149,7 @@
         log = self._logs
         if self._logs_sent < len(log):
             files = {'log': ('file', u'\n'.join(log[self._logs_sent:]) + '\n' )}
-            self._cnxh.http_post(self.instance_url() +
+            self.cnxh.http_post(self.instance_url() +
                     'file-upload',
                     files=files,
                     field='log_file',
@@ -167,12 +167,12 @@
             crname = name
         else:
             crname = getattr(checker, 'id', checker) # may be the checked id
-        data = self._cnxh.http_post(self._url, vid='create_subentity',
+        data = self.cnxh.http_post(self._url, vid='create_subentity',
                                     __cwetype__='CheckResult',
                                     __cwrel__='during_execution',
                                     name=self._unicode(crname), status=u'processing',
                                     starttime=datetime.now())
-        self._url = self._cnxh.instance_url + str(data[0]['eid'])
+        self._url = self.cnxh.instance_url + str(data[0]['eid'])
         if hasattr(checker, 'options'):
             options = ['%s=%s' % (k, v) for k, v in checker.options.iteritems()
                        if k in checker.options_def
@@ -184,7 +184,7 @@
     def end(self, status):
         """Register the given checker as closed with status <status>"""
         self.refresh_log()
-        self._cnxh.http_post(self._url, vid='set_attributes',
+        self.cnxh.http_post(self._url, vid='set_attributes',
                              status=self._unicode(status),
                              endtime=datetime.now(),)
 
@@ -195,7 +195,7 @@
     def make_check_writer(self):
         """Return a CheckDataWriter suitable to write checker log and result within this test"""
         self.refresh_log()
-        return CheckDataWriter(self._cnxh, self._url)
+        return CheckDataWriter(self.cnxh, self._url)
 
     def link_to_revision(self, environment, vcsrepo):
         changeset = vcsrepo.changeset()
@@ -208,10 +208,10 @@
     def end(self, status, archivedir=None):
         """mark the current test as closed (with status <status>) and archive if requested."""
         self.refresh_log()
-        self._cnxh.http_post(self._url, vid='set_attributes',
+        self.cnxh.http_post(self._url, vid='set_attributes',
                             status = self._unicode(status))
         if False and archivedir: # XXX this should be refactored! (mostly) useless as is
-            archive = make_archive_name(self._cnxh.cwinstid, self._url)
+            archive = make_archive_name(self.cnxh.cwinstid, self._url)
             archivefpath = os.path.join(tempfile.gettempdir(), archive)
             tarball = tarfile.open(archivefpath, ARCHIVE_MODE)
             try:
@@ -219,7 +219,7 @@
                 tarball.close()
                 files = {'log': (archive, StringIO(open(archivefpath,
                                  'rb').read()))}
-                self._cnxh.http_post(self.instance_url() + 'file-upload',
+                self.cnxh.http_post(self.instance_url() + 'file-upload',
                                      files=files,
                                      field='execution_archive',
                                      eid=self.target_eid())
--- a/test/unittest_preprocessors.py	Tue Apr 22 12:33:16 2014 +0200
+++ b/test/unittest_preprocessors.py	Mon Mar 24 10:17:30 2014 +0100
@@ -34,7 +34,7 @@
         pass
 
     def __init__(self, msgcfg, msgdep):
-        self._cnxh = FakeCnxh(msgcfg, msgdep)
+        self.cnxh = FakeCnxh(msgcfg, msgdep)
 
 class FileCheckerTest(ApycotBaseTC):
     def start_lgc_tests(self):