diff options
author | Martin Braun <martin.braun@ettus.com> | 2014-10-01 17:39:50 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-10-06 10:42:14 +0200 |
commit | 29a4693b11cbfa3f2a4c3c517d54cbc155018ee8 (patch) | |
tree | c92d1f3d533552b9fa63b7aadc26ad7546048d59 /images/populate_images.py | |
parent | 57e6930fef096b1af0fc23e59a777f57b39bf2aa (diff) | |
download | uhd-29a4693b11cbfa3f2a4c3c517d54cbc155018ee8.tar.gz uhd-29a4693b11cbfa3f2a4c3c517d54cbc155018ee8.tar.bz2 uhd-29a4693b11cbfa3f2a4c3c517d54cbc155018ee8.zip |
uhd: Added infrastructure for maintaining images directory
Diffstat (limited to 'images/populate_images.py')
-rwxr-xr-x | images/populate_images.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/images/populate_images.py b/images/populate_images.py new file mode 100755 index 000000000..1ffc9081b --- /dev/null +++ b/images/populate_images.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# +# Copyright 2014 Ettus Research LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +""" +Populates the current directory with a valid set of binaries for the +current commit. +""" + +import os +import re +import subprocess +import uhdimgs + +def get_md5_and_zipfilename(): + """ Return MD5 hash and ZIP filename from the host/CMakeLists.txt file. """ + cmakef = open(uhdimgs.get_cmake_main_file(), 'r').read() + md5_regex = re.compile(r'UHD_IMAGES_MD5SUM\s*"(?P<md5>[0-9a-f]{32})', flags=re.MULTILINE) + md5 = md5_regex.search(cmakef).groups('md5')[0] + filename_regex = re.compile(r'UHD_IMAGES_DOWNLOAD_SRC\s*"(?P<filename>[^"]*\.zip)', flags=re.MULTILINE) + filename = filename_regex.search(cmakef).groups('filename')[0] + return (md5, filename) + +def main(): + " Go, go, go! " + # Switch to correct dir + img_root_dir = os.path.join(uhdimgs.get_images_dir(), 'images') + os.chdir(uhdimgs.get_images_dir()) + # Read out the CMakeLists.txt file, get filename + print "== Reading MD5 and ZIP filename for current commit from {}...".format(uhdimgs.get_cmake_main_file()) + (md5, filename) = get_md5_and_zipfilename() + print "== Starting download..." + try: + downloader_cmd = [ + 'python', + '../host/utils/uhd_images_downloader.py.in', + '-i', img_root_dir, + '-f', filename, + '-c', md5 + ] + subprocess.check_call(downloader_cmd) + except (subprocess.CalledProcessError, OSError): + print "[ERROR] Failed to run downloader script." + exit(1) + print "== Done!" + +if __name__ == "__main__": + main() |