mirror of
https://github.com/odoo/runbot.git
synced 2025-03-19 17:35:45 +07:00

Multibuild can create generate a lots of checkout, especially for small and fast jobs, which can overload runbot discs since we are trying not to clean build immediatly. (To ease bug fix and allow wake up) This commit proposes to store source on a single place, so that docker can add them as ro volume in the build directory. The checkout is also moved to the installs jobs, so that builds containing only create builds steps won't checkout the sources. This change implies to use --addons-path correctly, since odoo and enterprise addons wont be merged in the same repo anymore. This will allow to test addons a dev will do, with a closer command line. This implies to change the code structure a litle, some changes where made to remove no-so-usefull fields on build, and some hard-coded logic (manifest_names and server_names) are now stored on repo instead. This changes implies that a build CANNOT write in his sources. It shouldn't be the case, but it means that runbot cannot be tested on runbot untill datas are written elsewhere than in static. Other possibilities are possible, like bind mounting the sources in the build directory instead of adding ro volumes in docker. Unfortunately, this needs to give access to mount as sudo for runbot user and changes docjker config to allow mounts in volumes which is not the case by default. A plus of this solution would be to be able to make an overlay mount.
103 lines
2.4 KiB
Python
103 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import contextlib
|
|
import fcntl
|
|
import itertools
|
|
import logging
|
|
import os
|
|
import psycopg2
|
|
import re
|
|
import socket
|
|
import time
|
|
|
|
from collections import OrderedDict
|
|
|
|
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Commit():
|
|
def __init__(self, repo, sha):
|
|
self.repo = repo
|
|
self.sha = sha
|
|
|
|
def _source_path(self, *path):
|
|
return self.repo._source_path(self.sha, *path)
|
|
|
|
def export(self):
|
|
return self.repo._git_export(self.sha)
|
|
|
|
def __str__(self):
|
|
return '%s:%s' % (self.repo.short_name, self.sha)
|
|
|
|
def fqdn():
|
|
return socket.getfqdn()
|
|
|
|
|
|
def time2str(t):
|
|
return time.strftime(DEFAULT_SERVER_DATETIME_FORMAT, t)
|
|
|
|
|
|
def dt2time(datetime):
|
|
"""Convert datetime to time"""
|
|
return time.mktime(time.strptime(datetime, DEFAULT_SERVER_DATETIME_FORMAT))
|
|
|
|
|
|
def now():
|
|
return time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
|
|
|
|
|
def grep(filename, string):
|
|
if os.path.isfile(filename):
|
|
return open(filename).read().find(string) != -1
|
|
return False
|
|
|
|
|
|
def uniq_list(l):
|
|
return OrderedDict.fromkeys(l).keys()
|
|
|
|
|
|
def flatten(list_of_lists):
|
|
return list(itertools.chain.from_iterable(list_of_lists))
|
|
|
|
|
|
def rfind(filename, pattern):
|
|
"""Determine in something in filename matches the pattern"""
|
|
if os.path.isfile(filename):
|
|
regexp = re.compile(pattern, re.M)
|
|
with open(filename, 'r') as f:
|
|
if regexp.findall(f.read()):
|
|
return True
|
|
return False
|
|
|
|
|
|
def s2human(time):
|
|
"""Convert a time in second into an human readable string"""
|
|
for delay, desc in [(86400, 'd'),(3600, 'h'),(60, 'm')]:
|
|
if time >= delay:
|
|
return str(int(time / delay)) + desc
|
|
return str(int(time)) + "s"
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def local_pgadmin_cursor():
|
|
cnx = None
|
|
try:
|
|
cnx = psycopg2.connect("dbname=postgres")
|
|
cnx.autocommit = True # required for admin commands
|
|
yield cnx.cursor()
|
|
finally:
|
|
if cnx:
|
|
cnx.close()
|
|
|
|
def get_py_version(build):
|
|
"""return the python name to use from build instance"""
|
|
executables = [ 'odoo-bin', 'openerp-server' ]
|
|
for server_path in map(build._path, executables):
|
|
if os.path.exists(server_path):
|
|
with open(server_path, 'r') as f:
|
|
if f.readline().strip().endswith('python3'):
|
|
return 'python3'
|
|
return 'python'
|