1 # Copyright (c) 2017 Wind River Systems, Inc.
2 # Copyright (c) 2017-2018 VMware, Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 logger = logging.getLogger(__name__)
22 if not os.path.exists(path):
23 os.makedirs(path, 0777)
26 def delete_dirs(path):
28 if os.path.exists(path):
30 except Exception as e:
31 logger.error(traceback.format_exc())
32 logger.error("Failed to delete %s:%s", path, e.message)
35 def download_file_from_http(url, local_dir, file_name):
36 local_file_name = os.path.join(local_dir, file_name)
37 is_download_ok = False
40 r = urllib2.Request(url)
41 req = urllib2.urlopen(r)
42 save_file = open(local_file_name, 'wb')
43 save_file.write(req.read())
48 logger.error(traceback.format_exc())
49 logger.error("Failed to download %s to %s.", url, local_file_name)
50 return is_download_ok, local_file_name