diff --git a/PowerDiagram.py b/PowerDiagram.py index 6deca1b..9b19253 100644 --- a/PowerDiagram.py +++ b/PowerDiagram.py @@ -7,8 +7,8 @@ ''' import re -import pygraphviz -from inventory import Inventory +import pygraphviz # port install py-pygraphviz +from inventory import Inventory, MachineSpecIdNotFound from SimpaDbUtil import SqlFile, SqlDatabaseReader from Lib import SimpaDbUtil @@ -199,7 +199,9 @@ class PowerConfig(object): machine_name = machine.name - if re.match('simpatix.._..', machine_name): + if re.match('[a-z]+.._..', machine_name): + # machine_name is a group of machines such as physix80_83 + # in this case, we use a hack : the type and power consumption is based on the first machine of this group (in this example physix80) machine_name = '_'.join(machine_name.split('_')[0:-1]) # print(machine_name) @@ -210,7 +212,7 @@ class PowerConfig(object): machine_spec_id = inventory.machine_name_to_machine_spec_id(machine_name) if machine_spec_id == '': machine_spec_id = None # some simple 'machines' such as powerext003 have undefined machine_spec_id - except SimpaDbUtil.TableAttrNotFound: + except MachineSpecIdNotFound: pass if machine_spec_id is not None: diff --git a/SimpaDbUtil.py b/SimpaDbUtil.py index 118f1bc..98b7736 100644 --- a/SimpaDbUtil.py +++ b/SimpaDbUtil.py @@ -1,4 +1,4 @@ -import MySQLdb +import MySQLdb # sudo port install py-mysql import time import StringIO import re diff --git a/inventory.py b/inventory.py index c0fc408..0c96e5a 100644 --- a/inventory.py +++ b/inventory.py @@ -45,7 +45,10 @@ class Inventory(object): return machine_name def machine_name_to_machine_spec_id(self, machine_name): - machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id') + try: + machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id') + except SimpaDbUtil.TableAttrNotFound as e: # @UnusedVariable + raise MachineSpecIdNotFound(machine_name) return machine_spec_id # electricity related methods