Skip to content

Commit

Permalink
Pylint fixes for webapp extension (#175)
Browse files Browse the repository at this point in the history
* Plylint fixes for Webapp

* Pylint fixes

* More Pylint fixes

* addressing PR feedback
  • Loading branch information
panchagnula authored and williexu committed May 11, 2018
1 parent 66f3755 commit fe91b65
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/webapp/azext_webapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
1 change: 1 addition & 0 deletions src/webapp/azext_webapp/create_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions src/webapp/azext_webapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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
17 changes: 10 additions & 7 deletions src/webapp/azext_webapp/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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...')
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()

0 comments on commit fe91b65

Please sign in to comment.