diff options
Diffstat (limited to 'lorrycontroller/gerrit.py')
-rw-r--r-- | lorrycontroller/gerrit.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py index 6ae24e3..6fde905 100644 --- a/lorrycontroller/gerrit.py +++ b/lorrycontroller/gerrit.py @@ -13,11 +13,14 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import logging import cliapp +from . import hosts -class Gerrit(object): + +class GerritDownstream(hosts.DownstreamHost): '''Run commands on a Gerrit instance. @@ -28,7 +31,12 @@ class Gerrit(object): ''' - def __init__(self, host, user, port=29418): + def __init__(self, app_settings): + # XXX These need to be configurable + host = 'localhost' + port = 29418 + user = 'lorry' + self._ssh_command_args = [ 'ssh', '-oStrictHostKeyChecking=no', '-oBatchMode=yes', '-p%i' % port, '%s@%s' % (user, host)] @@ -39,7 +47,7 @@ class Gerrit(object): out = out.decode('utf-8', errors='replace') return out - def has_project(self, name): + def _has_project(self, name): # There's no 'does this project exist' command in Gerrit 2.9.4; 'list # all projects with this prefix' is as close we can get. @@ -52,5 +60,18 @@ class Gerrit(object): else: return False - def create_project(self, name): + def prepare_repo(self, name, metadata): + '''Create a project in the local Gerrit server. + + The 'lorry' user must have createProject capability in the Gerrit. + + ''' + # TODO: set metadata + + if self._has_project(name): + logging.info('Project %s exists in local Gerrit already.', + name) + return + self._ssh_command(['gerrit', 'create-project', name]) + logging.info('Created %s project in local Gerrit.', name) |