From 800691a14cdcefc21fb57a2d432e807137aa8976 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 11 Jun 2019 14:55:18 +0200 Subject: [PATCH] [IMP] runbot: add a mode parameter to readfile When using the read_method in a "python job", it's sometimes needed to read a file in binary mode. With this commit, the mode can be specified when calling the method. --- runbot/models/build.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runbot/models/build.py b/runbot/models/build.py index 637196de..70bad943 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -890,12 +890,13 @@ class runbot_build(models.Model): new_step = step_ids[next_index] # job to do, state is job_state (testing or running) return {'active_step': new_step.id, 'local_state': new_step._step_state()} - def read_file(self, file): + def read_file(self, file, mode='r'): file_path = self._path(file) try: - with open(file_path, 'r') as f: + with open(file_path, mode) as f: return f.read() - except: + except Exception as e: + self._log('readfile', 'exception: %s' % e) return False def build_type_label(self):