summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ick2/__init__.py9
-rw-r--r--ick2/client.py41
2 files changed, 49 insertions, 1 deletions
diff --git a/ick2/__init__.py b/ick2/__init__.py
index 5b312e7..95f3914 100644
--- a/ick2/__init__.py
+++ b/ick2/__init__.py
@@ -52,4 +52,11 @@ from .controllerapi import (
from .blobapi import BlobAPI
from .blob_store import BlobStore
-from .client import HttpAPI, HttpError, ControllerClient, BlobClient
+from .client import HttpAPI, HttpError, ControllerClient, BlobClient, Reporter
+from .actionenvs import (
+ ActionEnvironment,
+ HostEnvironment,
+ ChrootEnvironment,
+ ContainerEnvironment,
+)
+from .workspace import WorkspaceArea, Workspace
diff --git a/ick2/client.py b/ick2/client.py
index bf708ae..99b8487 100644
--- a/ick2/client.py
+++ b/ick2/client.py
@@ -15,6 +15,7 @@
import json
import logging
+import time
import requests
@@ -170,6 +171,46 @@ class ControllerClient:
self._api.post(url, headers=headers, body=body)
+class Reporter: # pragma: no cover
+
+ def __init__(self, api, work):
+ self._api = api
+ self._work = dict(work)
+
+ def report(self, exit_code, stdout, stderr):
+ result = dict(self._work)
+ result['exit_code'] = exit_code
+ result['stdout'] = self.make_string(stdout)
+ result['stderr'] = self.make_string(stderr)
+ for key in result:
+ logging.debug('Reporter: result[%r]=%r', key, result[key])
+ self._api.report_work(result)
+
+ def make_string(self, thing):
+ if isinstance(thing, bytes):
+ return thing.decode('UTF-8')
+ if isinstance(thing, str):
+ return thing
+ if thing is None:
+ return thing
+ return repr(thing)
+
+ def get_work_result(self, work):
+ return {
+ 'build_id': work['build_id'],
+ 'worker': work['worker'],
+ 'project': work['project'],
+ 'pipeline': work['pipeline'],
+ 'stdout': '',
+ 'stderr': '',
+ 'exit_code': None,
+ 'timestamp': self.now(),
+ }
+
+ def now(self):
+ return time.strftime('%Y-%m-%dT%H:%M:%S')
+
+
class BlobClient:
def __init__(self):