PyLint fixes for tools-webrtc and webrtc/tools
Fix a lot of errors before bringing in the new config in https://codereview.webrtc.org/2737963003/ BUG=webrtc:7303 NOTRY=True Review-Url: https://codereview.webrtc.org/2736233003 Cr-Commit-Position: refs/heads/master@{#17137}
This commit is contained in:
@ -49,7 +49,7 @@ class FakeCmd(object):
|
||||
def __init__(self):
|
||||
self.expectations = []
|
||||
|
||||
def add_expectation(self, *args, **kwargs):
|
||||
def AddExpectation(self, *args, **kwargs):
|
||||
returns = kwargs.pop('_returns', None)
|
||||
self.expectations.append((args, kwargs, returns))
|
||||
|
||||
@ -74,13 +74,13 @@ class TestRollChromiumRevision(unittest.TestCase):
|
||||
self._new_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.new')
|
||||
|
||||
self.fake = FakeCmd()
|
||||
self.old_RunCommand = getattr(roll_deps, '_RunCommand')
|
||||
self.old_run_command = getattr(roll_deps, '_RunCommand')
|
||||
setattr(roll_deps, '_RunCommand', self.fake)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self._output_dir, ignore_errors=True)
|
||||
self.assertEqual(self.fake.expectations, [])
|
||||
setattr(roll_deps, '_RunCommand', self.old_RunCommand)
|
||||
setattr(roll_deps, '_RunCommand', self.old_run_command)
|
||||
|
||||
def testUpdateDepsFile(self):
|
||||
new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111'
|
||||
@ -98,10 +98,10 @@ class TestRollChromiumRevision(unittest.TestCase):
|
||||
local_scope = ParseDepsDict(deps_contents)
|
||||
vars_dict = local_scope['vars']
|
||||
|
||||
def assertVar(variable_name):
|
||||
def AssertVar(variable_name):
|
||||
self.assertEquals(vars_dict[variable_name], TEST_DATA_VARS[variable_name])
|
||||
assertVar('chromium_git')
|
||||
assertVar('chromium_revision')
|
||||
AssertVar('chromium_git')
|
||||
AssertVar('chromium_revision')
|
||||
self.assertEquals(len(local_scope['deps']), 3)
|
||||
self.assertEquals(len(local_scope['deps_os']), 1)
|
||||
|
||||
@ -137,7 +137,7 @@ class TestRollChromiumRevision(unittest.TestCase):
|
||||
|
||||
def _SetupGitLsRemoteCall(cmd_fake, url, revision):
|
||||
cmd = ['git', 'ls-remote', url, revision]
|
||||
cmd_fake.add_expectation(cmd, _returns=(revision, None))
|
||||
cmd_fake.AddExpectation(cmd, _returns=(revision, None))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -39,7 +39,7 @@ class Logger(object):
|
||||
self.log_level = DISPLAY_LEVEL
|
||||
self.messages_left = messages_left
|
||||
|
||||
def log(self, build_file_path, line_number, target_name, source_file,
|
||||
def Log(self, build_file_path, line_number, target_name, source_file,
|
||||
subpackage):
|
||||
if self.messages_left is not None:
|
||||
if not self.messages_left:
|
||||
@ -91,7 +91,7 @@ def _CheckBuildFile(build_file_path, packages, logger):
|
||||
line_number = subpackages_match.group('line_number')
|
||||
if subpackage:
|
||||
found_violations = True
|
||||
logger.log(build_file_path, line_number, target_name, source_file,
|
||||
logger.Log(build_file_path, line_number, target_name, source_file,
|
||||
subpackage)
|
||||
|
||||
return found_violations
|
||||
|
||||
@ -30,7 +30,7 @@ class Logger(object):
|
||||
self.messages = []
|
||||
self.test_dir = test_dir
|
||||
|
||||
def log(self, build_file_path, line_number, target_name, source_file,
|
||||
def Log(self, build_file_path, line_number, target_name, source_file,
|
||||
subpackage):
|
||||
build_file_path = os.path.relpath(build_file_path, self.test_dir)
|
||||
build_file_path = build_file_path.replace(os.path.sep, '/')
|
||||
@ -48,19 +48,19 @@ class UnitTest(unittest.TestCase):
|
||||
expected_messages = ReadPylFile(os.path.join(test_dir, 'expected.pyl'))
|
||||
self.assertListEqual(sorted(expected_messages), sorted(logger.messages))
|
||||
|
||||
def test_no_errors(self):
|
||||
def testNoErrors(self):
|
||||
self.RunTest(os.path.join(TESTDATA_DIR, 'no_errors'))
|
||||
|
||||
def test_multiple_errors_single_target(self):
|
||||
def testMultipleErrorsSingleTarget(self):
|
||||
self.RunTest(os.path.join(TESTDATA_DIR, 'multiple_errors_single_target'))
|
||||
|
||||
def test_multiple_errors_multiple_targets(self):
|
||||
def testMultipleErrorsMultipleTargets(self):
|
||||
self.RunTest(os.path.join(TESTDATA_DIR, 'multiple_errors_multiple_targets'))
|
||||
|
||||
def test_common_prefix(self):
|
||||
def testCommonPrefix(self):
|
||||
self.RunTest(os.path.join(TESTDATA_DIR, 'common_prefix'))
|
||||
|
||||
def test_all_build_files(self):
|
||||
def testAllBuildFiles(self):
|
||||
self.RunTest(os.path.join(TESTDATA_DIR, 'all_build_files'), True)
|
||||
|
||||
|
||||
|
||||
@ -15,19 +15,16 @@ This file emits the list of reasons why a particular build needs to be clobbered
|
||||
import os
|
||||
import sys
|
||||
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir))
|
||||
sys.path.insert(0, os.path.join(checkout_root, 'build'))
|
||||
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
|
||||
sys.path.insert(0, os.path.join(CHECKOUT_ROOT, 'build'))
|
||||
import landmine_utils
|
||||
|
||||
|
||||
distributor = landmine_utils.distributor
|
||||
gyp_defines = landmine_utils.gyp_defines
|
||||
gyp_msvs_version = landmine_utils.gyp_msvs_version
|
||||
platform = landmine_utils.platform
|
||||
platform = landmine_utils.platform # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def print_landmines():
|
||||
def print_landmines(): # pylint: disable=invalid-name
|
||||
"""
|
||||
ALL LANDMINES ARE EMITTED FROM HERE.
|
||||
"""
|
||||
@ -54,7 +51,7 @@ def print_landmines():
|
||||
# is no longer the case.
|
||||
print 'Clobber due to iOS compile errors (crbug.com/694721)'
|
||||
print 'Clobber to unblock https://codereview.webrtc.org/2709573003'
|
||||
print 'Clobber to fix https://codereview.webrtc.org/2709573003 after landing'
|
||||
print 'Clobber to fix after https://codereview.webrtc.org/2709573003'
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -43,7 +43,7 @@ class TemporaryDirectory(object):
|
||||
def __enter__(self):
|
||||
return self._name
|
||||
|
||||
def __exit__(self, exc, value, tb):
|
||||
def __exit__(self, exc, value, _tb):
|
||||
if self._name and not self._closed:
|
||||
shutil.rmtree(self._name)
|
||||
self._closed = True
|
||||
|
||||
@ -55,14 +55,14 @@ class NonStrippingEpilogOptionParser(optparse.OptionParser):
|
||||
return self.epilog
|
||||
|
||||
|
||||
def _get_external_ip():
|
||||
def _GetExternalIp():
|
||||
"""Finds out the machine's external IP by connecting to google.com."""
|
||||
external_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
external_socket.connect(('google.com', 80))
|
||||
return external_socket.getsockname()[0]
|
||||
|
||||
|
||||
def _parse_args():
|
||||
def _ParseArgs():
|
||||
"""Define and parse the command-line arguments."""
|
||||
presets_string = '\n'.join(str(p) for p in _PRESETS)
|
||||
parser = NonStrippingEpilogOptionParser(epilog=(
|
||||
@ -123,11 +123,11 @@ def _parse_args():
|
||||
except ValueError:
|
||||
parser.error('Invalid port range specified.')
|
||||
|
||||
_set_logger(options.verbose)
|
||||
_InitLogging(options.verbose)
|
||||
return options
|
||||
|
||||
|
||||
def _set_logger(verbose):
|
||||
def _InitLogging(verbose):
|
||||
"""Setup logging."""
|
||||
log_level = _DEFAULT_LOG_LEVEL
|
||||
if verbose:
|
||||
@ -135,8 +135,8 @@ def _set_logger(verbose):
|
||||
logging.basicConfig(level=log_level, format='%(message)s')
|
||||
|
||||
|
||||
def _main():
|
||||
options = _parse_args()
|
||||
def main():
|
||||
options = _ParseArgs()
|
||||
|
||||
# Build a configuration object. Override any preset configuration settings if
|
||||
# a value of a setting was also given as a flag.
|
||||
@ -154,19 +154,19 @@ def _main():
|
||||
emulator = network_emulator.NetworkEmulator(connection_config,
|
||||
options.port_range)
|
||||
try:
|
||||
emulator.check_permissions()
|
||||
emulator.CheckPermissions()
|
||||
except network_emulator.NetworkEmulatorError as e:
|
||||
logging.error('Error: %s\n\nCause: %s', e.fail_msg, e.error)
|
||||
return -1
|
||||
|
||||
if not options.target_ip:
|
||||
external_ip = _get_external_ip()
|
||||
external_ip = _GetExternalIp()
|
||||
else:
|
||||
external_ip = options.target_ip
|
||||
|
||||
logging.info('Constraining traffic to/from IP: %s', external_ip)
|
||||
try:
|
||||
emulator.emulate(external_ip)
|
||||
emulator.Emulate(external_ip)
|
||||
logging.info('Started network emulation with the following configuration:\n'
|
||||
' Receive bandwidth: %s kbps (%s kB/s)\n'
|
||||
' Send bandwidth : %s kbps (%s kB/s)\n'
|
||||
@ -184,7 +184,7 @@ def _main():
|
||||
options.port_range[0], options.port_range[1])
|
||||
raw_input('Press Enter to abort Network Emulation...')
|
||||
logging.info('Flushing all Dummynet rules...')
|
||||
network_emulator.cleanup()
|
||||
network_emulator.Cleanup()
|
||||
logging.info('Completed Network Emulation.')
|
||||
return 0
|
||||
except network_emulator.NetworkEmulatorError as e:
|
||||
@ -192,4 +192,4 @@ def _main():
|
||||
return -2
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(_main())
|
||||
sys.exit(main())
|
||||
|
||||
@ -53,20 +53,20 @@ class NetworkEmulator(object):
|
||||
self._port_range = port_range
|
||||
self._connection_config = connection_config
|
||||
|
||||
def emulate(self, target_ip):
|
||||
def Emulate(self, target_ip):
|
||||
"""Starts a network emulation by setting up Dummynet rules.
|
||||
|
||||
Args:
|
||||
target_ip: The IP address of the interface that shall be that have the
|
||||
network constraints applied to it.
|
||||
"""
|
||||
receive_pipe_id = self._create_dummynet_pipe(
|
||||
receive_pipe_id = self._CreateDummynetPipe(
|
||||
self._connection_config.receive_bw_kbps,
|
||||
self._connection_config.delay_ms,
|
||||
self._connection_config.packet_loss_percent,
|
||||
self._connection_config.queue_slots)
|
||||
logging.debug('Created receive pipe: %s', receive_pipe_id)
|
||||
send_pipe_id = self._create_dummynet_pipe(
|
||||
send_pipe_id = self._CreateDummynetPipe(
|
||||
self._connection_config.send_bw_kbps,
|
||||
self._connection_config.delay_ms,
|
||||
self._connection_config.packet_loss_percent,
|
||||
@ -74,15 +74,15 @@ class NetworkEmulator(object):
|
||||
logging.debug('Created send pipe: %s', send_pipe_id)
|
||||
|
||||
# Adding the rules will start the emulation.
|
||||
incoming_rule_id = self._create_dummynet_rule(receive_pipe_id, 'any',
|
||||
target_ip, self._port_range)
|
||||
incoming_rule_id = self._CreateDummynetRule(receive_pipe_id, 'any',
|
||||
target_ip, self._port_range)
|
||||
logging.debug('Created incoming rule: %s', incoming_rule_id)
|
||||
outgoing_rule_id = self._create_dummynet_rule(send_pipe_id, target_ip,
|
||||
'any', self._port_range)
|
||||
outgoing_rule_id = self._CreateDummynetRule(send_pipe_id, target_ip,
|
||||
'any', self._port_range)
|
||||
logging.debug('Created outgoing rule: %s', outgoing_rule_id)
|
||||
|
||||
@staticmethod
|
||||
def check_permissions():
|
||||
def CheckPermissions():
|
||||
"""Checks if permissions are available to run Dummynet commands.
|
||||
|
||||
Raises:
|
||||
@ -99,8 +99,8 @@ class NetworkEmulator(object):
|
||||
raise NetworkEmulatorError('You must run this script with administrator'
|
||||
' privileges.')
|
||||
|
||||
def _create_dummynet_rule(self, pipe_id, from_address, to_address,
|
||||
port_range):
|
||||
def _CreateDummynetRule(self, pipe_id, from_address, to_address,
|
||||
port_range):
|
||||
"""Creates a network emulation rule and returns its ID.
|
||||
|
||||
Args:
|
||||
@ -118,14 +118,14 @@ class NetworkEmulator(object):
|
||||
self._rule_counter += 100
|
||||
add_part = ['add', self._rule_counter, 'pipe', pipe_id,
|
||||
'ip', 'from', from_address, 'to', to_address]
|
||||
_run_ipfw_command(add_part + ['src-port', '%s-%s' % port_range],
|
||||
_RunIpfwCommand(add_part + ['src-port', '%s-%s' % port_range],
|
||||
'Failed to add Dummynet src-port rule.')
|
||||
_run_ipfw_command(add_part + ['dst-port', '%s-%s' % port_range],
|
||||
_RunIpfwCommand(add_part + ['dst-port', '%s-%s' % port_range],
|
||||
'Failed to add Dummynet dst-port rule.')
|
||||
return self._rule_counter
|
||||
|
||||
def _create_dummynet_pipe(self, bandwidth_kbps, delay_ms, packet_loss_percent,
|
||||
queue_slots):
|
||||
def _CreateDummynetPipe(self, bandwidth_kbps, delay_ms, packet_loss_percent,
|
||||
queue_slots):
|
||||
"""Creates a Dummynet pipe and return its ID.
|
||||
|
||||
Args:
|
||||
@ -146,21 +146,21 @@ class NetworkEmulator(object):
|
||||
if sys.platform.startswith('linux'):
|
||||
error_message += ('Make sure you have loaded the ipfw_mod.ko module to '
|
||||
'your kernel (sudo insmod /path/to/ipfw_mod.ko).')
|
||||
_run_ipfw_command(cmd, error_message)
|
||||
_RunIpfwCommand(cmd, error_message)
|
||||
return self._pipe_counter
|
||||
|
||||
def cleanup():
|
||||
def Cleanup():
|
||||
"""Stops the network emulation by flushing all Dummynet rules.
|
||||
|
||||
Notice that this will flush any rules that may have been created previously
|
||||
before starting the emulation.
|
||||
"""
|
||||
_run_ipfw_command(['-f', 'flush'],
|
||||
_RunIpfwCommand(['-f', 'flush'],
|
||||
'Failed to flush Dummynet rules!')
|
||||
_run_ipfw_command(['-f', 'pipe', 'flush'],
|
||||
_RunIpfwCommand(['-f', 'pipe', 'flush'],
|
||||
'Failed to flush Dummynet pipes!')
|
||||
|
||||
def _run_ipfw_command(command, fail_msg=None):
|
||||
def _RunIpfwCommand(command, fail_msg=None):
|
||||
"""Executes a command and prefixes the appropriate command for
|
||||
Windows or Linux/UNIX.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user