From bc7f80d39b0bd8dd1484567b89c2e8801754d077 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Tue, 14 Jul 2020 23:50:58 +0100 Subject: givemejob: Move upstream host metadata lookup out of get_repo_metadata In preparation for adding metadata for single repositories, move the code for looking up metadata through the Upstream Host connector into a separate function. --- lorrycontroller/givemejob.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py index 8f4a2a8..721b55e 100644 --- a/lorrycontroller/givemejob.py +++ b/lorrycontroller/givemejob.py @@ -65,12 +65,9 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): due = lorry_info['last_run'] + lorry_info['interval'] return (lorry_info['running_job'] is None and due <= now) - def get_repo_metadata(self, statedb, lorry_info): - '''Get repository head and description.''' - - if not lorry_info['from_host']: - return {} - + @staticmethod + def get_upstream_host_repo_metadata(lorry_info): + assert lorry_info['from_host'] assert lorry_info['from_path'] try: @@ -79,14 +76,25 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): # XXX Shouldn't happen, but currently the database schema # does not prevent it return {} - - metadata = lorrycontroller.get_upstream_host(host_info) \ + else: + return lorrycontroller.get_upstream_host(host_info) \ .get_repo_metadata(lorry_info['from_path']) - if 'description' in metadata: + + def get_repo_metadata(self, statedb, lorry_info): + '''Get repository head and description.''' + + host_name = lorry_info['from_host'] + if host_name: + metadata = self.get_upstream_host_repo_metadata(lorry_info) + else: + metadata = {} + + if host_name and 'description' in metadata: # Prepend Upstream Host name metadata['description'] = '{host}: {desc}'.format( - host=lorry_info['from_host'], + host=host_name, desc=metadata['description']) + return metadata def give_job_to_minion(self, statedb, lorry_info, now): -- cgit v1.2.1