diff --git a/pylintrc b/pylintrc index f9e4a383c98..f304190876a 100644 --- a/pylintrc +++ b/pylintrc @@ -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 diff --git a/src/azure/cli/_argparse.py b/src/azure/cli/_argparse.py index 623bfbadc8c..70abf3e3b56 100644 --- a/src/azure/cli/_argparse.py +++ b/src/azure/cli/_argparse.py @@ -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 @@ -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. @@ -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. @@ -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: @@ -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) @@ -219,12 +219,12 @@ 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) @@ -232,7 +232,7 @@ def _display_usage(self, nouns, noun_map, out=sys.stdout): print(' {}'.format(n), file=out) print(file=out) out.flush() - + argdoc = noun_map.get('$argdoc') if argdoc: print('Arguments', file=out) diff --git a/src/azure/cli/_debug.py b/src/azure/cli/_debug.py index c5d8a1db767..806fcb252f8 100644 --- a/src/azure/cli/_debug.py +++ b/src/azure/cli/_debug.py @@ -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)) + diff --git a/src/azure/cli/_locale.py b/src/azure/cli/_locale.py index b56abe94a66..7ded222077d 100644 --- a/src/azure/cli/_locale.py +++ b/src/azure/cli/_locale.py @@ -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 ''.format(key) + return _translations.get(key) or ''.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(): @@ -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 @@ -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) diff --git a/src/azure/cli/_logging.py b/src/azure/cli/_logging.py index 0102e0aabe3..c0dc5879714 100644 --- a/src/azure/cli/_logging.py +++ b/src/azure/cli/_logging.py @@ -1,4 +1,4 @@ -import logging as _logging +import logging as _logging import sys __all__ = ['logger', 'configure_logging'] @@ -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 diff --git a/src/azure/cli/_output.py b/src/azure/cli/_output.py index 529e25ea99f..f5dc596f7e0 100644 --- a/src/azure/cli/_output.py +++ b/src/azure/cli/_output.py @@ -1,4 +1,4 @@ -from __future__ import print_function, unicode_literals +from __future__ import print_function, unicode_literals import sys import json @@ -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 @@ -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)) @@ -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) diff --git a/src/azure/cli/_profile.py b/src/azure/cli/_profile.py index 87834bbefb5..af5b5866778 100644 --- a/src/azure/cli/_profile.py +++ b/src/azure/cli/_profile.py @@ -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 @@ -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 [] diff --git a/src/azure/cli/commands/__init__.py b/src/azure/cli/commands/__init__.py index b39c45a5492..d27ce5d1570 100644 --- a/src/azure/cli/commands/__init__.py +++ b/src/azure/cli/commands/__init__.py @@ -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 @@ -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 diff --git a/src/azure/cli/commands/_command_creation.py b/src/azure/cli/commands/_command_creation.py index daacf0aeb2c..5c46fa04cba 100644 --- a/src/azure/cli/commands/_command_creation.py +++ b/src/azure/cli/commands/_command_creation.py @@ -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 diff --git a/src/azure/cli/commands/login.py b/src/azure/cli/commands/login.py index 31125f3492f..fc165e37368 100644 --- a/src/azure/cli/commands/login.py +++ b/src/azure/cli/commands/login.py @@ -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() @@ -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']) diff --git a/src/azure/cli/commands/storage.py b/src/azure/cli/commands/storage.py index b765431c9e4..6a7ca95147a 100644 --- a/src/azure/cli/commands/storage.py +++ b/src/azure/cli/commands/storage.py @@ -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 @@ -8,7 +8,7 @@ @description(L('List storage accounts')) @option('--resource-group -g ', L('the resource group name')) @option('--subscription -s ', 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 @@ -26,7 +26,7 @@ def list_accounts(args, unexpected): #pylint: disable=unused-argument @command('storage account check') @option('--account-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)) diff --git a/src/azure/cli/main.py b/src/azure/cli/main.py index a685484ccfa..7c822cca712 100644 --- a/src/azure/cli/main.py +++ b/src/azure/cli/main.py @@ -1,4 +1,4 @@ -import os +import os from ._argparse import ArgumentParser from ._logging import configure_logging, logger @@ -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'))) @@ -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