summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-01-23 00:59:50 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-22 23:42:56 +0000
commitbad5d1a8c047a8118d30d9fa708b021d1599e0dc (patch)
tree5d97092376c727bc7f239a7e5dddf06e0298b3c5
parent6579c7120ee5a541427ff5b6b07f838d52f9fe7c (diff)
downloadopenembedded-core-bad5d1a8c047a8118d30d9fa708b021d1599e0dc.tar.gz
openembedded-core-bad5d1a8c047a8118d30d9fa708b021d1599e0dc.tar.bz2
openembedded-core-bad5d1a8c047a8118d30d9fa708b021d1599e0dc.zip
devtool: sdk-update: improve temp directory handling
* Use tempfile.mkdtemp() instead of hardcoding temp dir * Set a variable early for the temp locked sigs file and use that everywhere * Delete the temp dir at the end Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--scripts/lib/devtool/sdk.py75
1 files changed, 38 insertions, 37 deletions
diff --git a/scripts/lib/devtool/sdk.py b/scripts/lib/devtool/sdk.py
index 68139aaf3c..4fcd36a0df 100644
--- a/scripts/lib/devtool/sdk.py
+++ b/scripts/lib/devtool/sdk.py
@@ -7,6 +7,7 @@ import glob
import shutil
import errno
import sys
+import tempfile
from devtool import exec_build_env_command, setup_tinfoil, DevtoolError
logger = logging.getLogger('devtool')
@@ -133,45 +134,45 @@ def sdk_update(args, config, basepath, workspace):
return ret
else:
# devtool sdk-update http://myhost/sdk
- tmpsdk_dir = '/tmp/sdk-ext'
- if os.path.exists(tmpsdk_dir):
- shutil.rmtree(tmpsdk_dir)
- os.makedirs(tmpsdk_dir)
- os.makedirs(os.path.join(tmpsdk_dir, 'conf'))
- # Fetch locked-sigs.inc from update server
- ret = subprocess.call("wget -q -O - %s/conf/locked-sigs.inc > %s/locked-sigs.inc" % (updateserver, os.path.join(tmpsdk_dir, 'conf')), shell=True)
- if ret != 0:
- logger.error("Fetching conf/locked-sigs.inc from %s to %s/locked-sigs.inc failed" % (updateserver, os.path.join(tmpsdk_dir, 'conf')))
- return ret
- else:
- logger.info("Fetching conf/locked-sigs.inc from %s to %s/locked-sigs.inc succeeded" % (updateserver, os.path.join(tmpsdk_dir, 'conf')))
- new_locked_sig_file_path = os.path.join(tmpsdk_dir, 'conf/locked-sigs.inc')
- update_dict = generate_update_dict(new_locked_sig_file_path, old_locked_sig_file_path)
- logger.debug("update_dict = %s" % update_dict)
- if len(update_dict) == 0:
- logger.info("No need to update.")
- return 0
- # Update metadata
- logger.debug("Updating meta data via git ...")
- # Try using 'git pull', if failed, use 'git clone'
- if os.path.exists(os.path.join(basepath, 'layers/.git')):
- ret = subprocess.call("cd layers && git pull %s/layers/.git" % updateserver, shell=True)
- else:
- ret = -1
- if ret != 0:
- ret = subprocess.call("rm -rf layers && git clone %s/layers/.git" % updateserver, shell=True)
- if ret != 0:
- logger.error("Updating meta data via git failed")
- return ret
- logger.debug("Updating conf files ...")
- conf_files = ['local.conf', 'bblayers.conf', 'devtool.conf', 'locked-sigs.inc']
- for conf in conf_files:
- ret = subprocess.call("wget -q -O - %s/conf/%s > conf/%s" % (updateserver, conf, conf), shell=True)
+ tmpsdk_dir = tempfile.mkdtemp()
+ try:
+ os.makedirs(os.path.join(tmpsdk_dir, 'conf'))
+ new_locked_sig_file_path = os.path.join(tmpsdk_dir, 'conf', 'locked-sigs.inc')
+ # Fetch locked-sigs.inc from update server
+ ret = subprocess.call("wget -q -O - %s/conf/locked-sigs.inc > %s" % (updateserver, new_locked_sig_file_path), shell=True)
if ret != 0:
- logger.error("Update %s failed" % conf)
+ logger.error("Fetching conf/locked-sigs.inc from %s to %s failed" % (updateserver, new_locked_sig_file_path))
return ret
- with open(os.path.join(basepath, 'conf/local.conf'), 'a') as f:
- f.write('SSTATE_MIRRORS_append = " file://.* %s/sstate-cache/PATH \\n "\n' % updateserver)
+ else:
+ logger.info("Fetching conf/locked-sigs.inc from %s to %s succeeded" % (updateserver, new_locked_sig_file_path))
+ update_dict = generate_update_dict(new_locked_sig_file_path, old_locked_sig_file_path)
+ logger.debug("update_dict = %s" % update_dict)
+ if len(update_dict) == 0:
+ logger.info("No need to update.")
+ return 0
+ # Update metadata
+ logger.debug("Updating meta data via git ...")
+ # Try using 'git pull', if failed, use 'git clone'
+ if os.path.exists(os.path.join(basepath, 'layers/.git')):
+ ret = subprocess.call("cd layers && git pull %s/layers/.git" % updateserver, shell=True)
+ else:
+ ret = -1
+ if ret != 0:
+ ret = subprocess.call("rm -rf layers && git clone %s/layers/.git" % updateserver, shell=True)
+ if ret != 0:
+ logger.error("Updating meta data via git failed")
+ return ret
+ logger.debug("Updating conf files ...")
+ conf_files = ['local.conf', 'bblayers.conf', 'devtool.conf', 'locked-sigs.inc']
+ for conf in conf_files:
+ ret = subprocess.call("wget -q -O - %s/conf/%s > conf/%s" % (updateserver, conf, conf), shell=True)
+ if ret != 0:
+ logger.error("Update %s failed" % conf)
+ return ret
+ with open(os.path.join(basepath, 'conf/local.conf'), 'a') as f:
+ f.write('SSTATE_MIRRORS_append = " file://.* %s/sstate-cache/PATH \\n "\n' % updateserver)
+ finally:
+ shutil.rmtree(tmpsdk_dir)
if not args.skip_prepare:
# Run bitbake command for the whole SDK