Skip to content

Commit

Permalink
OptState: More flexible and can add options on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
dgasmith committed May 15, 2018
1 parent 3710e17 commit 612eec4
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions psi4/driver/p4util/optproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,29 @@ class OptionsState(object):
"""
def __init__(self, *largs):
self.data = []
self.data = {}
for item in largs:
if len(item) == 2:
self.data.append(OptionState(item[1], item[0]))
elif len(item) == 1:
self.data.append(OptionState(item[0]))
else:
raise ValidationError('Each argument to OptionsState should be an array, the first element of which is the module scope and the second element of which is the module name. Bad argument: %s' % (item))
self.add_option(item)

def add_option(self, item):
if len(item) == 2:
key = (item[1], item[0])
elif len(item) == 1:
key = (item[0], )
else:
raise ValidationError('Each argument to OptionsState should be an array, the first element of which is the module scope and the second element of which is the module name. Bad argument: %s' % (item))

if key in self.data:
raise ValidationError('Malformed options state, duplicate key adds of "%s"' % key)
else:
self.data[key] = OptionState(*key)

def __str__(self):
text = ''
for item in self.data:
for key, item in self.data.items():
text += str(item)
return text

def restore(self):
for item in self.data:
for key, item in self.data.items():
item.restore()

0 comments on commit 612eec4

Please sign in to comment.