#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2015 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import argparse
import sys
from common import vmimages


def main():
    parser = argparse.ArgumentParser(description='Download a virtual machine')
    parser.add_argument("--force", action="store_true", help="Force unnecessary downloads, delete images even if they aren't old")
    parser.add_argument("--store", action="append", help="Where to find images")
    parser.add_argument("--prune", action="store_true", help="Remove unused images and links")
    parser.add_argument("-d", "--dry-run-prune", dest="dryrun", action="store_true", help="Don't actually delete images and links")
    parser.add_argument('image', nargs='*')
    args = parser.parse_args()

    # By default download all links
    if not args.image and not args.prune:
        args.image = vmimages.every_image()

    if args.prune:
        vmimages.prune_images(args.force, args.dryrun)
    vmimages.download_images(args.image, args.force, args.store)

if __name__ == '__main__':
    sys.exit(main())
