Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# For all codes, run 'pylint --list-msgs' or go to 'http://pylint-messages.wikidot.com/all-codes'
# C0111 Missing docstring
# C0103 Invalid %s name "%s"
# C0303 Trailing whitespace
# I0011 Warning locally suppressed using disable-msg
# W0511 fixme
disable=C0111,C0103,C0303,I0011,W0511
disable=C0111,C0103,I0011,W0511
[DESIGN]
# Maximum number of locals for function / method body
max-locals=25
Expand Down
24 changes: 12 additions & 12 deletions src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function
from __future__ import print_function
import sys

from ._locale import L, get_file as locale_get_file
Expand Down Expand Up @@ -69,9 +69,9 @@ def __init__(self, prog):
self.global_args = {'--verbose', '--debug'}

def add_command(self,
handler,
name=None,
description=None,
handler,
name=None,
description=None,
args=None):
'''Registers a command that may be parsed by this parser.

Expand Down Expand Up @@ -124,9 +124,9 @@ def add_command(self,


def execute(self,
args,
show_usage=False,
show_completions=False,
args,
show_usage=False,
show_completions=False,
out=sys.stdout):
'''Parses `args` and invokes the associated handler.

Expand Down Expand Up @@ -173,7 +173,7 @@ def not_global(a):
except LookupError:
logger.debug('Missing data for noun %s', n)
show_usage = True

if show_completions:
return ArgumentParser._display_completions(m, out)
if show_usage:
Expand All @@ -195,7 +195,7 @@ def not_global(a):
elif target_value[1] is True:
# Arg with no value
if value is not None:
print(L("argument '{0}' does not take a value").format(key_n),
print(L("argument '{0}' does not take a value").format(key_n),
file=out)
return self._display_usage(nouns, m, out)
parsed.add_from_dotted(target_value[0], True)
Expand All @@ -219,20 +219,20 @@ def not_global(a):
finally:
sys.stdout = old_stdout

def _display_usage(self, nouns, noun_map, out=sys.stdout):
def _display_usage(self, nouns, noun_map, out=sys.stdout):
spec = ' '.join(noun_map.get('$spec') or nouns)
print(' {} {}'.format(self.prog, spec), file=out)
print(file=out)
out.flush()

subnouns = sorted(k for k in noun_map if not k.startswith('$'))
if subnouns:
print('Subcommands', file=out)
for n in subnouns:
print(' {}'.format(n), file=out)
print(file=out)
out.flush()

argdoc = noun_map.get('$argdoc')
if argdoc:
print('Arguments', file=out)
Expand Down
13 changes: 7 additions & 6 deletions src/azure/cli/_debug.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import os
from ._logging import logger

DISABLE_VERIFY_VARIABLE_NAME = "AZURE_CLI_DISABLE_CONNECTION_VERIFICATION"

def allow_debug_connection(client):
if should_disable_connection_verify():
def allow_debug_connection(client):
if should_disable_connection_verify():
logger.warning("Connection verification disabled by environment variable %s",
DISABLE_VERIFY_VARIABLE_NAME)
client.config.connection.verify = False

def should_disable_connection_verify():
return bool(os.environ.get(DISABLE_VERIFY_VARIABLE_NAME))

def should_disable_connection_verify():
return bool(os.environ.get(DISABLE_VERIFY_VARIABLE_NAME))

10 changes: 5 additions & 5 deletions src/azure/cli/_locale.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os.path
import os.path
from codecs import open as codecs_open

_translations = dict()
_locale_dir = ''

def L(key):
return _translations.get(key) or '<NO_TRANSLATION:{}>'.format(key)
return _translations.get(key) or '<NO_TRANSLATION:{}>'.format(key)

def install(locale_dir):
mapping = []

with codecs_open(os.path.join(locale_dir, "messages.txt"), 'r', encoding='utf-8-sig') as f:
for i in f:
if not i or i.startswith('#') or not i.strip():
Expand All @@ -18,7 +18,7 @@ def install(locale_dir):
mapping.append((i[5:].strip(), None))
else:
mapping[-1] = (mapping[-1][0], i.strip())

globals()['_translations'] = dict(mapping)
globals()['_locale_dir'] = locale_dir

Expand All @@ -27,5 +27,5 @@ def get_file(name):
src = _locale_dir
except (NameError, AttributeError):
raise RuntimeError("localizations not installed")

return os.path.join(src, name)
4 changes: 2 additions & 2 deletions src/azure/cli/_logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging as _logging
import logging as _logging
import sys

__all__ = ['logger', 'configure_logging']
Expand All @@ -13,7 +13,7 @@ def _arg_name(arg):

def configure_logging(argv, config):
level = _logging.WARNING

# Load logging info from config
if config.get('verbose'):
level = _logging.INFO
Expand Down
10 changes: 5 additions & 5 deletions src/azure/cli/_output.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function, unicode_literals
from __future__ import print_function, unicode_literals

import sys
import json
Expand Down Expand Up @@ -40,8 +40,8 @@ def format_text(obj):
except TypeError:
return ''

class OutputProducer(object): #pylint: disable=too-few-public-methods
class OutputProducer(object): #pylint: disable=too-few-public-methods

def __init__(self, formatter=format_json, file=sys.stdout): #pylint: disable=redefined-builtin
self.formatter = formatter
self.file = file
Expand All @@ -58,7 +58,7 @@ def __init__(self):
def dump(self):
if len(self._rows) == 1:
return

with StringIO() as io:
cols = [(c, self._columns[c]) for c in self._column_order]
io.write(' | '.join(c.center(w) for c, w in cols))
Expand Down Expand Up @@ -91,7 +91,7 @@ class TextOutput(object):

def __init__(self):
self.identifiers = {}

def add(self, identifier, value):
if identifier in self.identifiers:
self.identifiers[identifier].append(value)
Expand Down
12 changes: 6 additions & 6 deletions src/azure/cli/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ def get_login_credentials(self):
raise ValueError('Please run "account set" to select active account.')

return BasicTokenAuthentication(
{'access_token': active[0]['access_token']}), active[0]['id']
{'access_token': active[0]['access_token']}), active[0]['id']

