mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: add write_file and make_dirs methods
When using a "python job", it's sometimes useful to write a file or create a directory. Instead of giving a wide open access to the os module in the "_run_python" context, this commit adds a write_file and make_dirs methods on the build which is usable in the _run_python eval context.
This commit is contained in:
parent
800691a14c
commit
b98ff23cd9
@ -899,6 +899,25 @@ class runbot_build(models.Model):
|
||||
self._log('readfile', 'exception: %s' % e)
|
||||
return False
|
||||
|
||||
def write_file(self, file, data, mode='w'):
|
||||
file_path = self._path(file)
|
||||
file_dir = os.path.split(file_path)[0]
|
||||
os.makedirs(file_dir, exist_ok=True)
|
||||
try:
|
||||
with open(file_path, mode) as f:
|
||||
f.write(data)
|
||||
except Exception as e:
|
||||
self._log('write_file', 'exception: %s' % e)
|
||||
return False
|
||||
|
||||
def make_dirs(self, dir_path):
|
||||
full_path = self._path(dir_path)
|
||||
try:
|
||||
os.makedirs(full_path, exist_ok=True)
|
||||
except Exception as e:
|
||||
self._log('make_dirs', 'exception: %s' % e)
|
||||
return False
|
||||
|
||||
def build_type_label(self):
|
||||
self.ensure_one()
|
||||
return dict(self.fields_get('build_type', 'selection')['build_type']['selection']).get(self.build_type, self.build_type)
|
||||
|
Loading…
Reference in New Issue
Block a user