Move EnumAction to different file
This will make it easier to move main() in the future.
This commit is contained in:
parent
9cfed0f839
commit
a17135d85d
|
@ -19,6 +19,7 @@ from data.declarations import Declaration
|
|||
from data.embellishments import Embellishment
|
||||
from data.skulls import Skull
|
||||
from data.torsos import Torso
|
||||
from objects.enumaction import EnumAction
|
||||
|
||||
# This multiplier is applied to the profit margin to avoid losing precision due to rounding.
|
||||
PROFIT_MARGIN_MULTIPLIER = 10000000
|
||||
|
@ -1283,33 +1284,6 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non
|
|||
return printer.PrintableSolution(solver)
|
||||
|
||||
|
||||
class EnumAction(argparse.Action):
|
||||
def __init__(self, **kwargs):
|
||||
# Pop off the type value
|
||||
enum = kwargs.pop('type', None)
|
||||
|
||||
nargs = kwargs.pop('nargs', None)
|
||||
|
||||
# Generate choices from the Enum
|
||||
kwargs.setdefault('choices', tuple(member.name.lower() for member in enum))
|
||||
|
||||
super(EnumAction, self).__init__(**kwargs)
|
||||
|
||||
self._enum = enum
|
||||
self._nargs = nargs
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
# Convert value back into an Enum
|
||||
enum = self._enum[values.upper()]
|
||||
|
||||
if self._nargs is None or self._nargs == '?':
|
||||
setattr(namespace, self.dest, enum)
|
||||
else:
|
||||
items = getattr(namespace, self.dest, list())
|
||||
items.append(enum)
|
||||
setattr(namespace, self.dest, items)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='Bone Market Solver',
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
__all__ = ['EnumAction']
|
||||
__author__ = "Jeremy Saklad"
|
||||
|
||||
from argparse import Action
|
||||
|
||||
class EnumAction(Action):
|
||||
def __init__(self, **kwargs):
|
||||
# Pop off the type value
|
||||
enum = kwargs.pop('type', None)
|
||||
|
||||
nargs = kwargs.pop('nargs', None)
|
||||
|
||||
# Generate choices from the Enum
|
||||
kwargs.setdefault('choices', tuple(member.name.lower() for member in enum))
|
||||
|
||||
super(EnumAction, self).__init__(**kwargs)
|
||||
|
||||
self._enum = enum
|
||||
self._nargs = nargs
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
# Convert value back into an Enum
|
||||
enum = self._enum[values.upper()]
|
||||
|
||||
if self._nargs is None or self._nargs == '?':
|
||||
setattr(namespace, self.dest, enum)
|
||||
else:
|
||||
items = getattr(namespace, self.dest, list())
|
||||
items.append(enum)
|
||||
setattr(namespace, self.dest, items)
|
Loading…
Reference in New Issue