|
| 1 | +import pip |
| 2 | +from azure.cli.commands import command, description, option |
| 3 | +from azure.cli._locale import L |
| 4 | + |
| 5 | +# TODO:: Support installing/removing of a specific version |
| 6 | + |
| 7 | +@command('components list') |
| 8 | +@description(L('List the installed components.')) |
| 9 | +def list_components(args, unexpected): #pylint: disable=unused-argument |
| 10 | + return sorted(["%s (%s)" % (dist.key.replace('azure-cli-', ''), dist.version) for dist in pip.get_installed_distributions(local_only=False) if dist.key.startswith('azure-cli-')]) |
| 11 | + |
| 12 | +# @command('components check') |
| 13 | +# @description(L('Check a component for an update')) |
| 14 | +# @option('--name -n <name>') |
| 15 | +# def install_component(args, unexpected): #pylint: disable=unused-argument |
| 16 | +# component_name = args.get('name') |
| 17 | +# if not component_name: |
| 18 | +# # Show all |
| 19 | +# pip.main(['list', '--pre', '--outdated', '--isolated', |
| 20 | +# '--trusted-host', '40.112.211.51', |
| 21 | +# '--extra-index-url', 'http://40.112.211.51:8080/']) |
| 22 | +# else: |
| 23 | +# try: |
| 24 | +# __import__('azure.cli.command_modules.'+component_name+'.__main__') |
| 25 | +# # Check for updates |
| 26 | +# pip.main(['list', '--pre', '--outdated', '--isolated', |
| 27 | +# '--trusted-host', '40.112.211.51', |
| 28 | +# '--find-links', 'http://40.112.211.51:8080/simple/azure-cli-'+component_name]) |
| 29 | +# except ImportError: |
| 30 | +# raise RuntimeError("Component not installed.") |
| 31 | + |
| 32 | +# @command('components install') |
| 33 | +# @description(L('Install a component')) |
| 34 | +# @option('--name -n <name>', required=True) |
| 35 | +# @option('--version -v <version>') |
| 36 | +# def install_component(args, unexpected): #pylint: disable=unused-argument |
| 37 | +# component_name = args.get('name') |
| 38 | +# if not component_name: |
| 39 | +# raise RuntimeError("Specify a component name.") |
| 40 | +# try: |
| 41 | +# __import__('azure.cli.command_modules.'+component_name+'.__main__') |
| 42 | +# # Check for updates |
| 43 | +# pip.main(['list', '--pre', '--outdated', '--isolated', |
| 44 | +# '--trusted-host', '40.112.211.51', |
| 45 | +# '--find-links', 'http://40.112.211.51:8080/simple/azure-cli-'+component_name]) |
| 46 | +# raise RuntimeError("Component already installed.") |
| 47 | +# except ImportError: |
| 48 | +# version_no = '=='+args.get('version') if args.get('version') else '' |
| 49 | +# pip.main(['install', '--quiet', '--isolated', '--disable-pip-version-check', 'azure-cli-'+component_name+version_no, |
| 50 | +# '--extra-index-url', 'http://40.112.211.51:8080/', '--trusted-host', '40.112.211.51']) |
| 51 | + |
| 52 | +# @command('components update') |
| 53 | +# @description(L('Update a component')) |
| 54 | +# @option('--name -n <name>', required=True) |
| 55 | +# def update_component(args, unexpected): #pylint: disable=unused-argument |
| 56 | +# component_name = args.get('name') |
| 57 | +# if not component_name: |
| 58 | +# raise RuntimeError("Specify a component name.") |
| 59 | +# try: |
| 60 | +# __import__('azure.cli.command_modules.'+component_name+'.__main__') |
| 61 | +# pip.main(['install', '--quiet', '--isolated', '--disable-pip-version-check', '--upgrade', 'azure-cli-'+component_name, |
| 62 | +# '--extra-index-url', 'http://40.112.211.51:8080/', '--trusted-host', '40.112.211.51']) |
| 63 | +# except ImportError: |
| 64 | +# raise RuntimeError("Component not installed.") |
| 65 | + |
| 66 | +# @command('components remove') |
| 67 | +# @description(L('Remove a component')) |
| 68 | +# @option('--name -n <name>', required=True) |
| 69 | +# def remove_component(args, unexpected): #pylint: disable=unused-argument |
| 70 | +# component_name = args.get('name') |
| 71 | +# if not component_name: |
| 72 | +# raise RuntimeError("Specify a component name.") |
| 73 | +# try: |
| 74 | +# __import__('azure.cli.command_modules.'+component_name+'.__main__') |
| 75 | +# # The component is installed so we can uninstall it |
| 76 | +# pip.main(['uninstall', '--quiet', '--isolated', '--yes', 'azure-cli-'+component_name]) |
| 77 | +# except ImportError: |
| 78 | +# raise RuntimeError("Component not installed.") |
0 commit comments