import os
import sys
sys.path.append('.')
base_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(base_dir)
import argparse
import utils
import download_util
from downloader.downloader import download_dependency
from downloader.download_util import get_download_path
class CLI(object):
def __init__(self, prog, desc, epilog):
self.parser = argparse.ArgumentParser(
prog=prog,
formatter_class=utils.HelpFormatter,
description=desc,
epilog=epilog,
add_help=False
)
self.parser.add_argument('-h', '--help', nargs=0, action=download_util.CustomHelpAction,
help='Show this help text and update download config')
self.parser.add_argument(
"--os-list", dest="os_list", nargs="+", required=False, choices=download_util.get_os_list(),
action=utils.ValidChoices,
metavar="<OS>", help="Specific OS list to download, supported os are: %(choices)s")
self.parser.add_argument(
"--download", dest="pkg_list", nargs="+", required=False, choices=download_util.get_pkg_list(),
action=utils.ValidChoices, default=[],
metavar="<PKG>|<PKG>==<Version>", help="Specific package list to download, supported packages: %(choices)s")
def run(self, args, check):
if not args:
args = sys.argv[1:]
args = self.parser.parse_args(utils.args_with_comma(args))
if not args.os_list:
self.parser.print_help()
self.parser.error("the following arguments are required: --os-list")
download_dependency(args.os_list, args.pkg_list, get_download_path(), check)
def main(args=None, check=True):
cli = CLI(
"ascend-download",
"Download Ascend Packages and dependence packages for specified OS",
"notes: When <Version> is missing, <PKG> is the latest."
)
return cli.run(args, check)
if __name__ == '__main__':
sys.exit(main())