diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-01-23 00:59:50 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-24 09:40:32 +0000 |
commit | 3360baa96bb2ebd54efaba0fb9aa9a1c9093c233 (patch) | |
tree | b0371295532cb1323bc55e21a25702de27957cc1 /scripts/lib | |
parent | d193531d5ead804380884e97e14ce00cbdccf494 (diff) | |
download | poky-3360baa96bb2ebd54efaba0fb9aa9a1c9093c233.tar.gz |
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
(From OE-Core rev: bad5d1a8c047a8118d30d9fa708b021d1599e0dc)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/devtool/sdk.py | 75 |
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 | |||
7 | import shutil | 7 | import shutil |
8 | import errno | 8 | import errno |
9 | import sys | 9 | import sys |
10 | import tempfile | ||
10 | from devtool import exec_build_env_command, setup_tinfoil, DevtoolError | 11 | from devtool import exec_build_env_command, setup_tinfoil, DevtoolError |
11 | 12 | ||
12 | logger = logging.getLogger('devtool') | 13 | logger = logging.getLogger('devtool') |
@@ -133,45 +134,45 @@ def sdk_update(args, config, basepath, workspace): | |||
133 | return ret | 134 | return ret |
134 | else: | 135 | else: |
135 | # devtool sdk-update http://myhost/sdk | 136 | # devtool sdk-update http://myhost/sdk |
136 | tmpsdk_dir = '/tmp/sdk-ext' | 137 | tmpsdk_dir = tempfile.mkdtemp() |
137 | if os.path.exists(tmpsdk_dir): | 138 | try: |
138 | shutil.rmtree(tmpsdk_dir) | 139 | os.makedirs(os.path.join(tmpsdk_dir, 'conf')) |
139 | os.makedirs(tmpsdk_dir) | 140 | new_locked_sig_file_path = os.path.join(tmpsdk_dir, 'conf', 'locked-sigs.inc') |
140 | os.makedirs(os.path.join(tmpsdk_dir, 'conf')) | 141 | # Fetch locked-sigs.inc from update server |
141 | # Fetch locked-sigs.inc from update server | 142 | ret = subprocess.call("wget -q -O - %s/conf/locked-sigs.inc > %s" % (updateserver, new_locked_sig_file_path), shell=True) |
142 | ret = subprocess.call("wget -q -O - %s/conf/locked-sigs.inc > %s/locked-sigs.inc" % (updateserver, os.path.join(tmpsdk_dir, 'conf')), shell=True) | ||
143 | if ret != 0: | ||
144 | logger.error("Fetching conf/locked-sigs.inc from %s to %s/locked-sigs.inc failed" % (updateserver, os.path.join(tmpsdk_dir, 'conf'))) | ||
145 | return ret | ||
146 | else: | ||
147 | logger.info("Fetching conf/locked-sigs.inc from %s to %s/locked-sigs.inc succeeded" % (updateserver, os.path.join(tmpsdk_dir, 'conf'))) | ||
148 | new_locked_sig_file_path = os.path.join(tmpsdk_dir, 'conf/locked-sigs.inc') | ||
149 | update_dict = generate_update_dict(new_locked_sig_file_path, old_locked_sig_file_path) | ||
150 | logger.debug("update_dict = %s" % update_dict) | ||
151 | if len(update_dict) == 0: | ||
152 | logger.info("No need to update.") | ||
153 | return 0 | ||
154 | # Update metadata | ||
155 | logger.debug("Updating meta data via git ...") | ||
156 | # Try using 'git pull', if failed, use 'git clone' | ||
157 | if os.path.exists(os.path.join(basepath, 'layers/.git')): | ||
158 | ret = subprocess.call("cd layers && git pull %s/layers/.git" % updateserver, shell=True) | ||
159 | else: | ||
160 | ret = -1 | ||
161 | if ret != 0: | ||
162 | ret = subprocess.call("rm -rf layers && git clone %s/layers/.git" % updateserver, shell=True) | ||
163 | if ret != 0: | ||
164 | logger.error("Updating meta data via git failed") | ||
165 | return ret | ||
166 | logger.debug("Updating conf files ...") | ||
167 | conf_files = ['local.conf', 'bblayers.conf', 'devtool.conf', 'locked-sigs.inc'] | ||
168 | for conf in conf_files: | ||
169 | ret = subprocess.call("wget -q -O - %s/conf/%s > conf/%s" % (updateserver, conf, conf), shell=True) | ||
170 | if ret != 0: | 143 | if ret != 0: |
171 | logger.error("Update %s failed" % conf) | 144 | logger.error("Fetching conf/locked-sigs.inc from %s to %s failed" % (updateserver, new_locked_sig_file_path)) |
172 | return ret | 145 | return ret |
173 | with open(os.path.join(basepath, 'conf/local.conf'), 'a') as f: | 146 | else: |
174 | f.write('SSTATE_MIRRORS_append = " file://.* %s/sstate-cache/PATH \\n "\n' % updateserver) | 147 | logger.info("Fetching conf/locked-sigs.inc from %s to %s succeeded" % (updateserver, new_locked_sig_file_path)) |
148 | update_dict = generate_update_dict(new_locked_sig_file_path, old_locked_sig_file_path) | ||
149 | logger.debug("update_dict = %s" % update_dict) | ||
150 | if len(update_dict) == 0: | ||
151 | logger.info("No need to update.") | ||
152 | return 0 | ||
153 | # Update metadata | ||
154 | logger.debug("Updating meta data via git ...") | ||
155 | # Try using 'git pull', if failed, use 'git clone' | ||
156 | if os.path.exists(os.path.join(basepath, 'layers/.git')): | ||
157 | ret = subprocess.call("cd layers && git pull %s/layers/.git" % updateserver, shell=True) | ||
158 | else: | ||
159 | ret = -1 | ||
160 | if ret != 0: | ||
161 | ret = subprocess.call("rm -rf layers && git clone %s/layers/.git" % updateserver, shell=True) | ||
162 | if ret != 0: | ||
163 | logger.error("Updating meta data via git failed") | ||
164 | return ret | ||
165 | logger.debug("Updating conf files ...") | ||
166 | conf_files = ['local.conf', 'bblayers.conf', 'devtool.conf', 'locked-sigs.inc'] | ||
167 | for conf in conf_files: | ||
168 | ret = subprocess.call("wget -q -O - %s/conf/%s > conf/%s" % (updateserver, conf, conf), shell=True) | ||
169 | if ret != 0: | ||
170 | logger.error("Update %s failed" % conf) | ||
171 | return ret | ||
172 | with open(os.path.join(basepath, 'conf/local.conf'), 'a') as f: | ||
173 | f.write('SSTATE_MIRRORS_append = " file://.* %s/sstate-cache/PATH \\n "\n' % updateserver) | ||
174 | finally: | ||
175 | shutil.rmtree(tmpsdk_dir) | ||
175 | 176 | ||
176 | if not args.skip_prepare: | 177 | if not args.skip_prepare: |
177 | # Run bitbake command for the whole SDK | 178 | # Run bitbake command for the whole SDK |