summaryrefslogtreecommitdiff
path: root/morphlib/plugins/deploy_plugin.py
diff options
context:
space:
mode:
authorMark Doffman <mark.doffman@codethink.co.uk>2014-02-21 20:39:05 +0000
committerMark Doffman <mark.doffman@codethink.co.uk>2014-02-21 20:39:05 +0000
commitf8e4c0344c4016e0b462f7514c88b18c1a442e3d (patch)
tree810fbf9eb0bd63d0f608c97bb6bf333e313030d4 /morphlib/plugins/deploy_plugin.py
parent0ea37f35c47b7129b9a81e442c2d7739c6868705 (diff)
downloadmorph-f8e4c0344c4016e0b462f7514c88b18c1a442e3d.tar.gz
Revert "Add utilities for listing and finding extensions."
This reverts commit ab0a83a09a93ca33aa402d9c4d3b916a48a1a882.
Diffstat (limited to 'morphlib/plugins/deploy_plugin.py')
-rw-r--r--morphlib/plugins/deploy_plugin.py51
1 files changed, 40 insertions, 11 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 76ba8e20..47cd00c1 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013, 2014 Codethink Limited
+# 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
@@ -403,6 +403,7 @@ class DeployPlugin(cliapp.Plugin):
for name in names:
self._run_extension(
root_repo_dir,
+ ref,
name,
'.configure',
[system_tree],
@@ -412,6 +413,7 @@ class DeployPlugin(cliapp.Plugin):
self.app.status(msg='Writing to device')
self._run_extension(
root_repo_dir,
+ ref,
deployment_type,
'.write',
[system_tree, location],
@@ -424,7 +426,7 @@ class DeployPlugin(cliapp.Plugin):
self.app.status(msg='Finished deployment')
- def _run_extension(self, gd, name, kind, args, env):
+ def _run_extension(self, gd, ref, name, kind, args, env):
'''Run an extension.
The ``kind`` should be either ``.configure`` or ``.write``,
@@ -435,12 +437,39 @@ class DeployPlugin(cliapp.Plugin):
'''
- 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"` $l; done'],
- cwd=gd.dirname, env=env, stdout=None, stderr=None)
+ # 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 morphlib.Error(
+ '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"` $l; done'],
+ cwd=gd.dirname, env=env, stdout=None, stderr=None)
+
+ if delete_ext:
+ os.remove(ext_filename)
+
+ def _is_executable(self, filename):
+ st = os.stat(filename)
+ mask = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
+ return (stat.S_IMODE(st.st_mode) & mask) != 0