reformatted code to pep8 convention

This commit is contained in:
Guillaume Raffy 2018-08-27 15:17:09 +00:00
parent e9f3c5a784
commit 796ec2d6a5
1 changed files with 40 additions and 42 deletions

View File

@ -1,15 +1,11 @@
# encoding: utf-8 # encoding: utf-8
import sys
import os
import re
import datetime import datetime
from SimpaDbUtil import SqlDatabaseReader, SqlFile
class Inventory(object): class Inventory(object):
def __init__(self, sql_reader): def __init__(self, sql_reader):
""" """
:param SqlDatabaseReader sql_reader: the inventory database :param SimpaDbUtil.SqlDatabaseReader sql_reader: the inventory database
""" """
super(Inventory, self).__init__() super(Inventory, self).__init__()
self._sql_reader = sql_reader self._sql_reader = sql_reader
@ -32,7 +28,11 @@ class Inventory( object ):
return machine_name return machine_name
def machine_name_to_machine_spec_id(self, machine_name): def machine_name_to_machine_spec_id(self, machine_name):
# machine_spec_id = None
# try:
machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id') machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id')
# except:
# machine_spec_id = None
return machine_spec_id return machine_spec_id
# electricity related methods # electricity related methods
@ -81,7 +81,6 @@ class Inventory( object ):
ordering_date = datetime.datetime.strptime(ordering_date_as_str, '%d/%m/%Y') ordering_date = datetime.datetime.strptime(ordering_date_as_str, '%d/%m/%Y')
return ordering_date return ordering_date
def get_cpu_dflops(self, cpu_model): def get_cpu_dflops(self, cpu_model):
''' '''
returns the number of double precision operation per second this cpu can achieve returns the number of double precision operation per second this cpu can achieve
@ -134,7 +133,7 @@ class Inventory( object ):
:return float: the price of the item exluding taxes :return float: the price of the item exluding taxes
""" """
item_price = self._sql_reader.get_table_attr('machines', 'name', item_id, 'price_ex_vat') item_price = self._sql_reader.get_table_attr('machines', 'name', item_id, 'price_ex_vat')
if item_price == None: if item_price is None:
item_price = 0.0 item_price = 0.0
else: else:
item_price = float(item_price) item_price = float(item_price)
@ -159,7 +158,7 @@ class Inventory( object ):
rows = self._sql_reader.query("SELECT * FROM ownership WHERE machine_id='%s'" % item_id) rows = self._sql_reader.query("SELECT * FROM ownership WHERE machine_id='%s'" % item_id)
for row in rows: for row in rows:
(machine_id, owner, owner_ratio, comment)=row (machine_id, owner, owner_ratio, comment) = row # @UnusedVariable
ownership.append({'owner': owner, 'owner_ratio': owner_ratio}) ownership.append({'owner': owner, 'owner_ratio': owner_ratio})
return ownership return ownership
@ -168,8 +167,7 @@ class Inventory( object ):
rows = self._sql_reader.query("SELECT * FROM machine_users") rows = self._sql_reader.query("SELECT * FROM machine_users")
for row in rows: for row in rows:
(machine_id, user, user_ratio, comment)=row (machine_id, user, user_ratio, comment) = row # @UnusedVariable
if machine_id == item_id: if machine_id == item_id:
ownership.append({'user': user, 'user_ratio': user_ratio}) ownership.append({'user': user, 'user_ratio': user_ratio})
return ownership return ownership