diff options
Diffstat (limited to 'lorrycontroller/givemejob.py')
-rw-r--r-- | lorrycontroller/givemejob.py | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py index 755def0..0d9e6ab 100644 --- a/lorrycontroller/givemejob.py +++ b/lorrycontroller/givemejob.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Codethink Limited +# Copyright (C) 2014-2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,13 +14,9 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import collections import logging -import re -import time import bottle -import cliapp import lorrycontroller @@ -40,8 +36,7 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): now = statedb.get_current_time() for lorry_info in lorry_infos: if self.ready_to_run(lorry_info, now): - self.create_repository_in_local_trove( - statedb, lorry_info) + self.create_repository(statedb, lorry_info) if lorry_info['from_trovehost']: self.copy_repository_metadata(statedb, lorry_info) self.give_job_to_minion(statedb, lorry_info, now) @@ -67,6 +62,13 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): due = lorry_info['last_run'] + lorry_info['interval'] return (lorry_info['running_job'] is None and due <= now) + def create_repository(self, statedb, lorry_info): + api = self.app_settings['git-server-type'] + if api == 'gitano': + self.create_repository_in_local_trove(statedb, lorry_info) + elif api == 'gerrit': + self.create_gerrit_project(statedb, lorry_info) + def create_repository_in_local_trove(self, statedb, lorry_info): # Create repository on local Trove. If it fails, assume # it failed because the repository already existed, and @@ -82,12 +84,33 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): else: logging.info('Created %s on local repo', lorry_info['path']) + def create_gerrit_project(self, statedb, lorry_info): + '''Create a project in the local Gerrit server. + + The 'lorry' user must have createProject capability in the Gerrit. + + ''' + gerrit = lorrycontroller.Gerrit( + host='localhost', user='lorry') + project_name = lorry_info['path'] + + if gerrit.has_project(project_name): + logging.info('Project %s exists in local Gerrit already.', + project_name) + else: + gerrit.create_project(project_name) + logging.info('Created %s project in local Gerrit.', project_name) + def copy_repository_metadata(self, statedb, lorry_info): '''Copy project.head and project.description to the local Trove.''' assert lorry_info['from_trovehost'] assert lorry_info['from_path'] + if self.app_settings['git-server-type'] != 'gitano': + # FIXME: would be good to have this info in Gerrit too + return + remote = lorrycontroller.new_gitano_command(statedb, lorry_info['from_trovehost']) local = lorrycontroller.LocalTroveGitanoCommand() |