summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/deploy.py
diff options
context:
space:
mode:
authorJunchun Guan <junchunx.guan@intel.com>2014-12-19 11:41:56 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-23 10:18:16 +0000
commit0d686ccc7c7facdaa36df5c340d000c3674e58c5 (patch)
treefcd3a14b72b7ef05c85096a6f805661ed3abe0a5 /scripts/lib/devtool/deploy.py
parentcd5ca4a11daff2089ba3031103b9b9dab5b3c94e (diff)
downloadpoky-0d686ccc7c7facdaa36df5c340d000c3674e58c5.tar.gz
scripts/devtool: Support deploy/undeploy function
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] (From OE-Core rev: cc10751aa3121218b21ec2058358f3ea02a4500a) Signed-off-by: Junchun Guan <junchunx.guan@intel.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool/deploy.py')
-rw-r--r--scripts/lib/devtool/deploy.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
new file mode 100644
index 0000000000..bd23e95dd9
--- /dev/null
+++ b/scripts/lib/devtool/deploy.py
@@ -0,0 +1,100 @@
1# Development tool - deploy/undeploy command plugin
2#
3# Copyright (C) 2014 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import os
19import subprocess
20import logging
21from devtool import exec_build_env_command
22
23logger = logging.getLogger('devtool')
24
25def plugin_init(pluginlist):
26 pass
27
28
29def deploy(args, config, basepath, workspace):
30 import re
31 from devtool import exec_build_env_command
32
33 if not args.recipename in workspace:
34 logger.error("no recipe named %s in your workspace" % args.recipename)
35 return -1
36 try:
37 host, destdir = args.target.split(':')
38 except ValueError:
39 destdir = '/'
40 else:
41 args.target = host
42
43 deploy_dir = os.path.join(basepath, 'target_deploy', args.target)
44 deploy_file = os.path.join(deploy_dir, args.recipename + '.list')
45
46 if os.path.exists(deploy_file):
47 undeploy(args)
48
49 stdout, stderr = exec_build_env_command(config.init_path, basepath, 'bitbake -e %s' % args.recipename, shell=True)
50 recipe_outdir = re.search(r'^D="(.*)"', stdout, re.MULTILINE).group(1)
51 ret = subprocess.call('scp -qr %s/* %s:%s' % (recipe_outdir, args.target, destdir), shell=True)
52 if ret != 0:
53 return ret
54
55 logger.info('Successfully deployed %s' % recipe_outdir)
56
57 if not os.path.exists(deploy_dir):
58 os.makedirs(deploy_dir)
59
60 files_list = []
61 for root, _, files in os.walk(recipe_outdir):
62 for filename in files:
63 filename = os.path.relpath(os.path.join(root, filename), recipe_outdir)
64 files_list.append(os.path.join(destdir, filename))
65
66 with open(deploy_file, 'w') as fobj:
67 fobj.write('\n'.join(files_list))
68
69 return 0
70
71def undeploy(args, config, basepath, workspace):
72
73 deploy_file = os.path.join(basepath, 'target_deploy', args.target, args.recipename + '.list')
74 if not os.path.exists(deploy_file):
75 logger.error('%s has not been deployed' % args.recipename)
76 return -1
77
78 ret = subprocess.call("scp -q %s %s:/tmp" % (deploy_file, args.target), shell=True)
79 if ret != 0:
80 logger.error('Failed to copy %s to %s' % (deploy, args.target))
81 return -1
82
83 ret = subprocess.call("ssh %s 'xargs -n1 rm -f </tmp/%s'" % (args.target, os.path.basename(deploy_file)), shell=True)
84 if ret == 0:
85 logger.info('Successfully undeployed %s' % args.recipename)
86 os.remove(deploy_file)
87
88 return ret
89
90
91def register_commands(subparsers, context):
92 parser_deploy = subparsers.add_parser('deploy-target', help='Deploy recipe output files to live target machine')
93 parser_deploy.add_argument('recipename', help='Recipe to deploy')
94 parser_deploy.add_argument('target', help='Live target machine running an ssh server: user@hostname[:destdir]')
95 parser_deploy.set_defaults(func=deploy)
96
97 parser_undeploy = subparsers.add_parser('undeploy-target', help='Undeploy recipe output files in live target machine')
98 parser_undeploy.add_argument('recipename', help='Recipe to undeploy')
99 parser_undeploy.add_argument('target', help='Live target machine running an ssh server: user@hostname')
100 parser_undeploy.set_defaults(func=undeploy)