uhd/images/create_imgs_package.py
Martin Braun 30b157e4cf images: Clear out code from days of yore
The images/ subdir is used to create images packages for release tags.
However, it contained a lot of code from many releases ago, prior to the
usage of the cache/ directory.

This simply removes all the old code that is no longer required for
creating release packages.
2021-12-17 11:18:53 -06:00

84 lines
2.6 KiB
Python
Executable File

#!/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/>.
#
"""
Command-line utility to create a .zip-file with the current image set.
"""
import sys
import re
import os
import subprocess
import argparse
import shutil
import populate_images
def parse_args():
""" Parse args, duh """
parser = argparse.ArgumentParser()
parser.add_argument(
'--version',
help="Specify version. Will detect from tag otherwise."
)
return parser.parse_args()
def download_images(img_root_dir):
"""
Run the images downloader
"""
populate_images.download_images(img_root_dir)
def get_version():
"""
Figure out version based on tag.
"""
try:
git_cmd = ['git', 'describe', '--abbrev=0', '--tags']
git_output = subprocess.check_output(git_cmd).decode('UTF-8')
except subprocess.CalledProcessError as ex:
print(ex.output)
sys.exit(1)
print("Detected tag: {}".format(git_output))
version_mobj = re.search(r'[0-9]+\.[0-9]+\.[0-9]+\.[0-9]', git_output)
if version_mobj is None:
print("Error: Failure to resolve version from tag!")
sys.exit(1)
return version_mobj.group(0)
def main():
""" Go, go, go! """
args = parse_args()
img_root_dir = os.path.join(populate_images.get_images_dir(), 'images')
print("== Clearing out the images directory at {}, if present...".format(img_root_dir))
shutil.rmtree(img_root_dir, ignore_errors=True)
print("== Downloading images...")
download_images(img_root_dir)
print("== Determining version...")
version = args.version if args.version is not None else get_version()
print("Version string: {}".format(version))
print("== Creating archives...")
archive_cmd = ["./make_zip.sh", version]
try:
subprocess.call(archive_cmd)
except subprocess.CalledProcessError as ex:
print(ex.output)
sys.exit(1)
print("== Done!")
if __name__ == "__main__":
main()