How to use the knack.log.get_logger function in knack

To help you get started, we’ve selected a few knack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / appservice / _create_util.py View on Github external
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import zipfile
from knack.util import CLIError
from knack.log import get_logger
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.web.models import SkuDescription

from ._constants import (NETCORE_VERSION_DEFAULT, NETCORE_VERSIONS, NODE_VERSION_DEFAULT,
                         NODE_VERSIONS, NETCORE_RUNTIME_NAME, NODE_RUNTIME_NAME, DOTNET_RUNTIME_NAME,
                         DOTNET_VERSION_DEFAULT, DOTNET_VERSIONS, STATIC_RUNTIME_NAME,
                         PYTHON_RUNTIME_NAME, PYTHON_VERSION_DEFAULT, LINUX_SKU_DEFAULT, OS_DEFAULT)

logger = get_logger(__name__)


def _resource_client_factory(cli_ctx, **_):
    from azure.cli.core.profiles import ResourceType
    return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES)


def web_client_factory(cli_ctx, **_):
    from azure.mgmt.web import WebSiteManagementClient
    return get_mgmt_service_client(cli_ctx, WebSiteManagementClient)


def zip_contents_from_dir(dirPath, lang):
    relroot = os.path.abspath(os.path.join(dirPath, os.pardir))
    path_and_file = os.path.splitdrive(dirPath)[1]
    file_val = os.path.split(path_and_file)[1]
github Azure / azure-devops-cli-extension / azure-dev-cli-extensions / azext_dev / dev / boards / work_item.py View on Github external
# --------------------------------------------------------------------------------------------

import webbrowser

from knack.log import get_logger
from knack.util import CLIError
from vsts.exceptions import VstsServiceError
from vsts.work_item_tracking.v4_0.models.json_patch_operation import JsonPatchOperation
from vsts.work_item_tracking.v4_0.models.wiql import Wiql
from azext_dev.dev.common.identities import (ME, get_current_identity, resolve_identity)
from azext_dev.dev.common.services import (get_work_item_tracking_client,
                                      resolve_instance,
                                      resolve_instance_and_project)
from azext_dev.dev.common.uri import uri_quote

logger = get_logger(__name__)

