#!/usr/bin/env python # # Copyright (C) 2011-2013 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 # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # This is a program to read the metadata of a baserock image to produce a list # of all the chunks needed to build said image. import json import os import tempfile import gzip import sys import glob import cliapp path = os.path.dirname(os.path.dirname(__file__)) sys.path.append(path) import morphlib class FindArtifacts(morphlib.app.Morph): def process_args(self, args): artifacts_dir = os.path.join(self.settings['cachedir'], 'artifacts') # args[0] is the path to the built image. artifact = args[0] def find_artifacts(dirname): metadirs = [ os.path.join(dirname, 'factory', 'baserock'), os.path.join(dirname, 'baserock') ] existing_metadirs = [x for x in metadirs if os.path.isdir(x)] if not existing_metadirs: raise NotASystemArtifactError(artifact) metadir = existing_metadirs[0] for basename in glob.glob(os.path.join(metadir, '*.meta')): metafile = os.path.join(metadir, basename) metadata = json.load(open(metafile)) cache_key = metadata['cache-key'] artifact_glob = os.path.join(artifacts_dir, cache_key) + '*' found_artifacts = glob.glob(artifact_glob) if not found_artifacts: raise cliapp.AppException('Could not find cache-key ' + cache_key + ' for artifact ' + metajson['artifact-name']) for cached_file in found_artifacts: self.output.write(cached_file + "\n") morphlib.bins.call_in_artifact_directory(self, artifact, find_artifacts) FindArtifacts().run()