public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: Paul Eggleton <paul.eggleton@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 14/15] scripts/devtool: Support deploy/undeploy function
Date: Fri, 19 Dec 2014 11:41:56 +0000	[thread overview]
Message-ID: <19678636987fdbed3b16eea35652f00a12c19ac0.1418984743.git.paul.eggleton@linux.intel.com> (raw)
In-Reply-To: <cover.1418984743.git.paul.eggleton@linux.intel.com>
In-Reply-To: <cover.1418984743.git.paul.eggleton@linux.intel.com>

From: Junchun Guan <junchunx.guan@intel.com>

Deploy recipe output files to live target machine using scp
Store the files list and target machine info in localhost if deployment
is done
Undeploy recipe output files in target machine using the previous
deployment info

[YOCTO #6654]

Signed-off-by: Junchun Guan <junchunx.guan@intel.com>
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/lib/devtool/deploy.py | 100 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
 create mode 100644 scripts/lib/devtool/deploy.py

diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
new file mode 100644
index 0000000..bd23e95
--- /dev/null
+++ b/scripts/lib/devtool/deploy.py
@@ -0,0 +1,100 @@
+# Development tool - deploy/undeploy command plugin
+#
+# Copyright (C) 2014 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# 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.
+
+import os
+import subprocess
+import logging
+from devtool import exec_build_env_command
+
+logger = logging.getLogger('devtool')
+
+def plugin_init(pluginlist):
+    pass
+
+
+def deploy(args, config, basepath, workspace):
+    import re
+    from devtool import exec_build_env_command
+
+    if not args.recipename in workspace:
+        logger.error("no recipe named %s in your workspace" % args.recipename)
+        return -1
+    try:
+        host, destdir = args.target.split(':')
+    except ValueError:
+        destdir = '/'
+    else:
+        args.target = host
+
+    deploy_dir = os.path.join(basepath, 'target_deploy', args.target)
+    deploy_file = os.path.join(deploy_dir, args.recipename + '.list')
+
+    if os.path.exists(deploy_file):
+        undeploy(args)
+
+    stdout, stderr = exec_build_env_command(config.init_path, basepath, 'bitbake -e %s' % args.recipename, shell=True)
+    recipe_outdir = re.search(r'^D="(.*)"', stdout, re.MULTILINE).group(1)
+    ret = subprocess.call('scp -qr %s/* %s:%s' % (recipe_outdir, args.target, destdir), shell=True)
+    if ret != 0:
+        return ret
+
+    logger.info('Successfully deployed %s' % recipe_outdir)
+
+    if not os.path.exists(deploy_dir):
+        os.makedirs(deploy_dir)
+
+    files_list = []
+    for root, _, files in os.walk(recipe_outdir):
+        for filename in files:
+            filename = os.path.relpath(os.path.join(root, filename), recipe_outdir)
+            files_list.append(os.path.join(destdir, filename))
+
+    with open(deploy_file, 'w') as fobj:
+        fobj.write('\n'.join(files_list))
+
+    return 0
+
+def undeploy(args, config, basepath, workspace):
+
+    deploy_file = os.path.join(basepath, 'target_deploy', args.target, args.recipename + '.list')
+    if not os.path.exists(deploy_file):
+         logger.error('%s has not been deployed' % args.recipename)
+         return -1
+
+    ret = subprocess.call("scp -q %s %s:/tmp" % (deploy_file, args.target), shell=True)
+    if ret != 0:
+        logger.error('Failed to copy %s to %s' % (deploy, args.target))
+        return -1
+
+    ret = subprocess.call("ssh %s 'xargs -n1 rm -f </tmp/%s'" % (args.target, os.path.basename(deploy_file)), shell=True)
+    if ret == 0:
+        logger.info('Successfully undeployed %s' % args.recipename)
+        os.remove(deploy_file)
+
+    return ret
+
+
+def register_commands(subparsers, context):
+    parser_deploy = subparsers.add_parser('deploy-target', help='Deploy recipe output files to live target machine')
+    parser_deploy.add_argument('recipename', help='Recipe to deploy')
+    parser_deploy.add_argument('target', help='Live target machine running an ssh server: user@hostname[:destdir]')
+    parser_deploy.set_defaults(func=deploy)
+
+    parser_undeploy = subparsers.add_parser('undeploy-target', help='Undeploy recipe output files in live target machine')
+    parser_undeploy.add_argument('recipename', help='Recipe to undeploy')
+    parser_undeploy.add_argument('target', help='Live target machine running an ssh server: user@hostname')
+    parser_undeploy.set_defaults(func=undeploy)
-- 
1.9.3



  parent reply	other threads:[~2014-12-19 11:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-19 11:41 [PATCH 00/15] Developer workflow tools Paul Eggleton
2014-12-19 11:41 ` [PATCH 01/15] meta-environment: don't mark tasks as nostamp Paul Eggleton
2014-12-19 11:41 ` [PATCH 02/15] classes/package: move read_shlib_providers() to a common unit Paul Eggleton
2014-12-19 11:41 ` [PATCH 03/15] lib/oe/patch: fall back to patch if git apply fails Paul Eggleton
2014-12-19 11:41 ` [PATCH 04/15] lib/oe/patch: auto-commit when falling back from git am Paul Eggleton
2014-12-19 11:41 ` [PATCH 05/15] lib/oe/patch: use --keep-cr with " Paul Eggleton
2014-12-19 11:41 ` [PATCH 06/15] lib/oe/patch.py: abort "git am" if it fails Paul Eggleton
2014-12-19 11:41 ` [PATCH 07/15] lib/oe/patch: add support for extracting patches from git tree Paul Eggleton
2014-12-19 11:41 ` [PATCH 08/15] lib/oe: add recipeutils module Paul Eggleton
2014-12-19 11:41 ` [PATCH 09/15] oeqa/utils: make get_bb_var() more reliable Paul Eggleton
2014-12-19 11:41 ` [PATCH 10/15] classes/externalsrc: set do_compile as nostamp Paul Eggleton
2014-12-19 11:41 ` [PATCH 11/15] scripts/recipetool: Add a recipe auto-creation script Paul Eggleton
2014-12-19 11:41 ` [PATCH 12/15] scripts: add scriptutils module Paul Eggleton
2014-12-19 11:41 ` [PATCH 13/15] scripts/devtool: add development helper tool Paul Eggleton
2014-12-19 11:41 ` Paul Eggleton [this message]
2014-12-19 11:41 ` [PATCH 15/15] devtool: add QA tests Paul Eggleton
2014-12-23 12:30 ` [PATCH 00/15] Developer workflow tools Trevor Woerner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19678636987fdbed3b16eea35652f00a12c19ac0.1418984743.git.paul.eggleton@linux.intel.com \
    --to=paul.eggleton@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox