summaryrefslogtreecommitdiff
path: root/morphlib/plugins/deploy_plugin.py
diff options
context:
space:
mode:
authorMark Doffman <mark.doffman@codethink.co.uk>2014-02-21 18:58:56 +0000
committerMark Doffman <mark.doffman@codethink.co.uk>2014-03-31 21:33:22 +0000
commit8fb1dac02b0be1502fd7b19de981e2a81468ffe2 (patch)
treee2239babb6782d1ea869f43e18b6a59d59a3c326 /morphlib/plugins/deploy_plugin.py
parent20b4bf7dbf1b4950b82113f6ffdd2ef171cfc04e (diff)
downloadmorph-8fb1dac02b0be1502fd7b19de981e2a81468ffe2.tar.gz
Add utilities for listing and finding extensions.
Add a module to morphlib that can list all write and configuration extensions either in morph itself or the morphology repository. The module also contains methods to find an extension filename from the name and type.
Diffstat (limited to 'morphlib/plugins/deploy_plugin.py')
-rw-r--r--morphlib/plugins/deploy_plugin.py59
1 files changed, 16 insertions, 43 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index ae62b75d..1d582949 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -26,11 +26,6 @@ import uuid
import morphlib
-
-class ExtensionNotFoundError(morphlib.Error):
- pass
-
-
class DeployPlugin(cliapp.Plugin):
def enable(self):
@@ -425,9 +420,9 @@ class DeployPlugin(cliapp.Plugin):
# extension itself has the chance to raise an error.
try:
self._run_extension(
- root_repo_dir, ref, deployment_type, '.check',
+ root_repo_dir, deployment_type, '.check',
[location], env)
- except ExtensionNotFoundError:
+ except morphlib.extensions.ExtensionNotFoundError:
pass
def setup_deploy(self, build_command, deploy_tempdir, root_repo_dir, ref,
@@ -485,7 +480,6 @@ class DeployPlugin(cliapp.Plugin):
for name in names:
self._run_extension(
root_repo_dir,
- ref,
name,
'.configure',
[system_tree],
@@ -495,7 +489,6 @@ class DeployPlugin(cliapp.Plugin):
self.app.status(msg='Writing to device')
self._run_extension(
root_repo_dir,
- ref,
deployment_type,
'.write',
[system_tree, location],
@@ -506,7 +499,7 @@ class DeployPlugin(cliapp.Plugin):
self.app.status(msg='Cleaning up')
shutil.rmtree(deploy_private_tempdir)
- def _run_extension(self, gd, ref, name, kind, args, env):
+ def _run_extension(self, gd, name, kind, args, env):
'''Run an extension.
The ``kind`` should be either ``.configure`` or ``.write``,
@@ -516,39 +509,19 @@ class DeployPlugin(cliapp.Plugin):
system morphology (repo, ref), or with the Morph code.
'''
-
- # Look for extension in the system morphology's repository.
- try:
- ext = gd.get_file_from_ref(ref, name + kind)
- except cliapp.AppException:
- # Not found: look for it in the Morph code.
- code_dir = os.path.dirname(morphlib.__file__)
- ext_filename = os.path.join(code_dir, 'exts', name + kind)
- if not os.path.exists(ext_filename):
- raise ExtensionNotFoundError(
- 'Could not find extension %s%s' % (name, kind))
- if not self._is_executable(ext_filename):
- raise morphlib.Error(
- 'Extension not executable: %s' % ext_filename)
- delete_ext = False
- else:
- # Found it in the system morphology's repository.
- fd, ext_filename = tempfile.mkstemp()
- os.write(fd, ext)
- os.close(fd)
- os.chmod(ext_filename, 0700)
- delete_ext = True
-
- self.app.status(msg='Running extension %(name)s%(kind)s',
- name=name, kind=kind)
- self.app.runcmd(
- [ext_filename] + args,
- ['sh', '-c', 'while read l; do echo `date "+%F %T"` "$1$l"; done',
- '-', '%s[%s]' % (self.app.status_prefix, name + kind)],
- cwd=gd.dirname, env=env, stdout=None, stderr=None)
-
- if delete_ext:
- os.remove(ext_filename)
+ build_ref_prefix = self.app.settings['build-ref-prefix']
+ with morphlib.extensions.get_extension_filename(
+ build_ref_prefix, name, kind) as ext_filename:
+ self.app.status(msg='Running extension %(name)s%(kind)s',
+ name=name, kind=kind)
+ self.app.runcmd(
+ [ext_filename] + args,
+ ['sh',
+ '-c',
+ 'while read l; do echo `date "+%F %T"` "$1$l"; done',
+ '-',
+ '%s[%s]' % (self.app.status_prefix, name + kind)],
+ cwd=gd.dirname, env=env, stdout=None, stderr=None)
def _is_executable(self, filename):
st = os.stat(filename)