devserver: Fix lint issues.
Fix many (not all) lint issues in this directory.
BUG=None
TEST=run_unittests
Change-Id: Ifc934808c02aef45243e6a6ed099124cca4674d2
Reviewed-on: https://chromium-review.googlesource.com/354735
Commit-Ready: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Ningning Xia <nxia@chromium.org>
diff --git a/autoupdate.py b/autoupdate.py
index 5156268..98ac059 100644
--- a/autoupdate.py
+++ b/autoupdate.py
@@ -4,12 +4,13 @@
"""Devserver module for handling update client requests."""
+from __future__ import print_function
+
import base64
import collections
import fcntl
import json
import os
-import struct
import subprocess
import sys
import threading
@@ -39,9 +40,9 @@
# Files needed to serve an update.
UPDATE_FILES = (
- constants.UPDATE_FILE,
- constants.STATEFUL_FILE,
- constants.METADATA_FILE
+ constants.UPDATE_FILE,
+ constants.STATEFUL_FILE,
+ constants.METADATA_FILE
)
# Module-local log function.
@@ -64,7 +65,7 @@
else:
host_port[1] = new_port
- print host_port
+ print(host_port)
netloc = '%s:%s' % tuple(host_port)
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
@@ -174,7 +175,7 @@
proxy_port=None, src_image='', board=None,
copy_to_static_root=True, private_key=None,
private_key_for_metadata_hash_signature=None, public_key=None,
- critical_update=False, remote_payload=False, max_updates= -1,
+ critical_update=False, remote_payload=False, max_updates=-1,
host_log=False, *args, **kwargs):
super(Autoupdate, self).__init__(*args, **kwargs)
self.xbuddy = xbuddy
@@ -259,8 +260,7 @@
@staticmethod
def _CanUpdate(client_version, latest_version):
- """Returns true if the latest_version is greater than the client_version.
- """
+ """True if the latest_version is greater than the client_version."""
_Log('client version %s latest version %s', client_version, latest_version)
client_tokens = client_version.replace('_', '').split('.')
@@ -504,8 +504,8 @@
_Log('Pre-generating the update payload')
# Does not work with labels so just use static dir. (empty label)
pregenerated_update = self.GetPathToPayload('', FORCED_UPDATE, self.board)
- print 'PREGENERATED_UPDATE=%s' % _NonePathJoin(pregenerated_update,
- constants.UPDATE_FILE)
+ print('PREGENERATED_UPDATE=%s' % _NonePathJoin(pregenerated_update,
+ constants.UPDATE_FILE))
return pregenerated_update
def _GetRemotePayloadAttrs(self, url):
@@ -638,7 +638,7 @@
client_version = app.getAttribute('version')
channel = app.getAttribute('track')
board = (app.hasAttribute('board') and app.getAttribute('board')
- or self.GetDefaultBoardID())
+ or self.GetDefaultBoardID())
# Add attributes to log message
log_message['version'] = client_version
log_message['track'] = channel
diff --git a/autoupdate_lib.py b/autoupdate_lib.py
index 2e7a08b..76dd081 100644
--- a/autoupdate_lib.py
+++ b/autoupdate_lib.py
@@ -4,6 +4,8 @@
"""Module containing common autoupdate utilities and protocol dictionaries."""
+from __future__ import print_function
+
import datetime
import os
import time
diff --git a/autoupdate_unittest.py b/autoupdate_unittest.py
index eacd8c4..bbb4b34 100755
--- a/autoupdate_unittest.py
+++ b/autoupdate_unittest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -6,6 +6,8 @@
"""Unit tests for autoupdate.py."""
+from __future__ import print_function
+
import json
import os
import shutil
@@ -158,7 +160,7 @@
# Mock out GenerateUpdateImageWithCache to make an update file in cache
def mock_fn(_image):
- print 'mock_fn'
+ print('mock_fn')
# No good way to introduce an update file during execution.
cache_dir = os.path.join(self.static_image_dir, 'cache')
common_util.MkDirP(cache_dir)
@@ -203,7 +205,8 @@
au_mock = self._DummyAutoupdateConstructor()
au_mock.forced_image = "xbuddy:b/v/a"
- self._xbuddy._GetArtifact(['b', 'v', 'a'],
+ self._xbuddy._GetArtifact(
+ ['b', 'v', 'a'],
image_dir=None).AndReturn(('label', constants.TEST_IMAGE_FILE))
au_mock.GetUpdateForLabel(
@@ -290,7 +293,8 @@
attrs['forced_update_label'],
test_label)
self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
- self.assertFalse('forced_update_label' in
+ self.assertFalse(
+ 'forced_update_label' in
au_mock.host_infos.GetHostInfo('127.0.0.1').attrs)
def testGetVersionFromDir(self):
diff --git a/build_artifact.py b/build_artifact.py
index 78f1baa..81c2523 100755
--- a/build_artifact.py
+++ b/build_artifact.py
@@ -20,6 +20,8 @@
import devserver_constants
import log_util
+# We do a number of things with args/kwargs arguments that confuse pylint.
+# pylint: disable=docstring-misnamed-args
_AU_BASE = 'au'
_NTON_DIR_SUFFIX = '_nton'
@@ -519,8 +521,8 @@
Returns:
A data wrapper that describes an artifact's implementation.
-
"""
+ # pylint: disable=super-on-old-class
class NewArtifact(base):
"""A data wrapper that describes an artifact's implementation."""
ARTIFACT_TAG = tag
@@ -544,7 +546,9 @@
def _AddCrOSArtifact(tag, base, name, *fixed_args, **fixed_kwargs):
- """Add a data wrapper that describes a ChromeOS artifact's implementation to
+ """Add a data wrapper for ChromeOS artifacts.
+
+ Add a data wrapper that describes a ChromeOS artifact's implementation to
chromeos_artifact_map.
"""
artifact = _CreateNewArtifact(tag, base, name, *fixed_args, **fixed_kwargs)
@@ -623,7 +627,9 @@
def _AddAndroidArtifact(tag, base, name, *fixed_args, **fixed_kwargs):
- """Add a data wrapper that describes an Android artifact's implementation to
+ """Add a data wrapper for android artifacts.
+
+ Add a data wrapper that describes an Android artifact's implementation to
android_artifact_map.
"""
artifact = _CreateNewArtifact(tag, base, name, *fixed_args, **fixed_kwargs)
diff --git a/build_artifact_unittest.py b/build_artifact_unittest.py
index fa32e79..758d971 100755
--- a/build_artifact_unittest.py
+++ b/build_artifact_unittest.py
@@ -264,9 +264,7 @@
self._CheckMarker(artifact.marker_name, artifact.installed_files)
def testArtifactFactory(self):
- """Tests that BuildArtifact logic works for both named and file artifacts.
-
- """
+ """Tests that BuildArtifact works for both named and file artifacts."""
name_artifact = 'test_suites' # This file is in every real GS dir.
file_artifact = 'metadata.json' # This file is in every real GS dir.
factory = build_artifact.ChromeOSArtifactFactory(
diff --git a/build_util.py b/build_util.py
index 29c408b..0e8f680 100644
--- a/build_util.py
+++ b/build_util.py
@@ -2,13 +2,16 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+"""Defines a build related helper class."""
+
+from __future__ import print_function
+
import os
import sys
class BuildObject(object):
- """
- Common base class that defines key paths in the source tree.
+ """Common base class that defines key paths in the source tree.
Classes that inherit from BuildObject can access scripts in the src/scripts
directory, and have a handle to the static directory of the devserver.
diff --git a/builder_test.py b/builder_test.py
index 8fbd160..e8e8d44 100755
--- a/builder_test.py
+++ b/builder_test.py
@@ -1,15 +1,22 @@
-#!/usr/bin/python
+#!/usr/bin/python2
+
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+"""Unittests for builder.py."""
+
+from __future__ import print_function
+
import subprocess
import unittest
import builder
+# pylint: disable=protected-access
class BuilderTest(unittest.TestCase):
+ """Tests for builder."""
def testOutputOf(self):
self.assertRaises(subprocess.CalledProcessError,
builder._OutputOf, ['/bin/false'])