Hello community, here is the log from the commit of package azure-cli-find for openSUSE:Factory checked in at 2019-10-31 18:16:13 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/azure-cli-find (Old) and /work/SRC/openSUSE:Factory/.azure-cli-find.new.2990 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "azure-cli-find" Thu Oct 31 18:16:13 2019 rev:7 rq:742693 version:0.3.4 Changes: -------- --- /work/SRC/openSUSE:Factory/azure-cli-find/azure-cli-find.changes 2019-06-05 11:43:36.907034218 +0200 +++ /work/SRC/openSUSE:Factory/.azure-cli-find.new.2990/azure-cli-find.changes 2019-10-31 18:16:13.478070722 +0100 @@ -1,0 +2,8 @@ +Thu Oct 24 12:10:28 UTC 2019 - John Paul Adrian Glaubitz <[email protected]> + +- New upstream release + + Version 0.3.4 + + For detailed information about changes see the + HISTORY.txt file provided with this package + +------------------------------------------------------------------- Old: ---- azure-cli-find-0.2.13.tar.gz New: ---- azure-cli-find-0.3.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ azure-cli-find.spec ++++++ --- /var/tmp/diff_new_pack.0UV1rW/_old 2019-10-31 18:16:14.394071671 +0100 +++ /var/tmp/diff_new_pack.0UV1rW/_new 2019-10-31 18:16:14.402071678 +0100 @@ -17,7 +17,7 @@ Name: azure-cli-find -Version: 0.2.13 +Version: 0.3.4 Release: 0 Summary: Microsoft Azure CLI 'find' Command Module License: MIT ++++++ azure-cli-find-0.2.13.tar.gz -> azure-cli-find-0.3.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/HISTORY.rst new/azure-cli-find-0.3.4/HISTORY.rst --- old/azure-cli-find-0.2.13/HISTORY.rst 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/HISTORY.rst 2019-06-13 23:17:46.000000000 +0200 @@ -3,6 +3,26 @@ Release History =============== +0.3.4 +++++++ +* Minor fixes + +0.3.3 +++++++ +* Minor fixes + +0.3.2 +++++++ +* Minor fixes + +0.3.1 +++++++ +* Minor fixes + +0.3.0 +++++++ +* Major functionality update + 0.2.13 ++++++ * Minor fixes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/PKG-INFO new/azure-cli-find-0.3.4/PKG-INFO --- old/azure-cli-find-0.2.13/PKG-INFO 2018-12-20 01:55:46.000000000 +0100 +++ new/azure-cli-find-0.3.4/PKG-INFO 2019-06-13 23:17:57.000000000 +0200 @@ -1,7 +1,7 @@ Metadata-Version: 1.1 Name: azure-cli-find -Version: 0.2.13 -Summary: Microsoft Azure Command-Line Tools Find Command Module +Version: 0.3.4 +Summary: Intelligent querying for CLI Example information. Home-page: https://github.com/Azure/azure-cli Author: Microsoft Corporation Author-email: [email protected] @@ -9,7 +9,7 @@ Description: Microsoft Azure CLI 'find' Command Module ============================================= - Fulltext search and indexing module for Azure CLI + Find examples for any Azure CLI command .. :changelog: @@ -17,6 +17,26 @@ Release History =============== + 0.3.4 + ++++++ + * Minor fixes + + 0.3.3 + ++++++ + * Minor fixes + + 0.3.2 + ++++++ + * Minor fixes + + 0.3.1 + ++++++ + * Minor fixes + + 0.3.0 + ++++++ + * Major functionality update + 0.2.13 ++++++ * Minor fixes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/README.rst new/azure-cli-find-0.3.4/README.rst --- old/azure-cli-find-0.2.13/README.rst 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/README.rst 2019-06-13 23:17:46.000000000 +0200 @@ -1,4 +1,4 @@ Microsoft Azure CLI 'find' Command Module ============================================= -Fulltext search and indexing module for Azure CLI +Find examples for any Azure CLI command diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure/cli/command_modules/find/_gather_commands.py new/azure-cli-find-0.3.4/azure/cli/command_modules/find/_gather_commands.py --- old/azure-cli-find-0.2.13/azure/cli/command_modules/find/_gather_commands.py 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure/cli/command_modules/find/_gather_commands.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,84 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -import yaml - -from knack.help import REQUIRED_TAG -from knack.help_files import helps - - -def build_command_table(cli_ctx): - from azure.cli.core import MainCommandsLoader - cmd_table = MainCommandsLoader(cli_ctx).load_command_table(None) - for command in cmd_table: - cmd_table[command].load_arguments() - - data = {} - for command in cmd_table: - com_descip = {} - param_descrip = {} - com_descip['short-summary'] = cmd_table[command].description() \ - if callable(cmd_table[command].description) \ - else cmd_table[command].description or '' - com_descip['examples'] = '' - - for key in cmd_table[command].arguments: - required = '' - help_desc = '' - if cmd_table[command].arguments[key].type.settings.get('required'): - required = REQUIRED_TAG - if cmd_table[command].arguments[key].type.settings.get('help'): - help_desc = cmd_table[command].arguments[key].type.settings.get('help') - - name_options = [] - for name in cmd_table[command].arguments[key].options_list: - name_options.append(name) - - options = { - 'name': name_options, - 'required': required, - 'help': help_desc - } - param_descrip[cmd_table[command].arguments[key].options_list[0]] = options - - com_descip['parameters'] = param_descrip - data[command] = com_descip - - for command in helps: - diction_help = yaml.load(helps[command]) - if command not in data: - data[command] = { - 'short-summary': diction_help.get( - 'short-summary', ''), - 'long-summary': diction_help.get('long-summary', ''), - 'parameters': {} - } - else: - data[command]['short-summary'] = diction_help.get('short-summary', - data[command].get('short-summary', '')) - data[command]['long-summary'] = diction_help.get("long-summary", '') - data[command]['parameters'] = {} - - if 'parameters' in diction_help: - for param in diction_help["parameters"]: - if param['name'].split()[0] not in data[command]['parameters']: - options = { - 'name': name_options, - 'required': required, - 'help': help_desc - } - data[command]['parameters'] = { - param["name"].split()[0]: options - } - if 'short-summary' in param: - data[command]['parameters'][param['name'].split()[0]]['help'] \ - = param['short-summary'] - if 'examples' in diction_help: - string_example = '' - for example in diction_help['examples']: - string_example += example.get('name', '') + '\n' + example.get('text', '') + '\n' - data[command]['examples'] = string_example - - return data diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure/cli/command_modules/find/_help.py new/azure-cli-find-0.3.4/azure/cli/command_modules/find/_help.py --- old/azure-cli-find-0.2.13/azure/cli/command_modules/find/_help.py 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure/cli/command_modules/find/_help.py 2019-06-13 23:17:46.000000000 +0200 @@ -8,9 +8,15 @@ helps['find'] = """ type: command - short-summary: Find Azure CLI commands. + short-summary: I'm an AI robot, my advice is based on our Azure documentation as well as the usage patterns of Azure CLI and Azure ARM users. Using me improves Azure products and documentation. examples: - - name: Search for commands containing 'vm' or 'secret' - text: > - az find -q vm secret + - name: Give me any Azure CLI group and I’ll show the most popular commands within the group. + text: | + az find 'az storage' + - name: Give me any Azure CLI command and I’ll show the most popular parameters and subcommands. + text: | + az find 'az monitor activity-log list' + - name: You can also enter a search term, and I'll try to help find the best commands. + text: | + az find 'arm template' """ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure/cli/command_modules/find/_params.py new/azure-cli-find-0.3.4/azure/cli/command_modules/find/_params.py --- old/azure-cli-find-0.2.13/azure/cli/command_modules/find/_params.py 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure/cli/command_modules/find/_params.py 2019-06-13 23:17:46.000000000 +0200 @@ -6,5 +6,4 @@ def load_arguments(self, _): with self.argument_context('find') as c: - c.argument('criteria', options_list=['--search-query', '-q'], help='Query text to find.', nargs='+') - c.argument('reindex', help='Clear the current index and reindex the command modules.') + c.positional('cli_term', help='An Azure CLI command or group for which you need an example.') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure/cli/command_modules/find/commands.py new/azure-cli-find-0.3.4/azure/cli/command_modules/find/commands.py --- old/azure-cli-find-0.2.13/azure/cli/command_modules/find/commands.py 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure/cli/command_modules/find/commands.py 2019-06-13 23:17:46.000000000 +0200 @@ -6,4 +6,5 @@ def load_command_table(self, _): with self.command_group('') as g: - g.custom_command('find', 'find') + g.custom_command('find', 'process_query', is_preview=True) + return self.command_table diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure/cli/command_modules/find/custom.py new/azure-cli-find-0.3.4/azure/cli/command_modules/find/custom.py --- old/azure-cli-find-0.2.13/azure/cli/command_modules/find/custom.py 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure/cli/command_modules/find/custom.py 2019-06-13 23:17:46.000000000 +0200 @@ -2,115 +2,106 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- - from __future__ import print_function -import os -import textwrap -import shutil - +import random +import json import re -import six +import sys +import platform +import requests +import colorama # pylint: disable=import-error -from azure.cli.command_modules.find._gather_commands import build_command_table -from azure.cli.core.api import get_config_dir -INDEX_DIR_PREFIX = 'search_index' -INDEX_VERSION = 'v1' -INDEX_PATH = os.path.join(get_config_dir(), '{}_{}'.format(INDEX_DIR_PREFIX, INDEX_VERSION)) - - -def _get_schema(): - from whoosh.fields import TEXT, Schema - from whoosh.analysis import StemmingAnalyzer - stem_ana = StemmingAnalyzer() - return Schema( - cmd_name=TEXT(stored=True, analyzer=stem_ana, field_boost=1.3), - short_summary=TEXT(stored=True, analyzer=stem_ana), - long_summary=TEXT(stored=True, analyzer=stem_ana), - examples=TEXT(stored=True, analyzer=stem_ana)) - - -def _purge(): - for f in os.listdir(get_config_dir()): - if re.search("^{}_*".format(INDEX_DIR_PREFIX), f): - shutil.rmtree(os.path.join(get_config_dir(), f)) - - -def _create_index(cli_ctx): - from whoosh import index - _purge() - os.mkdir(INDEX_PATH) - index.create_in(INDEX_PATH, _get_schema()) - - # index help - ix = index.open_dir(INDEX_PATH) - writer = ix.writer() - for command, document in build_command_table(cli_ctx).items(): - writer.add_document( - cmd_name=six.u(command), - short_summary=six.u(document.get('short-summary', '')), - long_summary=six.u(document.get('long-summary', '')), - examples=six.u(document.get('examples', '')) - ) - writer.commit() - - -def _get_index(cli_ctx): - from whoosh import index - - # create index if it does not exist already - if not os.path.exists(INDEX_PATH): - _create_index(cli_ctx) - return index.open_dir(INDEX_PATH) - - -def _print_hit(hit): - def print_para(field): - if field not in hit: - print(hit) - print(textwrap.fill( - hit[field], - initial_indent=' ', - subsequent_indent=' ')) - - print('`az {0}`'.format(hit['cmd_name'])) - print_para('short_summary') - if hit.get('long_summary', None): - print_para('long_summary') - print('') - - -def find(cmd, criteria, reindex=False): - from whoosh.qparser import MultifieldParser - if reindex: - _create_index(cmd.cli_ctx) +from azure.cli.core import telemetry as telemetry_core +from azure.cli.core import __version__ as core_version +from pkg_resources import parse_version +from knack.log import get_logger +logger = get_logger(__name__) - try: - ix = _get_index(cmd.cli_ctx) - except ValueError: - # got a pickle error because the index was written by a different python version - # recreate the index and proceed - _create_index(cmd.cli_ctx) - ix = _get_index(cmd.cli_ctx) - - qp = MultifieldParser( - ['cmd_name', 'short_summary', 'long_summary', 'examples'], - schema=_get_schema() - ) - - if 'OR' in criteria or 'AND' in criteria: - # looks more advanced, let's trust them to make a great query - q = qp.parse(" ".join(criteria)) +WAIT_MESSAGE = ['I\'m an AI bot (learn more: aka.ms/aladdinkb); Let me see how I can help you...'] + +EXTENSION_NAME = 'find' + + +def process_query(cli_term): + print(random.choice(WAIT_MESSAGE), file=sys.stderr) + response = call_aladdin_service(cli_term) + + if response.status_code != 200: + logger.error('[?] Unexpected Error: [HTTP %s]: Content: %s', response.status_code, response.content) else: - # let's help out with some OR's to provide a less restrictive search - expanded_query = " OR ".join(criteria) + " OR '{}'".format(criteria) - q = qp.parse(expanded_query) - - with ix.searcher() as searcher: - from whoosh.highlight import UppercaseFormatter, ContextFragmenter - results = searcher.search(q) - results.fragmenter = ContextFragmenter(maxchars=300, surround=200) - results.formatter = UppercaseFormatter() - for hit in results: - _print_hit(hit) + if (platform.system() == 'Windows' and should_enable_styling()): + colorama.init(convert=True) + + answer_list = json.loads(response.content.decode(response.encoding)) + if (not answer_list or answer_list[0]['source'] == 'bing'): + print("\nSorry I am not able to help with [" + cli_term + "]." + "\nTry typing the beginning of a command e.g. " + style_message('az vm') + ".", file=sys.stderr) + else: + if answer_list[0]['source'] == 'pruned': + print("\nMore commands and examples are available in the latest version of the CLI," + "please update for the best experience.") + answer_list.pop(0) + print("\nHere are the most common ways to use [" + cli_term + "]: \n", file=sys.stderr) + num_results_to_show = min(3, len(answer_list)) + for i in range(num_results_to_show): + current_title = answer_list[i]['title'].strip() + current_snippet = answer_list[i]['snippet'].strip() + if current_title.startswith("az "): + current_title, current_snippet = current_snippet, current_title + current_title = current_title.split('\r\n')[0] + elif '```azurecli\r\n' in current_snippet: + start_index = current_snippet.index('```azurecli\r\n') + len('```azurecli\r\n') + current_snippet = current_snippet[start_index:] + current_snippet = current_snippet.replace('```', '').replace(current_title, '').strip() + current_snippet = re.sub(r'\[.*\]', '', current_snippet).strip() + print(style_message(current_title)) + print(current_snippet + '\n') + + +def style_message(msg): + if should_enable_styling(): + try: + msg = colorama.Style.BRIGHT + msg + colorama.Style.RESET_ALL + except KeyError: + pass + return msg + + +def should_enable_styling(): + try: + # Style if tty stream is available + if sys.stdout.isatty(): + return True + except AttributeError: + pass + return False + + +def call_aladdin_service(query): + client_request_id = '' + if telemetry_core._session.application: # pylint: disable=protected-access + client_request_id = telemetry_core._session.application.data['headers']['x-ms-client-request-id'] # pylint: disable=protected-access + + context = { + 'session_id': telemetry_core._session._get_base_properties()['Reserved.SessionId'], # pylint: disable=protected-access + 'subscription_id': telemetry_core._get_azure_subscription_id(), # pylint: disable=protected-access + 'client_request_id': client_request_id, # pylint: disable=protected-access + 'installation_id': telemetry_core._get_installation_id(), # pylint: disable=protected-access + 'version_number': str(parse_version(core_version)) + } + + service_input = { + 'paragraphText': "<div id='dummyHeader'></div>", + 'currentPageUrl': "", + 'query': "ALADDIN-CLI:" + query, + 'context': context + } + + api_url = 'https://aladdinservice-prod.azurewebsites.net/api/aladdin/generateCards' + headers = {'Content-Type': 'application/json'} + + response = requests.post(api_url, headers=headers, json=service_input) + + return response diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure_cli_find.egg-info/PKG-INFO new/azure-cli-find-0.3.4/azure_cli_find.egg-info/PKG-INFO --- old/azure-cli-find-0.2.13/azure_cli_find.egg-info/PKG-INFO 2018-12-20 01:55:46.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure_cli_find.egg-info/PKG-INFO 2019-06-13 23:17:57.000000000 +0200 @@ -1,7 +1,7 @@ Metadata-Version: 1.1 Name: azure-cli-find -Version: 0.2.13 -Summary: Microsoft Azure Command-Line Tools Find Command Module +Version: 0.3.4 +Summary: Intelligent querying for CLI Example information. Home-page: https://github.com/Azure/azure-cli Author: Microsoft Corporation Author-email: [email protected] @@ -9,7 +9,7 @@ Description: Microsoft Azure CLI 'find' Command Module ============================================= - Fulltext search and indexing module for Azure CLI + Find examples for any Azure CLI command .. :changelog: @@ -17,6 +17,26 @@ Release History =============== + 0.3.4 + ++++++ + * Minor fixes + + 0.3.3 + ++++++ + * Minor fixes + + 0.3.2 + ++++++ + * Minor fixes + + 0.3.1 + ++++++ + * Minor fixes + + 0.3.0 + ++++++ + * Major functionality update + 0.2.13 ++++++ * Minor fixes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure_cli_find.egg-info/SOURCES.txt new/azure-cli-find-0.3.4/azure_cli_find.egg-info/SOURCES.txt --- old/azure-cli-find-0.2.13/azure_cli_find.egg-info/SOURCES.txt 2018-12-20 01:55:46.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure_cli_find.egg-info/SOURCES.txt 2019-06-13 23:17:57.000000000 +0200 @@ -7,7 +7,6 @@ azure/cli/__init__.py azure/cli/command_modules/__init__.py azure/cli/command_modules/find/__init__.py -azure/cli/command_modules/find/_gather_commands.py azure/cli/command_modules/find/_help.py azure/cli/command_modules/find/_params.py azure/cli/command_modules/find/commands.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/azure_cli_find.egg-info/requires.txt new/azure-cli-find-0.3.4/azure_cli_find.egg-info/requires.txt --- old/azure-cli-find-0.2.13/azure_cli_find.egg-info/requires.txt 2018-12-20 01:55:46.000000000 +0100 +++ new/azure-cli-find-0.3.4/azure_cli_find.egg-info/requires.txt 2019-06-13 23:17:57.000000000 +0200 @@ -1,2 +1 @@ azure-cli-core -whoosh diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-find-0.2.13/setup.py new/azure-cli-find-0.3.4/setup.py --- old/azure-cli-find-0.2.13/setup.py 2018-12-20 01:55:19.000000000 +0100 +++ new/azure-cli-find-0.3.4/setup.py 2019-06-13 23:17:46.000000000 +0200 @@ -15,7 +15,7 @@ cmdclass = {} -VERSION = "0.2.13" +VERSION = "0.3.4" CLASSIFIERS = [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', @@ -31,8 +31,7 @@ ] DEPENDENCIES = [ - 'azure-cli-core', - 'whoosh' + 'azure-cli-core' ] with open('README.rst', 'r', encoding='utf-8') as f: @@ -43,7 +42,7 @@ setup( name='azure-cli-find', version=VERSION, - description='Microsoft Azure Command-Line Tools Find Command Module', + description='Intelligent querying for CLI Example information.', long_description=README + '\n\n' + HISTORY, license='MIT', author='Microsoft Corporation',
