summaryrefslogtreecommitdiff
path: root/morphlib/plugins
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-22 14:06:30 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-22 14:07:51 +0000
commitebaa5335302e0275a549bacfb698737ce9132abc (patch)
tree65782f65e9320d837f7fc0c114278f3ff700c425 /morphlib/plugins
parentb18764f144983dfb9aa892892084af1daeb9100d (diff)
downloadmorph-ebaa5335302e0275a549bacfb698737ce9132abc.tar.gz
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
Diffstat (limited to 'morphlib/plugins')
-rw-r--r--morphlib/plugins/show_build_log_plugin.py54
1 files changed, 33 insertions, 21 deletions
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