def create_work_item(work_item_type, title, description=None, assigned_to=None, state=None, area=None,
                     iteration=None, reason=None, discussion=None, fields=None, open_browser=False,
                     team_instance=None, project=None, detect=None):
    """Create a work item.
    :param work_item_type: Name of the work item type (e.g. Bug).
    :type work_item_type: str
    :param title: Title of the work item.
    :type title: str
    :param description: Description of the work item.
    :type description: str
    :param assigned_to: Name of the person the work item is assigned-to (e.g. fabrikam).
    :type assigned_to: str
    :param state: State of the work item (e.g. active)
    :type state: str
    :param area: Area the work item is assigned to (e.g. Demos)
github microsoft / knack / knack / output.py View on Github external
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function

import errno
import json
import traceback
from collections import OrderedDict
from six import StringIO, text_type, u, string_types

from .util import CLIError, CommandResultItem, CtxTypeError
from .events import EVENT_INVOKER_POST_PARSE_ARGS, EVENT_PARSER_GLOBAL_CREATE
from .log import get_logger

logger = get_logger(__name__)


def _decode_str(output):
    if not isinstance(output, text_type):
        output = u(str(output))
    return output


class _ComplexEncoder(json.JSONEncoder):

    def default(self, o):  # pylint: disable=method-hidden
        if isinstance(o, bytes) and not isinstance(o, str):
            return o.decode()
        return json.JSONEncoder.default(self, o)
github Azure / azure-cli / src / azure-cli-core / azure / cli / core / extension / _resolve.py View on Github external
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from pkg_resources import parse_version

from knack.log import get_logger

from azure.cli.core.extension import ext_compat_with_cli, WHEEL_INFO_RE
from azure.cli.core.extension._index import get_index_extensions


logger = get_logger(__name__)


class NoExtensionCandidatesError(Exception):
    pass


def _is_not_platform_specific(item):
    parsed_filename = WHEEL_INFO_RE(item['filename'])
    p = parsed_filename.groupdict()
    if p.get('pyver') == 'py2.py3' and p.get('abi') == 'none' and p.get('plat') == 'any':
        return True
    logger.debug("Skipping '%s' as not universal wheel."
                 "We do not currently support platform specific extension detection. "
                 "They can be installed with the full URL %s", item['filename'], item.get('downloadUrl'))
    return False
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / feedback / custom.py View on Github external
from knack.util import CLIError

from azure.cli.core.extension._resolve import resolve_project_url_from_index, NoExtensionCandidatesError
from azure.cli.core.util import get_az_version_string, open_page_in_browser, can_launch_browser, in_cloud_console
from azure.cli.core.azlogging import _UNKNOWN_COMMAND, _CMD_LOG_LINE_PREFIX
from azure.cli.core.commands.constants import SURVEY_PROMPT

_ONE_MIN_IN_SECS = 60

_ONE_HR_IN_SECS = 3600

# see: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
_MAX_URL_LENGTH = 2035


logger = get_logger(__name__)

_MSG_THNK = 'Thanks for your feedback!'

_GET_STARTED_URL = "aka.ms/azcli/get-started"
_QUESTIONS_URL = "aka.ms/azcli/questions"

_CLI_ISSUES_URL = "aka.ms/azcli/issues"
_RAW_CLI_ISSUES_URL = "https://github.com/azure/azure-cli/issues/new"

_EXTENSIONS_ISSUES_URL = "aka.ms/azcli/ext/issues"
_RAW_EXTENSIONS_ISSUES_URL = "https://github.com/azure/azure-cli-extensions/issues/new"

_MSG_INTR = \
    '\nWe appreciate your feedback!\n\n' \
    'For more information on getting started, visit: {}\n' \
    'If you have questions, visit our Stack Overflow page: {}\n'\
github Azure / azure-cli / src / azure-cli-core / azure / cli / core / cloud.py View on Github external
# --------------------------------------------------------------------------------------------

import os
import json
from pprint import pformat
from six.moves import configparser

from azure.cli.core.profiles import API_PROFILES
from azure.cli.core._config import GLOBAL_CONFIG_DIR
from azure.cli.core.util import urlretrieve

from knack.log import get_logger
from knack.util import CLIError
from knack.config import get_config_parser

logger = get_logger(__name__)

CLOUD_CONFIG_FILE = os.path.join(GLOBAL_CONFIG_DIR, 'clouds.config')


class CloudNotRegisteredException(Exception):
    def __init__(self, cloud_name):
        super(CloudNotRegisteredException, self).__init__(cloud_name)
        self.cloud_name = cloud_name

    def __str__(self):
        return "The cloud '{}' is not registered.".format(self.cloud_name)


class CloudAlreadyRegisteredException(Exception):
    def __init__(self, cloud_name):
        super(CloudAlreadyRegisteredException, self).__init__(cloud_name)
github Azure / azure-cli-extensions / src / storage-preview / azext_storage_preview / azcopy / util.py View on Github external
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


import os
import json
import platform
import subprocess
import datetime
from six.moves.urllib.parse import urlparse
from azure.cli.core._profile import Profile
from knack.log import get_logger

logger = get_logger(__name__)


STORAGE_RESOURCE_ENDPOINT = "https://storage.azure.com"
SERVICES = {'blob', 'file'}
AZCOPY_VERSION = '10.3.1'


class AzCopy(object):
    system_executable_path = {
        'Darwin': ['azcopy_darwin_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],
        'Linux': ['azcopy_linux_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],
        'Windows': ['azcopy_windows_amd64_{}'.format(AZCOPY_VERSION), 'azcopy.exe']
    }

    def __init__(self, creds=None):
        self.system = platform.system()
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / storage / operations / blob.py View on Github external
def storage_blob_copy_batch(cmd, client, source_client, container_name=None,
                            destination_path=None, source_container=None, source_share=None,
                            source_sas=None, pattern=None, dryrun=False):
    """Copy a group of blob or files to a blob container."""
    logger = None
    if dryrun:
        logger = get_logger(__name__)
        logger.warning('copy files or blobs to blob container')
        logger.warning('    account %s', client.account_name)
        logger.warning('  container %s', container_name)
        logger.warning('     source %s', source_container or source_share)
        logger.warning('source type %s', 'blob' if source_container else 'file')
        logger.warning('    pattern %s', pattern)
        logger.warning(' operations')

    if source_container:
        # copy blobs for blob container

        # if the source client is None, recreate one from the destination client.
        source_client = source_client or create_blob_service_from_storage_client(cmd, client)
        if not source_sas:
            source_sas = create_short_lived_container_sas(cmd, source_client.account_name, source_client.account_key,
                                                          source_container)
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / vm / disk_encryption.py View on Github external
# --------------------------------------------------------------------------------------------
import uuid
import os

from knack.log import get_logger

from azure.cli.core.commands import LongRunningOperation

from azure.cli.command_modules.vm.custom import set_vm, _compute_client_factory, _is_linux_os
from azure.cli.command_modules.vm._vm_utils import get_key_vault_base_url, create_keyvault_data_plane_client

_DATA_VOLUME_TYPE = 'DATA'
_ALL_VOLUME_TYPE = 'ALL'
_STATUS_ENCRYPTED = 'Encrypted'

logger = get_logger(__name__)

vm_extension_info = {
    'Linux': {
        'publisher': os.environ.get('ADE_TEST_EXTENSION_PUBLISHER') or 'Microsoft.Azure.Security',
        'name': os.environ.get('ADE_TEST_EXTENSION_NAME') or 'AzureDiskEncryptionForLinux',
        'version': '1.1',
        'legacy_version': '0.1'
    },
    'Windows': {
        'publisher': os.environ.get('ADE_TEST_EXTENSION_PUBLISHER') or 'Microsoft.Azure.Security',
        'name': os.environ.get('ADE_TEST_EXTENSION_NAME') or 'AzureDiskEncryption',
        'version': '2.2',
        'legacy_version': '1.1'
    }
}
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / iotcentral / custom.py View on Github external
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger
from knack.util import CLIError

from azure.mgmt.iotcentral.models import (AppSkuInfo,
                                          App)

from ._client_factory import resource_service_factory

logger = get_logger(__name__)


def iotcentral_app_create(
        cmd, client, app_name, resource_group_name, subdomain, sku="S1",
        location=None, template=None, display_name=None
):
    cli_ctx = cmd.cli_ctx
    location = _ensure_location(cli_ctx, resource_group_name, location)
    display_name = _ensure_display_name(app_name, display_name)
    appSku = AppSkuInfo(name=sku)

    app = App(subdomain=subdomain,
              location=location,
              display_name=display_name,
              sku=appSku,
              template=template)