mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] various code cleanups
This commit is contained in:
parent
a70e64e976
commit
6109efb122
@ -262,24 +262,24 @@ class runbot_repo(osv.osv):
|
|||||||
def scheduler(self, cr, uid, ids=None, context=None):
|
def scheduler(self, cr, uid, ids=None, context=None):
|
||||||
for repo in self.browse(cr, uid, ids, context=context):
|
for repo in self.browse(cr, uid, ids, context=context):
|
||||||
Build = self.pool['runbot.build']
|
Build = self.pool['runbot.build']
|
||||||
dom = [('repo_id', '=', repo.id)]
|
domain = [('repo_id', '=', repo.id)]
|
||||||
|
|
||||||
# schedule jobs
|
# schedule jobs (transitions testing -> running, kill jobs, ...)
|
||||||
build_ids = Build.search(cr, uid, dom + [('state', 'in', ['testing', 'running'])])
|
build_ids = Build.search(cr, uid, domain + [('state', 'in', ['testing', 'running'])])
|
||||||
Build.schedule(cr, uid, build_ids)
|
Build.schedule(cr, uid, build_ids)
|
||||||
|
|
||||||
# launch new tests
|
# launch new tests
|
||||||
testing = Build.search(cr, uid, dom + [('state', '=', 'testing')], count=True)
|
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')])
|
||||||
while testing < repo.testing:
|
while testing < repo.testing:
|
||||||
# select the next build to process
|
# select the next build to process
|
||||||
pending_ids = Build.search(cr, uid, dom + [('state', '=', 'pending')])
|
pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending')])
|
||||||
if pending_ids:
|
if pending_ids:
|
||||||
pending = Build.browse(cr, uid, pending_ids[0])
|
pending = Build.browse(cr, uid, pending_ids[0])
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
# gather information about currently running builds
|
# gather information about currently running builds
|
||||||
running_ids = Build.search(cr, uid, dom + [('state', '=', 'running')])
|
running_ids = Build.search(cr, uid, domain + [('state', '=', 'running')])
|
||||||
running_len = len(running_ids)
|
running_len = len(running_ids)
|
||||||
running_max = 0
|
running_max = 0
|
||||||
if running_ids:
|
if running_ids:
|
||||||
@ -292,10 +292,10 @@ class runbot_repo(osv.osv):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# compute the number of testing job again
|
# compute the number of testing job again
|
||||||
testing = Build.search(cr, uid, dom + [('state', '=', 'testing')], count=True)
|
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')])
|
||||||
|
|
||||||
# terminate and reap doomed build
|
# terminate and reap doomed build
|
||||||
build_ids = Build.search(cr, uid, dom + [('state', '=', 'running')])
|
build_ids = Build.search(cr, uid, domain + [('state', '=', 'running')])
|
||||||
# sort builds: the last build of each sticky branch then the rest
|
# sort builds: the last build of each sticky branch then the rest
|
||||||
sticky = {}
|
sticky = {}
|
||||||
non_sticky = []
|
non_sticky = []
|
||||||
@ -311,16 +311,16 @@ class runbot_repo(osv.osv):
|
|||||||
Build.reap(cr, uid, build_ids)
|
Build.reap(cr, uid, build_ids)
|
||||||
|
|
||||||
def nginx(self, cr, uid, context=None):
|
def nginx(self, cr, uid, context=None):
|
||||||
v = {}
|
settings = {}
|
||||||
v['port'] = openerp.tools.config['xmlrpc_port']
|
settings['port'] = openerp.tools.config['xmlrpc_port']
|
||||||
nginx_dir = os.path.join(self.root(cr, uid), 'nginx')
|
nginx_dir = os.path.join(self.root(cr, uid), 'nginx')
|
||||||
v['nginx_dir'] = nginx_dir
|
settings['nginx_dir'] = nginx_dir
|
||||||
ids = self.search(cr, uid, [('nginx','=',True)], order='id')
|
ids = self.search(cr, uid, [('nginx','=',True)], order='id')
|
||||||
if ids:
|
if ids:
|
||||||
build_ids = self.pool['runbot.build'].search(cr, uid, [('repo_id','in',ids), ('state','=','running')])
|
build_ids = self.pool['runbot.build'].search(cr, uid, [('repo_id','in',ids), ('state','=','running')])
|
||||||
v['builds'] = self.pool['runbot.build'].browse(cr, uid, build_ids)
|
settings['builds'] = self.pool['runbot.build'].browse(cr, uid, build_ids)
|
||||||
|
|
||||||
nginx_config = self.pool['ir.ui.view'].render(cr, uid, "runbot.nginx_config", v)
|
nginx_config = self.pool['ir.ui.view'].render(cr, uid, "runbot.nginx_config", settings)
|
||||||
mkdirs([nginx_dir])
|
mkdirs([nginx_dir])
|
||||||
open(os.path.join(nginx_dir, 'nginx.conf'),'w').write(nginx_config)
|
open(os.path.join(nginx_dir, 'nginx.conf'),'w').write(nginx_config)
|
||||||
try:
|
try:
|
||||||
@ -333,10 +333,10 @@ class runbot_repo(osv.osv):
|
|||||||
|
|
||||||
def killall(self, cr, uid, ids=None, context=None):
|
def killall(self, cr, uid, ids=None, context=None):
|
||||||
# kill switch
|
# kill switch
|
||||||
bo = self.pool['runbot.build']
|
Build = self.pool['runbot.build']
|
||||||
build_ids = bo.search(cr, uid, [('state', 'not in', ['done', 'pending'])])
|
build_ids = Build.search(cr, uid, [('state', 'not in', ['done', 'pending'])])
|
||||||
bo.terminate(cr, uid, build_ids)
|
Build.terminate(cr, uid, build_ids)
|
||||||
bo.reap(cr, uid, build_ids)
|
Build.reap(cr, uid, build_ids)
|
||||||
|
|
||||||
def cron(self, cr, uid, ids=None, context=None):
|
def cron(self, cr, uid, ids=None, context=None):
|
||||||
ids = self.search(cr, uid, [('auto', '=', True)])
|
ids = self.search(cr, uid, [('auto', '=', True)])
|
||||||
@ -385,6 +385,7 @@ class runbot_build(osv.osv):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
def _get_time(self, cr, uid, ids, field_name, arg, context=None):
|
def _get_time(self, cr, uid, ids, field_name, arg, context=None):
|
||||||
|
"""Return the time taken by the tests"""
|
||||||
r = {}
|
r = {}
|
||||||
for build in self.browse(cr, uid, ids, context=context):
|
for build in self.browse(cr, uid, ids, context=context):
|
||||||
r[build.id] = 0
|
r[build.id] = 0
|
||||||
@ -395,6 +396,7 @@ class runbot_build(osv.osv):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
def _get_age(self, cr, uid, ids, field_name, arg, context=None):
|
def _get_age(self, cr, uid, ids, field_name, arg, context=None):
|
||||||
|
"""Return the time between job start and now"""
|
||||||
r = {}
|
r = {}
|
||||||
for build in self.browse(cr, uid, ids, context=context):
|
for build in self.browse(cr, uid, ids, context=context):
|
||||||
r[build.id] = 0
|
r[build.id] = 0
|
||||||
@ -439,8 +441,8 @@ class runbot_build(osv.osv):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def create(self, cr, uid, values, context=None):
|
def create(self, cr, uid, values, context=None):
|
||||||
bid = super(runbot_build, self).create(cr, uid, values, context=context)
|
build_id = super(runbot_build, self).create(cr, uid, values, context=context)
|
||||||
self.write(cr, uid, [bid], {'sequence' : bid}, context=context)
|
self.write(cr, uid, [build_id], {'sequence' : build_id}, context=context)
|
||||||
|
|
||||||
def reset(self, cr, uid, ids, context=None):
|
def reset(self, cr, uid, ids, context=None):
|
||||||
self.write(cr, uid, ids, { 'state' : 'pending' }, context=context)
|
self.write(cr, uid, ids, { 'state' : 'pending' }, context=context)
|
||||||
@ -452,7 +454,7 @@ class runbot_build(osv.osv):
|
|||||||
_logger.debug(*l)
|
_logger.debug(*l)
|
||||||
|
|
||||||
def list_jobs(self):
|
def list_jobs(self):
|
||||||
jobs = [i for i in dir(self) if i.startswith('job')]
|
jobs = [job for job in dir(self) if job.startswith('job')]
|
||||||
jobs.sort()
|
jobs.sort()
|
||||||
return jobs
|
return jobs
|
||||||
|
|
||||||
@ -522,6 +524,7 @@ class runbot_build(osv.osv):
|
|||||||
openerp.service.db._create_empty_database(dbname)
|
openerp.service.db._create_empty_database(dbname)
|
||||||
|
|
||||||
def cmd(self, cr, uid, ids, context=None):
|
def cmd(self, cr, uid, ids, context=None):
|
||||||
|
"""Return a list describing the command to start the build"""
|
||||||
for build in self.browse(cr, uid, ids, context=context):
|
for build in self.browse(cr, uid, ids, context=context):
|
||||||
# Server
|
# Server
|
||||||
server_path = build.path("openerp-server")
|
server_path = build.path("openerp-server")
|
||||||
@ -534,12 +537,12 @@ class runbot_build(osv.osv):
|
|||||||
|
|
||||||
# modules
|
# modules
|
||||||
if build.repo_id.modules:
|
if build.repo_id.modules:
|
||||||
mods = build.repo_id.modules
|
modules = build.repo_id.modules
|
||||||
else:
|
else:
|
||||||
l = glob.glob(build.path('openerp/addons/*/__init__.py'))
|
l = glob.glob(build.path('openerp/addons/*/__init__.py'))
|
||||||
mods = set([os.path.basename(os.path.dirname(i)) for i in l])
|
modules = set([os.path.basename(os.path.dirname(i)) for i in l])
|
||||||
mods = mods - set(['auth_ldap', 'document_ftp', 'hw_escpos', 'hw_proxy', 'hw_scanner', 'base_gengo', 'website_gengo'])
|
modules = modules - set(['auth_ldap', 'document_ftp', 'hw_escpos', 'hw_proxy', 'hw_scanner', 'base_gengo', 'website_gengo'])
|
||||||
mods = ",".join(list(mods))
|
modules = ",".join(list(modules))
|
||||||
|
|
||||||
# commandline
|
# commandline
|
||||||
cmd = [
|
cmd = [
|
||||||
@ -562,7 +565,7 @@ class runbot_build(osv.osv):
|
|||||||
#self.run_log(cmd, logfile=self.test_all_path)
|
#self.run_log(cmd, logfile=self.test_all_path)
|
||||||
#run(["coverage","html","-d",self.coverage_base_path,"--ignore-errors","--include=*.py"],env={'COVERAGE_FILE': self.coverage_file_path})
|
#run(["coverage","html","-d",self.coverage_base_path,"--ignore-errors","--include=*.py"],env={'COVERAGE_FILE': self.coverage_file_path})
|
||||||
|
|
||||||
return cmd, mods
|
return cmd, modules
|
||||||
|
|
||||||
def spawn(self, cmd, lock_path, log_path, cpu_limit=None, shell=False, showstderr=False):
|
def spawn(self, cmd, lock_path, log_path, cpu_limit=None, shell=False, showstderr=False):
|
||||||
def preexec_fn():
|
def preexec_fn():
|
||||||
@ -586,6 +589,7 @@ class runbot_build(osv.osv):
|
|||||||
return p.pid
|
return p.pid
|
||||||
|
|
||||||
def github_status(self, cr, uid, ids, context=None):
|
def github_status(self, cr, uid, ids, context=None):
|
||||||
|
"""Notify github of failed/successful builds"""
|
||||||
for build in self.browse(cr, uid, ids, context=context):
|
for build in self.browse(cr, uid, ids, context=context):
|
||||||
desc = "runbot build %s" % (build.dest,)
|
desc = "runbot build %s" % (build.dest,)
|
||||||
if build.state == 'testing':
|
if build.state == 'testing':
|
||||||
@ -689,6 +693,7 @@ class runbot_build(osv.osv):
|
|||||||
return self.spawn(cmd, lock_path, log_path, cpu_limit=None, showstderr=True)
|
return self.spawn(cmd, lock_path, log_path, cpu_limit=None, showstderr=True)
|
||||||
|
|
||||||
def force(self, cr, uid, ids, context=None):
|
def force(self, cr, uid, ids, context=None):
|
||||||
|
"""Force a rebuild"""
|
||||||
for build in self.browse(cr, uid, ids, context=context):
|
for build in self.browse(cr, uid, ids, context=context):
|
||||||
max_id = self.search(cr, uid, [('repo_id','=',build.repo_id.id)], order='id desc', limit=1)[0]
|
max_id = self.search(cr, uid, [('repo_id','=',build.repo_id.id)], order='id desc', limit=1)[0]
|
||||||
# Force it now
|
# Force it now
|
||||||
@ -872,9 +877,9 @@ class RunbotController(http.Controller):
|
|||||||
v['branches'] = branches
|
v['branches'] = branches
|
||||||
|
|
||||||
# stats
|
# stats
|
||||||
v['testing'] = build_obj.search(cr, uid, [('repo_id','=',repo.id), ('state','=','testing')], count=True)
|
v['testing'] = build_obj.search_count(cr, uid, [('repo_id','=',repo.id), ('state','=','testing')])
|
||||||
v['running'] = build_obj.search(cr, uid, [('repo_id','=',repo.id), ('state','=','running')], count=True)
|
v['running'] = build_obj.search_count(cr, uid, [('repo_id','=',repo.id), ('state','=','running')])
|
||||||
v['pending'] = build_obj.search(cr, uid, [('repo_id','=',repo.id), ('state','=','pending')], count=True)
|
v['pending'] = build_obj.search_count(cr, uid, [('repo_id','=',repo.id), ('state','=','pending')])
|
||||||
|
|
||||||
v.update({
|
v.update({
|
||||||
'search': search,
|
'search': search,
|
||||||
|
Loading…
Reference in New Issue
Block a user