diff options
-rw-r--r-- | morphlib/plugins/copy-artifacts_plugin.py | 106 | ||||
-rwxr-xr-x | scripts/find-artifacts | 67 | ||||
-rw-r--r-- | without-test-modules | 1 |
3 files changed, 107 insertions, 67 deletions
diff --git a/morphlib/plugins/copy-artifacts_plugin.py b/morphlib/plugins/copy-artifacts_plugin.py new file mode 100644 index 00000000..9cf8c147 --- /dev/null +++ b/morphlib/plugins/copy-artifacts_plugin.py @@ -0,0 +1,106 @@ +# Copyright (C) 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. + + + +# FIXME: no tests + + + +import os +import glob +import json + + +import cliapp + + + +import morphlib + + + +class CopyArtifactsPlugin(cliapp.Plugin): + + def enable(self): + self.app.add_subcommand( + 'list-artifacts', self.list_artifacts, + arg_synopsis='SYSTEM') + self.app.add_subcommand( + 'copy-artifacts', self.copy_artifacts, + arg_synopsis='SYSTEM DESTINATION') + + def disable(self): + pass + + def list_artifacts(self, args): + '''List every artifact that makes up a system''' + + if len(args) != 1: + raise cliapp.AppException( + 'Wrong number of arguments to list-artifacts command' + '(see help)') + + system = args[0] + artifacts = self.find_artifacts(system) + for artifact in artifacts: + self.app.output.write(artifact + "\n") + + def copy_artifacts(self, args): + '''Copy every artifact that makes up a system to an rsync path''' + + if len(args) != 2: + raise cliapp.AppException( + 'Wrong number of arguments to copy-artifacts command' + '(see help)') + + system = args[0] + rsync_dest = args[1] + artifacts = self.find_artifacts(system) + cmdline = ['rsync'] + cmdline.extend(artifacts) + cmdline.append(rsync_dest) + cliapp.runcmd(cmdline) + + def find_artifacts(self, system): + artifacts_dir = os.path.join(self.app.settings['cachedir'], 'artifacts') + artifacts = [] + + def find_in_system(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(system) + 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']) + artifacts.extend(found_artifacts) + + morphlib.bins.call_in_artifact_directory( + self.app, system, find_in_system) + + return artifacts + diff --git a/scripts/find-artifacts b/scripts/find-artifacts deleted file mode 100755 index 462126fc..00000000 --- a/scripts/find-artifacts +++ /dev/null @@ -1,67 +0,0 @@ -#!/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() diff --git a/without-test-modules b/without-test-modules index cc901f32..b1603c69 100644 --- a/without-test-modules +++ b/without-test-modules @@ -24,3 +24,4 @@ morphlib/plugins/expand_repo_plugin.py morphlib/plugins/deploy_plugin.py morphlib/plugins/__init__.py morphlib/writeexts.py +morphlib/plugins/copy-artifacts_plugin.py |