Skip to content

Commit

Permalink
Merge pull request #350 from weibullguy/refactor/update_opts_prefs_as…
Browse files Browse the repository at this point in the history
…sistants

refactor(Opt::GUI): add EditOptions assistant
  • Loading branch information
weibullguy authored Aug 30, 2020
2 parents 9ed547c + ae8fd3f commit 2e7898e
Show file tree
Hide file tree
Showing 13 changed files with 704 additions and 1,027 deletions.
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
repos:
- repo: local
hooks:
- id: bandit
name: bandit
entry: bandit
args: [--ini, .bandit, -b, .bandit.baseline, -c, .bandit.conf, --recursive, src/]
language: system
files: .py$
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.27.0
hooks:
Expand Down
119 changes: 55 additions & 64 deletions cobertura.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage branch-rate="0.9068" branches-covered="954" branches-valid="1052" complexity="0" line-rate="0.9597" lines-covered="5766" lines-valid="6008" timestamp="1598419426049" version="4.5.4">
<coverage branch-rate="0.9076" branches-covered="953" branches-valid="1050" complexity="0" line-rate="0.9597" lines-covered="5757" lines-valid="5999" timestamp="1598757625847" version="4.5.4">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources/>
Expand Down Expand Up @@ -3184,33 +3184,33 @@
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="339"/>
<line hits="1" number="340"/>
<line hits="1" number="344"/>
<line hits="1" number="356"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="358"/>
<line hits="1" number="363"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="366"/>
<line hits="1" number="367"/>
<line hits="1" number="355"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="357"/>
<line hits="1" number="362"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="365"/>
<line hits="1" number="366"/>
<line hits="1" number="370"/>
<line hits="1" number="371"/>
<line hits="1" number="372"/>
<line hits="1" number="373"/>
<line hits="1" number="374"/>
<line hits="1" number="375"/>
<line hits="1" number="377"/>
<line hits="1" number="380"/>
<line hits="1" number="376"/>
<line hits="1" number="379"/>
<line hits="1" number="387"/>
<line hits="1" number="388"/>
<line hits="1" number="389"/>
<line hits="1" number="390"/>
<line hits="1" number="392"/>
<line hits="1" number="394"/>
<line hits="1" number="391"/>
<line hits="1" number="393"/>
<line hits="1" number="395"/>
<line hits="1" number="396"/>
<line hits="1" number="397"/>
<line hits="1" number="398"/>
<line hits="1" number="399"/>
<line hits="1" number="402"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="403"/>
<line hits="1" number="404"/>
<line hits="1" number="408"/>
<line branch="true" condition-coverage="50% (1/2)" hits="1" missing-branches="410" number="409"/>
<line hits="0" number="410"/>
<line hits="1" number="401"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="402"/>
<line hits="1" number="403"/>
<line hits="1" number="407"/>
<line branch="true" condition-coverage="50% (1/2)" hits="1" missing-branches="409" number="408"/>
<line hits="0" number="409"/>
</lines>
</class>
<class branch-rate="1" complexity="0" filename="/home/drowland/.pyenv/versions/3.7.2/envs/ramstk-py3-pygobject/lib/python3.7/site-packages/ramstk/controllers/hardware/matrixmanager.py" line-rate="0.8182" name="matrixmanager.py">
Expand All @@ -3231,71 +3231,62 @@
</class>
</classes>
</package>
<package branch-rate="0.9375" complexity="0" line-rate="1" name=".home.drowland..pyenv.versions.3.7.2.envs.ramstk-py3-pygobject.lib.python3.7.site-packages.ramstk.controllers.options">
<package branch-rate="1" complexity="0" line-rate="1" name=".home.drowland..pyenv.versions.3.7.2.envs.ramstk-py3-pygobject.lib.python3.7.site-packages.ramstk.controllers.options">
<classes>
<class branch-rate="1" complexity="0" filename="/home/drowland/.pyenv/versions/3.7.2/envs/ramstk-py3-pygobject/lib/python3.7/site-packages/ramstk/controllers/options/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines>
<line hits="1" number="8"/>
</lines>
</class>
<class branch-rate="0.9375" complexity="0" filename="/home/drowland/.pyenv/versions/3.7.2/envs/ramstk-py3-pygobject/lib/python3.7/site-packages/ramstk/controllers/options/datamanager.py" line-rate="1" name="datamanager.py">
<class branch-rate="1" complexity="0" filename="/home/drowland/.pyenv/versions/3.7.2/envs/ramstk-py3-pygobject/lib/python3.7/site-packages/ramstk/controllers/options/datamanager.py" line-rate="1" name="datamanager.py">
<methods/>
<lines>
<line hits="1" number="7"/>
<line hits="1" number="21"/>
<line hits="1" number="29"/>
<line hits="1" number="22"/>
<line hits="1" number="30"/>
<line hits="1" number="32"/>
<line hits="1" number="34"/>
<line hits="1" number="41"/>
<line hits="1" number="48"/>
<line hits="1" number="31"/>
<line hits="1" number="33"/>
<line hits="1" number="35"/>
<line hits="1" number="42"/>
<line hits="1" number="49"/>
<line hits="1" number="50"/>
<line hits="1" number="53"/>
<line hits="1" number="51"/>
<line hits="1" number="54"/>
<line hits="1" number="55"/>
<line hits="1" number="56"/>
<line hits="1" number="57"/>
<line hits="1" number="59"/>
<line hits="1" number="66"/>
<line hits="1" number="68"/>
<line hits="1" number="77"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="79"/>
<line hits="1" number="80"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="82"/>
<line hits="1" number="84"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="89"/>
<line hits="1" number="92"/>
<line hits="1" number="97"/>
<line hits="1" number="99"/>
<line hits="1" number="112"/>
<line hits="1" number="114"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="116"/>
<line hits="1" number="117"/>
<line hits="1" number="118"/>
<line hits="1" number="120"/>
<line hits="1" number="121"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="123"/>
<line hits="1" number="124"/>
<line hits="1" number="58"/>
<line hits="1" number="60"/>
<line hits="1" number="67"/>
<line hits="1" number="69"/>
<line hits="1" number="78"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="80"/>
<line hits="1" number="81"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="84"/>
<line hits="1" number="86"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="92"/>
<line hits="1" number="95"/>
<line hits="1" number="100"/>
<line hits="1" number="102"/>
<line hits="1" number="113"/>
<line hits="1" number="115"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="117"/>
<line hits="1" number="119"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="122"/>
<line hits="1" number="123"/>
<line hits="1" number="125"/>
<line hits="1" number="126"/>
<line hits="1" number="127"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="129"/>
<line hits="1" number="130"/>
<line hits="1" number="132"/>
<line hits="1" number="134"/>
<line hits="1" number="136"/>
<line hits="1" number="128"/>
<line hits="1" number="131"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="139"/>
<line hits="1" number="141"/>
<line hits="1" number="143"/>
<line hits="1" number="144"/>
<line hits="1" number="145"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="146"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="145"/>
<line hits="1" number="147"/>
<line branch="true" condition-coverage="50% (1/2)" hits="1" missing-branches="152" number="149"/>
<line hits="1" number="150"/>
<line hits="1" number="152"/>
<line hits="1" number="154"/>
<line hits="1" number="155"/>
<line hits="1" number="156"/>
<line hits="1" number="148"/>
<line hits="1" number="149"/>
<line hits="1" number="151"/>
</lines>
</class>
</classes>
Expand Down
2 changes: 1 addition & 1 deletion src/ramstk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def the_one_ring() -> None:
_program_mgr.dic_managers['validation']['data'] = dmValidation()
_program_mgr.dic_managers['validation']['matrix'] = mmValidation()
_program_mgr.dic_managers['options']['data'] = dmOptions(
common_dao=_site_db,
common_dao=site_db,
site_configuration=site_configuration,
user_configuration=user_configuration)
_program_mgr.user_configuration = user_configuration
Expand Down
3 changes: 1 addition & 2 deletions src/ramstk/controllers/hardware/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ def _do_set_hardware_attributes(self, node_id: List[int],
:param int node_id: the ID of the record in the RAMSTK Program
database table whose attributes are to be set.
:param str key: the key in the attributes dict.
:param value: the new value of the attribute to set.
:param dict package: the key:value for the attribute being updated.
:return: None
:rtype: None
"""
Expand Down
79 changes: 36 additions & 43 deletions src/ramstk/controllers/options/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class DataManager(RAMSTKDataManager):
"""
Contain the attributes and methods of the Options data manager.
This class manages the Options data from the RAMSTKMode, RAMSTKMechains,
RAMSTKOpLoad, RAMSTKOpStress, and RAMSTKTestMethod data models.
This class manages the user-configurable Preferences and Options data from
the Site and Program databases.
"""

_tag = 'options'
_root = 0

def __init__(self, **kwargs) -> None: # pylint: disable=unused-argument
def __init__(self, **kwargs) -> None:
"""Initialize a Options data manager instance."""
RAMSTKDataManager.__init__(self, **kwargs)

Expand All @@ -50,7 +50,7 @@ def __init__(self, **kwargs) -> None: # pylint: disable=unused-argument
self.user_configuration = kwargs['user_configuration']

# Subscribe to PyPubSub messages.
pub.subscribe(self.do_select_all, 'request_select_options')
pub.subscribe(self.do_select_all, 'selected_revision')
pub.subscribe(self.do_update, 'request_update_option')
pub.subscribe(self.do_get_attributes, 'request_get_option_attributes')
pub.subscribe(self.do_get_tree, 'request_get_options_tree')
Expand All @@ -63,29 +63,31 @@ def do_get_tree(self) -> None:
:return: None
:rtype: None
"""
pub.sendMessage('succeed_get_options_tree', dmtree=self.tree)
pub.sendMessage('succeed_get_options_tree', tree=self.tree)

def do_select_all(self, parent_id: int) -> None: # pylint: disable=arguments-differ
def do_select_all(self, attributes: Dict[str, Any]) -> None:
"""
Retrieve all the Options data from the RAMSTK Program database.
:param int parent_id: the parent (function or hardware) ID to select
the Options for.
:param dict attributes: the RAMSTK option attributes for the
selected Revision.
:return: None
:rtype: None
"""
self._revision_id = parent_id
self._revision_id = attributes['revision_id']

for _node in self.tree.children(self.tree.root):
self.tree.remove_node(_node.identifier)

# noinspection PyUnresolvedReferences
for _option in self.common_dao.session.query(RAMSTKSiteInfo).all():

self.tree.create_node(tag='Site Info',
identifier='siteinfo',
parent=self._root,
data={'siteinfo': _option})

# noinspection PyUnresolvedReferences
for _option in self.dao.session.query(RAMSTKProgramInfo).filter(
RAMSTKProgramInfo.revision_id == self._revision_id).all():

Expand All @@ -96,64 +98,55 @@ def do_select_all(self, parent_id: int) -> None: # pylint: disable=arguments-di

pub.sendMessage('succeed_retrieve_options', tree=self.tree)

def do_set_attributes(self, node_id: List[int],
def do_set_attributes(self, node_id: List[str],
package: Dict[str, Any]) -> None:
"""
Set the attributes of the record associated with the Module ID.
:param int node_id: the ID of the record in the RAMSTK Program
database table whose attributes are to be set.
:param str key: the key in the attributes dict.
:param value: the new value of the attribute to set.
:param str table: the name of the table whose attributes are being set.
:param dict package: the key:value for the attribute being updated.
:return: None
:rtype: None
"""
[[_key, _value]] = package.items()

_pkey = {'siteinfo': ['site_id'], 'programinfo': ['revision_id']}
_pkey = {'siteinfo': 'site_id', 'programinfo': 'revision_id'}

for _table in ['siteinfo', 'programinfo']:
try:
_attributes = self.do_select(node_id[0],
table=_table).get_attributes()
except (AttributeError, KeyError):
_attributes = {}

for _field in _pkey[_table]:
try:
_attributes.pop(_field)
except KeyError:
pass
for _table in node_id:
# noinspection PyTypeChecker
_attributes = self.do_select(_table,
table=_table).get_attributes()

if _key in _attributes:
_attributes[_key] = _value

self.do_select(node_id[0],
_attributes.pop(_pkey[_table])

# noinspection PyTypeChecker
self.do_select(_table,
table=_table).set_attributes(_attributes)
self.do_get_tree()

def do_update(self, node_id: int) -> None:
def do_update(self, node_id: str) -> None:
"""
Update the record associated with node ID in RAMSTK databases.
:param int node_id: the node ID of the Options item to save.
:param str node_id: the node ID of the Options item to save.
:return: None
:rtype: None
"""
try:
_table = list(self.tree.get_node(node_id).data.keys())[0]
if node_id in ['siteinfo']:
self.common_dao.session.add(
self.tree.get_node(node_id).data[_table])
elif node_id in ['programinfo']:
self.dao.session.add(self.tree.get_node(node_id).data[_table])

if node_id == 'siteinfo':
# noinspection PyUnresolvedReferences
self.common_dao.session.add(
self.tree.get_node(node_id).data[node_id])
self.dao.do_update()
pub.sendMessage('succeed_update_options', node_id=node_id)
elif node_id == 'programinfo':
# noinspection PyUnresolvedReferences
self.dao.session.add(self.tree.get_node(node_id).data[node_id])
self.dao.do_update()

pub.sendMessage('succeed_update_options', node_id=node_id)
except AttributeError:
else:
pub.sendMessage('fail_update_options',
error_message=('Attempted to save non-existent '
'Option with Options ID '
'{0:s}.').format(str(node_id)))
error_message=('Error saving {0:s} Options to the '
'database.').format(node_id))
Loading

0 comments on commit 2e7898e

Please sign in to comment.