summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/deploy.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/devtool/deploy.py')
-rw-r--r--scripts/lib/devtool/deploy.py141
1 files changed, 72 insertions, 69 deletions
diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
index 66644ccb6a..fb84f2dd08 100644
--- a/scripts/lib/devtool/deploy.py
+++ b/scripts/lib/devtool/deploy.py
@@ -155,83 +155,86 @@ def deploy(args, config, basepath, workspace):
155 155
156 tinfoil = setup_tinfoil(basepath=basepath) 156 tinfoil = setup_tinfoil(basepath=basepath)
157 try: 157 try:
158 rd = oe.recipeutils.parse_recipe_simple(tinfoil.cooker, args.recipename, tinfoil.config_data) 158 try:
159 except Exception as e: 159 rd = oe.recipeutils.parse_recipe_simple(tinfoil.cooker, args.recipename, tinfoil.config_data)
160 raise DevtoolError('Exception parsing recipe %s: %s' % 160 except Exception as e:
161 (args.recipename, e)) 161 raise DevtoolError('Exception parsing recipe %s: %s' %
162 recipe_outdir = rd.getVar('D', True) 162 (args.recipename, e))
163 if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir): 163 recipe_outdir = rd.getVar('D', True)
164 raise DevtoolError('No files to deploy - have you built the %s ' 164 if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir):
165 'recipe? If so, the install step has not installed ' 165 raise DevtoolError('No files to deploy - have you built the %s '
166 'any files.' % args.recipename) 166 'recipe? If so, the install step has not installed '
167 'any files.' % args.recipename)
167 168
168 filelist = [] 169 filelist = []
169 ftotalsize = 0 170 ftotalsize = 0
170 for root, _, files in os.walk(recipe_outdir): 171 for root, _, files in os.walk(recipe_outdir):
171 for fn in files: 172 for fn in files:
172 # Get the size in kiB (since we'll be comparing it to the output of du -k) 173 # Get the size in kiB (since we'll be comparing it to the output of du -k)
173 # MUST use lstat() here not stat() or getfilesize() since we don't want to 174 # MUST use lstat() here not stat() or getfilesize() since we don't want to
174 # dereference symlinks 175 # dereference symlinks
175 fsize = int(math.ceil(float(os.lstat(os.path.join(root, fn)).st_size)/1024)) 176 fsize = int(math.ceil(float(os.lstat(os.path.join(root, fn)).st_size)/1024))
176 ftotalsize += fsize 177 ftotalsize += fsize
177 # The path as it would appear on the target 178 # The path as it would appear on the target
178 fpath = os.path.join(destdir, os.path.relpath(root, recipe_outdir), fn) 179 fpath = os.path.join(destdir, os.path.relpath(root, recipe_outdir), fn)
179 filelist.append((fpath, fsize)) 180 filelist.append((fpath, fsize))
180 181
181 if args.dry_run: 182 if args.dry_run:
182 print('Files to be deployed for %s on target %s:' % (args.recipename, args.target)) 183 print('Files to be deployed for %s on target %s:' % (args.recipename, args.target))
183 for item, _ in filelist: 184 for item, _ in filelist:
184 print(' %s' % item) 185 print(' %s' % item)
185 return 0 186 return 0
186 187
187 188
188 extraoptions = '' 189 extraoptions = ''
189 if args.no_host_check: 190 if args.no_host_check:
190 extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' 191 extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
191 if not args.show_status: 192 if not args.show_status:
192 extraoptions += ' -q' 193 extraoptions += ' -q'
193 194
194 # In order to delete previously deployed files and have the manifest file on 195 # In order to delete previously deployed files and have the manifest file on
195 # the target, we write out a shell script and then copy it to the target 196 # the target, we write out a shell script and then copy it to the target
196 # so we can then run it (piping tar output to it). 197 # so we can then run it (piping tar output to it).
197 # (We cannot use scp here, because it doesn't preserve symlinks.) 198 # (We cannot use scp here, because it doesn't preserve symlinks.)
198 tmpdir = tempfile.mkdtemp(prefix='devtool') 199 tmpdir = tempfile.mkdtemp(prefix='devtool')
199 try: 200 try:
200 tmpscript = '/tmp/devtool_deploy.sh' 201 tmpscript = '/tmp/devtool_deploy.sh'
201 tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list') 202 tmpfilelist = os.path.join(os.path.dirname(tmpscript), 'devtool_deploy.list')
202 shellscript = _prepare_remote_script(deploy=True, 203 shellscript = _prepare_remote_script(deploy=True,
203 verbose=args.show_status, 204 verbose=args.show_status,
204 nopreserve=args.no_preserve, 205 nopreserve=args.no_preserve,
205 nocheckspace=args.no_check_space) 206 nocheckspace=args.no_check_space)
206 # Write out the script to a file 207 # Write out the script to a file
207 with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f: 208 with open(os.path.join(tmpdir, os.path.basename(tmpscript)), 'w') as f:
208 f.write(shellscript) 209 f.write(shellscript)
209 # Write out the file list 210 # Write out the file list
210 with open(os.path.join(tmpdir, os.path.basename(tmpfilelist)), 'w') as f: 211 with open(os.path.join(tmpdir, os.path.basename(tmpfilelist)), 'w') as f:
211 f.write('%d\n' % ftotalsize) 212 f.write('%d\n' % ftotalsize)
212 for fpath, fsize in filelist: 213 for fpath, fsize in filelist:
213 f.write('%s %d\n' % (fpath, fsize)) 214 f.write('%s %d\n' % (fpath, fsize))
214 # Copy them to the target 215 # Copy them to the target
215 ret = subprocess.call("scp %s %s/* %s:%s" % (extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True) 216 ret = subprocess.call("scp %s %s/* %s:%s" % (extraoptions, tmpdir, args.target, os.path.dirname(tmpscript)), shell=True)
216 if ret != 0: 217 if ret != 0:
217 raise DevtoolError('Failed to copy script to %s - rerun with -s to ' 218 raise DevtoolError('Failed to copy script to %s - rerun with -s to '
218 'get a complete error message' % args.target) 219 'get a complete error message' % args.target)
219 finally: 220 finally:
220 shutil.rmtree(tmpdir) 221 shutil.rmtree(tmpdir)
221 222
222 # Now run the script 223 # Now run the script
223 ret = exec_fakeroot(rd, 'tar cf - . | ssh %s %s \'sh %s %s %s %s\'' % (extraoptions, args.target, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True) 224 ret = exec_fakeroot(rd, 'tar cf - . | ssh %s %s \'sh %s %s %s %s\'' % (extraoptions, args.target, tmpscript, args.recipename, destdir, tmpfilelist), cwd=recipe_outdir, shell=True)
224 if ret != 0: 225 if ret != 0:
225 raise DevtoolError('Deploy failed - rerun with -s to get a complete ' 226 raise DevtoolError('Deploy failed - rerun with -s to get a complete '
226 'error message') 227 'error message')
227 228
228 logger.info('Successfully deployed %s' % recipe_outdir) 229 logger.info('Successfully deployed %s' % recipe_outdir)
229 230
230 files_list = [] 231 files_list = []
231 for root, _, files in os.walk(recipe_outdir): 232 for root, _, files in os.walk(recipe_outdir):
232 for filename in files: 233 for filename in files:
233 filename = os.path.relpath(os.path.join(root, filename), recipe_outdir) 234 filename = os.path.relpath(os.path.join(root, filename), recipe_outdir)
234 files_list.append(os.path.join(destdir, filename)) 235 files_list.append(os.path.join(destdir, filename))
236 finally:
237 tinfoil.shutdown()
235 238
236 return 0 239 return 0
237 240