From bb13ba3914e09f5406a98b16e7c8fda44a02b7d0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 1 Jul 2012 21:45:52 -0700 Subject: utils: added .in extension to images downloader source There seems to be confusion that this file can be used w/o building. The images downloader has been renamed to prevent execution b4 configure. --- host/utils/CMakeLists.txt | 2 +- host/utils/uhd_images_downloader.py | 95 ---------------------------------- host/utils/uhd_images_downloader.py.in | 95 ++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 96 deletions(-) delete mode 100644 host/utils/uhd_images_downloader.py create mode 100644 host/utils/uhd_images_downloader.py.in (limited to 'host/utils') diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index a4ff21eee..413cf3d4e 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -66,7 +66,7 @@ ENDFOREACH(util_source) #UHD images downloader configuration CONFIGURE_FILE( - ${CMAKE_CURRENT_SOURCE_DIR}/uhd_images_downloader.py + ${CMAKE_CURRENT_SOURCE_DIR}/uhd_images_downloader.py.in ${CMAKE_CURRENT_BINARY_DIR}/uhd_images_downloader.py @ONLY) INSTALL(PROGRAMS diff --git a/host/utils/uhd_images_downloader.py b/host/utils/uhd_images_downloader.py deleted file mode 100644 index be76f5b2d..000000000 --- a/host/utils/uhd_images_downloader.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2012 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 . -# - -from optparse import OptionParser -import os -import os.path -import shutil -import sys -import urllib2 -import zipfile - -if __name__ == "__main__": - - #Command line options - parser = OptionParser() - parser.add_option("--download-location", type="string", default="@CMAKE_INSTALL_PREFIX@/share/uhd/images", help="Set custom download location for images, [default=%default]") - parser.add_option("--buffer-size", type="int", default=8192, help="Set download buffer size, [default=%default]",) - (options, args) = parser.parse_args() - - #Configuring image download info - images_src = "@UHD_IMAGES_DOWNLOAD_SRC@" - filename = images_src.split("/")[-1] - - #Configuring image destination - cmake_install_prefix = "@CMAKE_INSTALL_PREFIX@" - if options.download_location != "": - images_dir = options.download_location - else: - images_dir = "@CMAKE_INSTALL_PREFIX@/share/uhd/images" - - u = urllib2.urlopen(images_src) - f = open(filename, "wb") - meta = u.info() - #filesize = int(meta.getheaders("Content-Length")[0]) - filesize = float(int(meta.getheaders("Content-Length")[0])) - - print "Downloading images from: %s" % images_src - - filesize_dl = 0.0 - - #Downloading file - while True: - buffer = u.read(options.buffer_size) - if not buffer: - break - - filesize_dl -= len(buffer) - f.write(buffer) - - status = r"%2.2f MB/%2.2f MB (%3.2f" % (-filesize_dl/1e6, filesize/1e6, (-filesize_dl*100.)/filesize) + r"%)" - status += chr(8)*(len(status)+1) - print status, - - f.close() - - #Extracting contents of zip file - if os.path.exists("tempdir"): - shutil.rmtree("tempdir") - os.mkdir("tempdir") - - images_zip = zipfile.ZipFile(filename) - images_zip.extractall("tempdir") - - #Removing images currently in images_dir - if os.path.exists(images_dir): - try: - shutil.rmtree(images_dir) - except: - sys.stderr.write("\nMake sure you have write permissions in the images directory.\n") - sys.exit(0) - - #Copying downloaded images into images_dir - shutil.copytree("tempdir/%s/share/uhd/images" % filename[:-4],images_dir) - - #Removing tempdir and zip file - shutil.rmtree("tempdir") - images_zip.close() - os.remove(filename) - - print "\nImages successfully installed to: %s" % images_dir diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in new file mode 100644 index 000000000..be76f5b2d --- /dev/null +++ b/host/utils/uhd_images_downloader.py.in @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# +# Copyright 2012 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 . +# + +from optparse import OptionParser +import os +import os.path +import shutil +import sys +import urllib2 +import zipfile + +if __name__ == "__main__": + + #Command line options + parser = OptionParser() + parser.add_option("--download-location", type="string", default="@CMAKE_INSTALL_PREFIX@/share/uhd/images", help="Set custom download location for images, [default=%default]") + parser.add_option("--buffer-size", type="int", default=8192, help="Set download buffer size, [default=%default]",) + (options, args) = parser.parse_args() + + #Configuring image download info + images_src = "@UHD_IMAGES_DOWNLOAD_SRC@" + filename = images_src.split("/")[-1] + + #Configuring image destination + cmake_install_prefix = "@CMAKE_INSTALL_PREFIX@" + if options.download_location != "": + images_dir = options.download_location + else: + images_dir = "@CMAKE_INSTALL_PREFIX@/share/uhd/images" + + u = urllib2.urlopen(images_src) + f = open(filename, "wb") + meta = u.info() + #filesize = int(meta.getheaders("Content-Length")[0]) + filesize = float(int(meta.getheaders("Content-Length")[0])) + + print "Downloading images from: %s" % images_src + + filesize_dl = 0.0 + + #Downloading file + while True: + buffer = u.read(options.buffer_size) + if not buffer: + break + + filesize_dl -= len(buffer) + f.write(buffer) + + status = r"%2.2f MB/%2.2f MB (%3.2f" % (-filesize_dl/1e6, filesize/1e6, (-filesize_dl*100.)/filesize) + r"%)" + status += chr(8)*(len(status)+1) + print status, + + f.close() + + #Extracting contents of zip file + if os.path.exists("tempdir"): + shutil.rmtree("tempdir") + os.mkdir("tempdir") + + images_zip = zipfile.ZipFile(filename) + images_zip.extractall("tempdir") + + #Removing images currently in images_dir + if os.path.exists(images_dir): + try: + shutil.rmtree(images_dir) + except: + sys.stderr.write("\nMake sure you have write permissions in the images directory.\n") + sys.exit(0) + + #Copying downloaded images into images_dir + shutil.copytree("tempdir/%s/share/uhd/images" % filename[:-4],images_dir) + + #Removing tempdir and zip file + shutil.rmtree("tempdir") + images_zip.close() + os.remove(filename) + + print "\nImages successfully installed to: %s" % images_dir -- cgit v1.2.3