def set_active_subscription(self, subscription_id_or_name):
subscriptions = self.load_subscriptions()

subscription_id_or_name = subscription_id_or_name.lower()
result = [x for x in subscriptions
if subscription_id_or_name == x['id'].lower() or
result = [x for x in subscriptions
if subscription_id_or_name == x['id'].lower() or
subscription_id_or_name == x['name'].lower()]

if len(result) != 1:
raise ValueError('The subscription of "{}" does not exist or has more than'
' one match.'.format(subscription_id_or_name))

for s in subscriptions:
s['active'] = False
result[0]['active'] = True
Expand All @@ -90,7 +90,7 @@ def logout(self, user):
subscriptions[0]['active'] = True

self._save_subscriptions(subscriptions)

def load_subscriptions(self):
return self._storage.get('subscriptions') or []

Expand Down
4 changes: 2 additions & 2 deletions src/azure/cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .._argparse import IncorrectUsageError
from .._argparse import IncorrectUsageError
from .._logging import logger

# TODO: Alternatively, simply scan the directory for all modules
Expand Down Expand Up @@ -41,7 +41,7 @@ def add_to_parser(parser, command_name=None):
When `command` is specified, only commands from that module will be loaded.
If the module is not found, all commands are loaded.
'''

# Importing the modules is sufficient to invoke the decorators. Then we can
# get all of the commands from the _COMMANDS variable.
loaded = False
Expand Down
4 changes: 2 additions & 2 deletions src/azure/cli/commands/_command_creation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .._profile import Profile
from .._profile import Profile
import azure.cli._debug as _debug
import azure.cli as cli

def get_service_client(client_type, config_type):
profile = Profile()
client = client_type(config_type(*profile.get_login_credentials()))
_debug.allow_debug_connection(client)
_debug.allow_debug_connection(client)
client.config.add_user_agent("AZURECLI_{}".format(cli.__version__))
return client
8 changes: 4 additions & 4 deletions src/azure/cli/commands/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def login(args, unexpected): #pylint: disable=unused-argument
import getpass
password = getpass.getpass(L('Password: '))

credentials = UserPassCredentials(username,
password,
client_id=CLIENT_ID,
credentials = UserPassCredentials(username,
password,
client_id=CLIENT_ID,
verify=not should_disable_connection_verify())
client = SubscriptionClient(SubscriptionClientConfiguration(credentials))
subscriptions = client.subscriptions.list()
Expand All @@ -34,7 +34,7 @@ def login(args, unexpected): #pylint: disable=unused-argument

serializable = Serializer().serialize_data(subscriptions, "[Subscription]")

#keep useful properties and not json serializable
#keep useful properties and not json serializable
profile = Profile()
consolidated = Profile.normalize_properties(username, subscriptions)
profile.set_subscriptions(consolidated, credentials.token['access_token'])
Expand Down
6 changes: 3 additions & 3 deletions src/azure/cli/commands/storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from msrest import Serializer
from msrest import Serializer
from ..commands import command, description, option
from ._command_creation import get_service_client
from .._logging import logger
Expand All @@ -8,7 +8,7 @@
@description(L('List storage accounts'))
@option('--resource-group -g <resourceGroup>', L('the resource group name'))
@option('--subscription -s <id>', L('the subscription id'))
def list_accounts(args, unexpected): #pylint: disable=unused-argument
def list_accounts(args, unexpected): #pylint: disable=unused-argument
from azure.mgmt.storage import StorageManagementClient, StorageManagementClientConfiguration
from azure.mgmt.storage.models import StorageAccount
from msrestazure.azure_active_directory import UserPassCredentials
Expand All @@ -26,7 +26,7 @@ def list_accounts(args, unexpected): #pylint: disable=unused-argument

@command('storage account check')
@option('--account-name <name>')
def checkname(args, unexpected): #pylint: disable=unused-argument
def checkname(args, unexpected): #pylint: disable=unused-argument
from azure.mgmt.storage import StorageManagementClient, StorageManagementClientConfiguration
smc = get_service_client(StorageManagementClient, StorageManagementClientConfiguration)
logger.warning(smc.storage_accounts.check_name_availability(args.account_name))
8 changes: 4 additions & 4 deletions src/azure/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os

from ._argparse import ArgumentParser
from ._logging import configure_logging, logger
Expand All @@ -18,8 +18,8 @@ def main(args):
configure_logging(args, CONFIG)

from ._locale import install as locale_install
locale_install(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'locale',
locale_install(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'locale',
CONFIG.get('locale', 'en-US')))


Expand All @@ -36,7 +36,7 @@ def main(args):
else:
# No noun found, so load all commands.
commands.add_to_parser(parser)

try:
result = parser.execute(args)
# Commands can return a dictionary/list of results
Expand Down