From fe91b65a24f553e5d395103059f22c011f1a2160 Mon Sep 17 00:00:00 2001 From: Sisira Panchagnula Date: Thu, 10 May 2018 17:12:56 -0700 Subject: [PATCH] Pylint fixes for webapp extension (#175) * Plylint fixes for Webapp * Pylint fixes * More Pylint fixes * addressing PR feedback --- src/webapp/azext_webapp/__init__.py | 3 ++- src/webapp/azext_webapp/create_util.py | 1 + src/webapp/azext_webapp/custom.py | 26 ++++++++++---------------- src/webapp/azext_webapp/tunnel.py | 17 ++++++++++------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/webapp/azext_webapp/__init__.py b/src/webapp/azext_webapp/__init__.py index 10bcd23f630..f0d511c4baa 100644 --- a/src/webapp/azext_webapp/__init__.py +++ b/src/webapp/azext_webapp/__init__.py @@ -35,7 +35,8 @@ def load_arguments(self, _): help="shows summary of the create and deploy operation instead of executing it", default=False, action='store_true') with self.argument_context('webapp remote-connection create') as c: - c.argument('port', options_list=['--port', '-p'], help='Port for the remote connection. Default: Random available port', type=int) + c.argument('port', options_list=['--port', '-p'], + help='Port for the remote connection. Default: Random available port', type=int) c.argument('name', options_list=['--name', '-n'], help='Name of the webapp to connect to') with self.argument_context('webapp config snapshot list') as c: c.argument('resource_group', options_list=['--resource-group', '-g'], help='Name of resource group.') diff --git a/src/webapp/azext_webapp/create_util.py b/src/webapp/azext_webapp/create_util.py index ae18d055f9f..b86676a7336 100644 --- a/src/webapp/azext_webapp/create_util.py +++ b/src/webapp/azext_webapp/create_util.py @@ -116,6 +116,7 @@ def check_app_exists(cmd, rg_name, app_name): return False +# pylint:disable=unexpected-keyword-arg def get_lang_from_content(src_path): import glob # NODE: package.json should exist in the application root dir diff --git a/src/webapp/azext_webapp/custom.py b/src/webapp/azext_webapp/custom.py index b53633e1fba..63fdcccbe1a 100644 --- a/src/webapp/azext_webapp/custom.py +++ b/src/webapp/azext_webapp/custom.py @@ -4,13 +4,11 @@ # -------------------------------------------------------------------------------------------- from __future__ import print_function +import json from knack.log import get_logger from knack.util import CLIError - from azure.mgmt.web.models import (AppServicePlan, SkuDescription, SnapshotRecoveryRequest, SnapshotRecoveryTarget) - from azure.cli.core.commands.client_factory import get_subscription_id - from azure.cli.command_modules.appservice.custom import ( create_webapp, update_app_settings, @@ -19,9 +17,7 @@ get_sku_name, list_publish_profiles, get_site_configs) - from azure.cli.command_modules.appservice._appservice_utils import _generic_site_operation - from .create_util import ( zip_contents_from_dir, get_runtime_version_details, @@ -33,14 +29,10 @@ get_lang_from_content, web_client_factory ) - from ._constants import (NODE_RUNTIME_NAME, OS_DEFAULT, JAVA_RUNTIME_NAME, STATIC_RUNTIME_NAME) -import json -import time - logger = get_logger(__name__) -# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements +# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements,too-many-branches def create_deploy_webapp(cmd, name, location=None, dryrun=False): @@ -245,6 +237,7 @@ def _check_for_ready_tunnel(remote_debugging, tunnel_server): def create_tunnel(cmd, resource_group_name, name, port=None, slot=None): + import time profiles = list_publish_profiles(cmd, resource_group_name, name, slot) user_name = next(p['userName'] for p in profiles) user_password = next(p['userPWD'] for p in profiles) @@ -268,6 +261,7 @@ def create_tunnel(cmd, resource_group_name, name, port=None, slot=None): def _start_tunnel(tunnel_server, remote_debugging_enabled): + import time if not _check_for_ready_tunnel(remote_debugging_enabled, tunnel_server): logger.warning('Tunnel is not ready yet, please wait (may take up to 1 minute)') while True: @@ -299,7 +293,7 @@ def _zip_deploy(cmd, rg_name, name, zip_path): # keep checking for status of the deployment deployment_url = scm_url + '/api/deployments/latest' response = requests.get(deployment_url, headers=authorization) - if(response.json()['status'] != 4): + if response.json()['status'] != 4: logger.warning(response.json()['progress']) _check_deployment_status(deployment_url, authorization) @@ -312,15 +306,15 @@ def _check_deployment_status(deployment_url, authorization): res_dict = response.json() num_trials = num_trials + 1 if res_dict['status'] == 5: - return logger.warning("Zip deployment failed status {}".format( + logger.warning("Zip deployment failed status {}".format( res_dict['status_text'] )) + break elif res_dict['status'] == 4: - return + break logger.warning(res_dict['progress']) - # if the deployment is taking longer than expected - r = requests.get(deployment_url, headers=authorization) + # if the deployment is taking longer than expected + r = requests.get(deployment_url, headers=authorization) if r.json()['status'] != 4: logger.warning("""Deployment is taking longer than expected. Please verify status at '{}' beforing launching the app""".format(deployment_url)) - return diff --git a/src/webapp/azext_webapp/tunnel.py b/src/webapp/azext_webapp/tunnel.py index b2653fbaa25..a675ca2438b 100644 --- a/src/webapp/azext_webapp/tunnel.py +++ b/src/webapp/azext_webapp/tunnel.py @@ -34,6 +34,7 @@ def recv(self): return data +# pylint: disable=no-member,too-many-instance-attributes,bare-except,no-self-use class TunnelServer(object): def __init__(self, local_addr, local_port, remote_addr, remote_user_name, remote_password): self.local_addr = local_addr @@ -43,6 +44,8 @@ def __init__(self, local_addr, local_port, remote_addr, remote_user_name, remote self.remote_addr = remote_addr self.remote_user_name = remote_user_name self.remote_password = remote_password + self.client = None + self.ws = None logger.info('Creating a socket on port: %s', self.local_port) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) logger.info('Setting socket options') @@ -63,7 +66,7 @@ def create_basic_auth(self): def is_port_open(self): is_port_open = False with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: - if sock.connect_ex(('', self.local_port)) == 0: + if sock.connect_ex('', self.local_port) == 0: logger.info('Port %s is NOT open', self.local_port) else: logger.warning('Port %s is open', self.local_port) @@ -99,7 +102,7 @@ def is_port_set_to_default(self): return True return False - def listen(self): + def _listen(self): self.sock.listen(100) index = 0 basic_auth_string = self.create_basic_auth() @@ -125,8 +128,8 @@ def listen(self): logger.info('Websocket, connected status: %s', self.ws.connected) index = index + 1 logger.info('Got debugger connection... index: %s', index) - debugger_thread = Thread(target=self.listen_to_client, args=(self.client, self.ws, index)) - web_socket_thread = Thread(target=self.listen_to_web_socket, args=(self.client, self.ws, index)) + debugger_thread = Thread(target=self._listen_to_client, args=(self.client, self.ws, index)) + web_socket_thread = Thread(target=self._listen_to_web_socket, args=(self.client, self.ws, index)) debugger_thread.start() web_socket_thread.start() logger.info('Both debugger and websocket threads started...') @@ -136,7 +139,7 @@ def listen(self): logger.info('Both debugger and websocket threads stopped...') logger.warning('Stopped local server..') - def listen_to_web_socket(self, client, ws_socket, index): + def _listen_to_web_socket(self, client, ws_socket, index): while True: try: logger.info('Waiting for websocket data, connection status: %s, index: %s', ws_socket.connected, index) @@ -159,7 +162,7 @@ def listen_to_web_socket(self, client, ws_socket, index): ws_socket.close() return False - def listen_to_client(self, client, ws_socket, index): + def _listen_to_client(self, client, ws_socket, index): while True: try: logger.info('Waiting for debugger data, index: %s', index) @@ -184,4 +187,4 @@ def listen_to_client(self, client, ws_socket, index): def start_server(self): logger.warning('Start your favorite client and connect to port %s', self.local_port) - self.listen() + self._listen()