[autotest] Style nits in lab_inventory module.
This converts the lab_inventory module and its unit tests to better
follow PEP-8 regarding blank lines and column width.
BUG=None
TEST=None
Change-Id: Ie7a5261b46d4fea4db510055615e5968e3cc3201
Reviewed-on: https://chromium-review.googlesource.com/1033338
Commit-Ready: Richard Barnette <jrbarnette@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
diff --git a/site_utils/lab_inventory.py b/site_utils/lab_inventory.py
index d43e12d..ddd33af 100755
--- a/site_utils/lab_inventory.py
+++ b/site_utils/lab_inventory.py
@@ -46,7 +46,6 @@
With no arguments, gathers the status for all models in the lab.
With one or more named models on the command line, restricts
reporting to just those models.
-
"""
@@ -170,20 +169,17 @@
self._broken_list = None
self._idle_list = None
-
def record_host(self, host_history):
"""Add one `HostJobHistory` object to the collection.
@param host_history The `HostJobHistory` object to be
remembered.
-
"""
self._working_list = None
self._broken_list = None
self._idle_list = None
self._histories.append(host_history)
-
def get_working_list(self):
"""Return a list of all working DUTs in the pool.
@@ -193,19 +189,16 @@
Cache the result so that we only cacluate it once.
@return A list of HostJobHistory objects.
-
"""
if self._working_list is None:
self._working_list = [h for h in self._histories
if h.last_diagnosis()[0] == status_history.WORKING]
return self._working_list
-
def get_working(self):
"""Return the number of working DUTs in the pool."""
return len(self.get_working_list())
-
def get_broken_list(self):
"""Return a list of all broken DUTs in the pool.
@@ -215,19 +208,16 @@
Cache the result so that we only cacluate it once.
@return A list of HostJobHistory objects.
-
"""
if self._broken_list is None:
self._broken_list = [h for h in self._histories
if h.last_diagnosis()[0] == status_history.BROKEN]
return self._broken_list
-
def get_broken(self):
"""Return the number of broken DUTs in the pool."""
return len(self.get_broken_list())
-
def get_idle_list(self):
"""Return a list of all idle DUTs in the pool.
@@ -237,7 +227,6 @@
Cache the result so that we only cacluate it once.
@return A list of HostJobHistory objects.
-
"""
idle_statuses = {status_history.UNUSED, status_history.UNKNOWN}
if self._idle_list is None:
@@ -245,12 +234,10 @@
if h.last_diagnosis()[0] in idle_statuses]
return self._idle_list
-
def get_idle(self):
"""Return the number of idle DUTs in the pool."""
return len(self.get_idle_list())
-
def get_total(self):
"""Return the total number of DUTs in the pool."""
return len(self._histories)
@@ -281,12 +268,10 @@
@param host_history The `HostJobHistory` object to be
remembered.
-
"""
pool = host_history.host_pool
self._histories_by_pool[pool].record_host(host_history)
-
def _count_pool(self, get_pool_count, pool=None):
"""Internal helper to count hosts in a given pool.
@@ -297,7 +282,6 @@
_PoolCount object.
@param pool The pool to be counted. If `None`,
return the total across all pools.
-
"""
if pool is None:
return sum([get_pool_count(cached_history) for cached_history in
@@ -305,7 +289,6 @@
else:
return get_pool_count(self._histories_by_pool[pool])
-
def get_working_list(self):
"""Return a list of all working DUTs (across all pools).
@@ -313,14 +296,12 @@
ones where the last diagnosis is `WORKING`.
@return A list of HostJobHistory objects.
-
"""
l = []
for p in self._histories_by_pool.values():
l.extend(p.get_working_list())
return l
-
def get_working(self, pool=None):
"""Return the number of working DUTs in a pool.
@@ -332,7 +313,6 @@
"""
return self._count_pool(_HostSetInventory.get_working, pool)
-
def get_broken_list(self):
"""Return a list of all broken DUTs (across all pools).
@@ -340,14 +320,12 @@
selecting the ones where the last diagnosis is `BROKEN`.
@return A list of HostJobHistory objects.
-
"""
l = []
for p in self._histories_by_pool.values():
l.extend(p.get_broken_list())
return l
-
def get_broken(self, pool=None):
"""Return the number of broken DUTs in a pool.
@@ -358,7 +336,6 @@
"""
return self._count_pool(_HostSetInventory.get_broken, pool)
-
def get_idle_list(self, pool=None):
"""Return a list of all idle DUTs in the given pool.
@@ -369,7 +346,6 @@
across all pools.
@return A list of HostJobHistory objects.
-
"""
if pool is None:
l = []
@@ -379,7 +355,6 @@
else:
return self._histories_by_pool[pool].get_idle_list()
-
def get_idle(self, pool=None):
"""Return the number of idle DUTs in a pool.
@@ -390,7 +365,6 @@
"""
return self._count_pool(_HostSetInventory.get_idle, pool)
-
def get_spares_buffer(self, spare_pool=SPARE_POOL):
"""Return the the nominal number of working spares.
@@ -404,7 +378,6 @@
"""
return self.get_total(spare_pool) - self.get_broken()
-
def get_total(self, pool=None):
"""Return the total number of DUTs in a pool.
@@ -466,7 +439,6 @@
@param modellist List of models to include. If empty,
include all available models.
@return A `_LabInventory` object for the specified models.
-
"""
target_pools = MANAGED_POOLS
label_list = [constants.Labels.POOL_PREFIX + l for l in target_pools]
@@ -489,7 +461,6 @@
start_time, end_time))
return cls([create(host) for host in afehosts], target_pools)
-
def __init__(self, histories, pools):
models = {h.host_model for h in histories}
self._modeldata = {model: _PoolSetInventory(pools) for model in models}
@@ -498,21 +469,17 @@
self[h.host_model].record_host(h)
self._boards = {h.host_board for h in histories}
-
def __getitem__(self, key):
return self._modeldata.__getitem__(key)
-
def __len__(self):
return self._modeldata.__len__()
-
def __iter__(self):
return self._modeldata.__iter__()
-
def reportable_items(self, spare_pool=SPARE_POOL):
- """Iterate over all items subject to reporting.
+ """Iterate over all items subject to reporting.
Yields the contents of `self.iteritems()` filtered to include
only reportable models. A model is reportable if it has DUTs in
@@ -526,17 +493,14 @@
if spares != 0 and spares != total:
yield model, histories
-
def get_num_duts(self):
"""Return the total number of DUTs in the inventory."""
return self._dut_count
-
def get_num_models(self):
"""Return the total number of models in the inventory."""
return len(self)
-
def get_pool_models(self, pool):
"""Return all models in `pool`.
@@ -544,7 +508,6 @@
"""
return {m for m, h in self.iteritems() if h.get_total(pool)}
-
def get_boards(self):
return self._boards
@@ -567,7 +530,6 @@
break down.
@return A list of sorted lists of DUTs.
-
"""
BASE = 100
lab_lists = {}
@@ -659,7 +621,6 @@
@param inventory `_LabInventory` object from which to generate
recommendations.
@param num_recommend Number of DUTs to recommend for repair.
-
"""
logging.debug('Creating DUT repair recommendations')
model_buffer_counts = {}
@@ -855,7 +816,6 @@
@param inventory `_LabInventory` object to be reported on.
@return String with the inventory message to be sent.
-
"""
logging.debug('Creating idle inventory')
message = [_IDLE_INVENTORY_HEADER]
@@ -1195,7 +1155,6 @@
@param address_list A list of strings containing comma
separate e-mail addresses.
@return A list of the individual e-mail addresses.
-
"""
newlist = []
for arg in address_list:
@@ -1220,7 +1179,6 @@
`ArgumentParser`
@return True if the arguments are semantically good, or False
if the arguments don't meet requirements.
-
"""
arguments.model_notify = _separate_email_addresses(
arguments.model_notify)
@@ -1250,7 +1208,6 @@
@param script Path to this script file.
@return A path to a directory.
-
"""
basedir = os.path.dirname(os.path.abspath(script))
basedir = os.path.dirname(basedir)
@@ -1267,7 +1224,6 @@
@param argv Standard command line argument vector; argv[0] is
assumed to be the command name.
@return Result returned by ArgumentParser.parse_args().
-
"""
parser = argparse.ArgumentParser(
prog=argv[0],