From ebaa5335302e0275a549bacfb698737ce9132abc Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 22 Jun 2015 14:06:30 +0000 Subject: Make `morph show-build-log` look in local repo cache for build logs This makes it more useful and saves people from poking around in the cache in order to dig up build logs. Change-Id: I8e062c5c32b01aca0df54e1974ead3c3b3134cc3 --- morphlib/plugins/show_build_log_plugin.py | 54 +++++++++++++++++++------------ 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'morphlib/plugins') diff --git a/morphlib/plugins/show_build_log_plugin.py b/morphlib/plugins/show_build_log_plugin.py index 98509841..f2a975c1 100644 --- a/morphlib/plugins/show_build_log_plugin.py +++ b/morphlib/plugins/show_build_log_plugin.py @@ -14,6 +14,7 @@ import cliapp +import logging import os import urllib import urlparse @@ -77,29 +78,40 @@ class ShowBuildLog(cliapp.Plugin): break if cache_key: - self.show_build_log_for_artifact(cache_key) + f = self.get_build_log_for_artifact(cache_key) + build_output = [] + for line in f: + build_output.append(str(line)) + self.app.output.write(''.join(build_output)) else: raise cliapp.AppException('Component not found in the given ' 'system.') - def show_build_log_for_artifact(self, cache_key): - artifact_cache_server = ( - self.app.settings['artifact-cache-server'] or - self.app.settings['cache-server']) - - url = urlparse.urljoin(artifact_cache_server, - '/1.0/artifacts?filename=%s.build-log' % cache_key) - response = urllib.urlopen(url) - if response.getcode() == 200: - build_output = [] - for line in response: - build_output.append(str(line)) - self.app.output.write(''.join(build_output)) - elif response.getcode() == 404: - raise cliapp.AppException( - 'No build log for artifact %s found on cache server %s' % - (cache_key, artifact_cache_server)) + def get_build_log_for_artifact(self, cache_key): + lac, rac = morphlib.util.new_artifact_caches(self.app.settings) + + if lac.has_source_metadata(None, cache_key, 'build-log'): + logging.info('Found build log for %s in local cache.', cache_key) + f = lac.get_source_metadata(None, cache_key, 'build-log') else: - raise cliapp.AppException( - 'Error connecting to cache server %s: %s' % - (artifact_cache_server, response.getcode())) + artifact_cache_server = ( + self.app.settings['artifact-cache-server'] or + self.app.settings['cache-server']) + + url = urlparse.urljoin(artifact_cache_server, + '/1.0/artifacts?filename=%s.build-log' % cache_key) + response = urllib.urlopen(url) + if response.getcode() == 200: + logging.info('Found build log for %s in remote cache %s.', + cache_key, artifact_cache_server) + f = response + elif response.getcode() == 404: + raise cliapp.AppException( + 'No build log for artifact %s found on cache server %s' % + (cache_key, artifact_cache_server)) + else: + raise cliapp.AppException( + 'Error connecting to cache server %s: %s' % + (artifact_cache_server, response.getcode())) + + return f -- cgit v1.2.1